Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"
)
}
}
new Promise((resolve, reject) => {
const { schema } = store.getState();
graphql(schema, introspectionQuery)
.then(res => fs.writeFileSync(snapshotLocation, JSON.stringify(res.data)))
.then(() => {
console.log("Wrote schema");
resolve();
})
.catch(e => {
console.log("Failed to write schema: ", e);
reject();
});
});
const extractSchema = async () => {
const { schema } = store.getState();
const { data: fullSchema } = await graphql(schema, introspectionQuery);
const output = JSON.stringify(fullSchema, null, 2);
const sha1sum = crypto.createHash('sha1').update(output).digest('hex');
if (cache !== sha1sum) {
cache = sha1sum;
await fs.promises.writeFile(schemaOutputPath, output, 'utf-8');
log(`Schema file extracted to ${schemaOutputPath}!`);
}
};