File tree Expand file tree Collapse file tree
packages/gatsby-source-graphql/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ jest.mock(`gatsby/graphql`, () => {
2020 }
2121} )
2222const { sourceNodes } = require ( `../gatsby-node` )
23- const nodeFetch = require ( `node- fetch` )
23+ const { fetchWrapper } = require ( `../ fetch` )
2424
2525const getInternalGatsbyAPI = ( ) => {
2626 const actions = {
@@ -98,7 +98,7 @@ describe(`createHttpLink`, () => {
9898 } )
9999
100100 expect ( createHttpLink ) . toHaveBeenCalledWith (
101- expect . objectContaining ( { fetch : nodeFetch } )
101+ expect . objectContaining ( { fetch : fetchWrapper } )
102102 )
103103 } )
104104} )
Original file line number Diff line number Diff line change 1+ const nodeFetch = require ( `node-fetch` )
2+
3+ // this is passed to the Apollo Link
4+ // https://www.apollographql.com/docs/link/links/http/#fetch-polyfill
5+
6+ exports . fetchWrapper = async ( uri , options ) => {
7+ const response = await nodeFetch ( uri , options )
8+
9+ if ( response . status >= 400 ) {
10+ throw new Error (
11+ `Source GraphQL API: HTTP error ${ response . status } ${ response . statusText } `
12+ )
13+ }
14+
15+ return response
16+ }
Original file line number Diff line number Diff line change 77} = require ( `@graphql-tools/wrap` )
88const { linkToExecutor } = require ( `@graphql-tools/links` )
99const { createHttpLink } = require ( `apollo-link-http` )
10- const nodeFetch = require ( `node-fetch` )
1110const invariant = require ( `invariant` )
11+ const { fetchWrapper } = require ( `./fetch` )
1212const { createDataloaderLink } = require ( `./batching/dataloader-link` )
1313
1414const {
@@ -26,7 +26,7 @@ exports.sourceNodes = async (
2626 typeName,
2727 fieldName,
2828 headers = { } ,
29- fetch = nodeFetch ,
29+ fetch = fetchWrapper ,
3030 fetchOptions = { } ,
3131 createLink,
3232 createSchema,
You can’t perform that action at this time.
0 commit comments