When trying to use gatsby-source-graphql and GraphCMS I get a "TypeError: fetcher is not a function" and it doesn't generate any nodes. It appears to be in the gatsby-node.js function inside of gatsby-source-graphql. It has something to do with the introspectSchema call.
Clone this github repo: https://github.com/lukenetti3/graphcms.git
Try and run "gatsby develop" and you should see error.
It should generate nodes and I should see them when I go to localhost:8000/__graphql
Seeing error in image below:
System:
OS: macOS 10.15.4
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 13.12.0 - /usr/local/bin/node
npm: 6.14.4 - /usr/local/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 80.0.3987.163
Safari: 13.1
npmPackages:
gatsby: ^2.20.15 => 2.20.15
gatsby-cli: ^2.11.5 => 2.11.5
gatsby-image: ^2.3.2 => 2.3.2
gatsby-plugin-emotion: ^4.2.1 => 4.2.1
gatsby-plugin-offline: ^3.1.2 => 3.1.2
gatsby-plugin-react-helmet: ^3.2.1 => 3.2.1
gatsby-plugin-sass: ^2.2.1 => 2.2.1
gatsby-plugin-sharp: ^2.5.4 => 2.5.4
gatsby-plugin-smoothscroll: ^1.1.0 => 1.1.0
gatsby-plugin-typography: ^2.4.1 => 2.4.1
gatsby-plugin-web-font-loader: ^1.0.4 => 1.0.4
gatsby-source-filesystem: ^2.2.2 => 2.2.2
gatsby-source-graphql: ^2.3.2 => 2.3.2
gatsby-transformer-sharp: ^2.4.4 => 2.4.4
npmGlobalPackages:
gatsby-cli: 2.11.6
It appears the update to apollo-link-http is the culprit. I pinned apollo-link-http to 1.5.16, which seems to have fixed the problem for me.
That worked! Thank you so much. If you don't mind telling me. How did you determine this was the culprit?
Luck, mostly. The short version is that I did a search for fetcher
in my project to see if I could track down the problem. Saw that apollo-link-http was one of the packages calling it. Noticed that said package had a version bump yesterday, so I rolled it back.
I need help figuring out how exactly you changed this?
I did it like this: npm install [email protected]
pinning the dependency didn't work for me.
I had to load a fetch polyfill in gatsby-config
require('isomorphic-unfetch')
well, the polyfill worked, and now it is not working anymore.
The bug throws here:
https://github.com/yaacovCR/graphql-tools-fork/blob/master/src/stitch/introspectSchema.ts#L22
Since apollo-link
update 2 days ago, the link is not an instance of ApolloLink anymore.
Pinning the dependency of apollo-link
and apollo-link-http
to the old version worked for me:
I added this to package.json
using yarn
"resolutions": {
"**/apollo-link": "1.2.13",
"**/apollo-link-http": "1.5.16"
}
I am not sure if the second pin is really necessary, I think the first one is enough. I will probably try tomorrow.
I guess this shouldn't be closed? Expect library user to pin a version is a workaround, not a solution.
Try running npm ls apollo-link or yarn why apollo-link. You should only have a single version of apollo-link and then things should work properly.
I can change the instanceof check to use duck typing, or use apollo-link as peer dependency, but I am not quite sure why this is necessary, ie why you would have two different versions with a patch update...
@yaacovCR I would go with duck typing. You cannot be sure that you use the same apollo-link
version than the library that gave you that link, can you?
I have the same issue (https://github.com/gatsbyjs/gatsby/issues/23041), if I add the suggested resolutions field in package.json I got an other error:
"gatsby-source-graphql" threw an error while running the sourceNodes lifecycle:
Cannot use GraphQLDirective "@cacheControl" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
I have the same issue (#23041), if I add the suggested resolutions field in package.json I got an other error:
"gatsby-source-graphql" threw an error while running the sourceNodes lifecycle: Cannot use GraphQLDirective "@cacheControl" from another module or realm. Ensure that there is only one instance of "graphql" in the node_modules directory. If different versions of "graphql" are the dependencies of other relied on modules, use "resolutions" to ensure only one version is installed.
you should remove graphql from your dependencies so you use the same version as gatsby uses.
try npm ls graphql
or yarn why graphql
@yaacovCR it is usual in gatsby apps that we use apollo in the frontend, and graphql-source plugin to get static data. In that case, it is pretty hard to assure that we have only one version of apollo-link installed.
See https://github.com/apollographql/graphql-tools/pull/1362
Fixed in graphql-tools v5, which will hopefully be released soon.
Then gatsby-source-graphql can be changed back to upstream graphql-tools as v5 release takes in fixes in fork. fork will be deprecated.
Thanks for re-opening this. Was wondering why my builds were failing. Ill keep an eye on this thread!
I did it like this:
npm install [email protected]
This got me past the error.
Same here.
Should be fixed via #23103 (published in [email protected])
Most helpful comment
I did it like this:
npm install [email protected]