Last active
July 18, 2023 21:51
-
-
Save kkemple/6169e8dc16369b7c01ad7408fc7917a9 to your computer and use it in GitHub Desktop.
Extract Schema from Gatsby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
extends: ["react-app"], | |
env: { | |
browser: true, | |
node: true, | |
jest: true | |
}, | |
rules: { | |
"graphql/template-strings": [ | |
"error", | |
{ | |
env: "relay", | |
tagName: "graphql", | |
schemaJson: require("./schema.json") | |
} | |
], | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from "path" | |
import { writeFile } from "fs" | |
import { introspectionQuery, graphql } from "gatsby/graphql" | |
exports.onPostBootstrap = async ({ store }) => { | |
try { | |
const { schema } = store.getState() | |
const data = await graphql(schema, introspectionQuery) | |
await fs.writeFile( | |
path.resolve(process.cwd(), `schema.json`), | |
JSON.stringify(data) | |
) | |
} catch (error) { | |
return error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment