Skip to content

Instantly share code, notes, and snippets.

@kkemple
Last active July 18, 2023 21:51
Show Gist options
  • Save kkemple/6169e8dc16369b7c01ad7408fc7917a9 to your computer and use it in GitHub Desktop.
Save kkemple/6169e8dc16369b7c01ad7408fc7917a9 to your computer and use it in GitHub Desktop.
Extract Schema from Gatsby
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")
}
],
}
};
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