-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
37 lines (31 loc) · 1.1 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
30
31
32
33
34
35
36
37
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const { introspectionQuery, graphql, printSchema } = require('gatsby/graphql');
const write = require('write');
/**
* Generate GraphQL schema.json file to be read by tslint
* Thanks: https://gist.github.com/kkemple/6169e8dc16369b7c01ad7408fc7917a9
*/
exports.onPostBootstrap = async ({ store }) => {
try {
const { schema } = store.getState();
const jsonSchema = await graphql(schema, introspectionQuery);
const sdlSchema = printSchema(schema);
write.sync('schema.json', JSON.stringify(jsonSchema.data), {});
write.sync('schema.graphql', sdlSchema, {});
console.log('\n\n[gatsby-plugin-extract-schema] Wrote schema\n'); // eslint-disable-line
} catch (error) {
console.error(
'\n\n[gatsby-plugin-extract-schema] Failed to write schema: ',
error,
'\n',
);
}
};
const { fmImagesToRelative } = require('gatsby-remark-relative-images');
exports.onCreateNode = ({ node }) => {
fmImagesToRelative(node);
};