diff --git a/packages/gatsby-graphiql-explorer/src/app/app.js b/packages/gatsby-graphiql-explorer/src/app/app.js index 41bdaed93a332..50b3d3e8e1e2b 100644 --- a/packages/gatsby-graphiql-explorer/src/app/app.js +++ b/packages/gatsby-graphiql-explorer/src/app/app.js @@ -173,7 +173,11 @@ class App extends React.Component { graphQLFetcher({ query: getIntrospectionQuery(), }).then(result => { - const newState = { schema: buildClientSchema(result.data) } + const newState = { + schema: buildClientSchema(result.data), + enableRefresh: result.extensions.enableRefresh, + refreshToken: result.extensions.refreshToken, + } if (this.state.query === null) { try { @@ -302,6 +306,16 @@ class App extends React.Component { this.setState({ codeExporterIsOpen: newCodeExporterIsOpen }) } + _refreshExternalDataSources = () => { + const options = { method: `post` } + if (this.state.refreshToken) { + options.headers = { + Authorization: this.state.refreshToken, + } + } + return fetch(`/__refresh`, options) + } + render() { const { query, variables, schema, codeExporterIsOpen } = this.state const codeExporter = codeExporterIsOpen ? ( @@ -356,6 +370,13 @@ class App extends React.Component { label="Code Exporter" title="Toggle Code Exporter" /> + {this.state.enableRefresh && ( + + )} {codeExporter} diff --git a/packages/gatsby/src/utils/start-server.ts b/packages/gatsby/src/utils/start-server.ts index d1d2be626d2de..8a65a2588d6af 100644 --- a/packages/gatsby/src/utils/start-server.ts +++ b/packages/gatsby/src/utils/start-server.ts @@ -161,6 +161,12 @@ export async function startServer( return { schema, graphiql: false, + extensions(): { [key: string]: unknown } { + return { + enableRefresh: process.env.ENABLE_GATSBY_REFRESH_ENDPOINT, + refreshToken: process.env.GATSBY_REFRESH_TOKEN, + } + }, context: withResolverContext({ schema, schemaComposer: schemaCustomization.composer,