How to use the gatsby/graphql.graphql function in gatsby

To help you get started, we’ve selected a few gatsby examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github damassi / gatsby-starter-typescript-rebass-netlifycms / gatsby-node.js View on Github external
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"
    )
  }
}
github NickyMeuleman / gatsby-plugin-extract-schema / gatsby-node.js View on Github external
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();
      });
  });
github cometkim / gatsby-plugin-typegen / gatsby-node.ts View on Github external
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}!`);
    }
  };