diff --git a/packages/gatsby-source-graphql/README.md b/packages/gatsby-source-graphql/README.md index 941597a1ec88d..0993f30e01cd7 100644 --- a/packages/gatsby-source-graphql/README.md +++ b/packages/gatsby-source-graphql/README.md @@ -42,6 +42,12 @@ module.exports = { // Learn about environment variables: https://gatsby.dev/env-vars Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, }, + // HTTP headers alternatively accepts a function (allows async) + headers: async () => { + return { + Authorization: await getAuthorizationToken(), + } + }, // Additional options to pass to node-fetch fetchOptions: {}, }, diff --git a/packages/gatsby-source-graphql/src/gatsby-node.js b/packages/gatsby-source-graphql/src/gatsby-node.js index b1988b7dec867..a02d79a8f42dc 100644 --- a/packages/gatsby-source-graphql/src/gatsby-node.js +++ b/packages/gatsby-source-graphql/src/gatsby-node.js @@ -51,8 +51,8 @@ exports.sourceNodes = async ( link = createHttpLink({ uri: url, fetch, - headers, fetchOptions, + headers: typeof headers === `function` ? await headers() : headers, }) }