-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgatsby-node.js
29 lines (25 loc) · 1.04 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const write = require("write");
const path = require("path");
const { printSchema } = require("gatsby/graphql");
exports.onPostBootstrap = async ({ store }, options) => {
try {
const defaultLocation = path.resolve(process.cwd(), "schema.graphql");
const defaultGetSchema = async (obj) =>
printSchema(obj, { commentDescriptions: true });
const defaultWriteSchema = async (location, schema) =>
write(location, schema);
const location = options.dest || defaultLocation;
const { schema: internalSchemaObj } = store.getState();
const getSchema = options.getSchema || defaultGetSchema
let schema = (await getSchema(internalSchemaObj));
schema = options.adjustSchema ? await options.adjustSchema(schema) : schema;
const writeSchema = options && options.writeSchema || defaultWriteSchema;
await writeSchema(location, schema);
console.log("[gatsby-plugin-extract-schema] Wrote schema");
} catch (error) {
console.error(
"[gatsby-plugin-extract-schema] Failed to write schema: ",
error
);
}
};