gatsby-source-graphql plugin re-runs createPage when using fragments
See original GitHub issueDescription
If a page query contains a fragment, the graphql source plugin seemingly re-runs the whole create page query multiple times.
Steps to reproduce
This can be recreated from the graphql source example here: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-gatsby-source-graphql
- In gatsby-node.js
console.log()
the blog title. gatsby develop
and see that it outputs the titles twice- in blog-post.js remove the titleImage fields from the exported query which includes a GatsbyImageSharpFixed fragment.
gatsby develop
and see that it outputs the titles once.
Expected result
createPage should be called once per page.
Actual result
createPage is called twice per page.
Environment
System: OS: macOS 10.15.2 CPU: (12) x64 Intel® Core™ i7-8850H CPU @ 2.60GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.16.3 - /usr/local/bin/node Yarn: 1.16.0 - /usr/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Chrome: 78.0.3904.108 Firefox: 71.0 Safari: 13.0.4 npmPackages: gatsby: ^2.0.0 => 2.18.11 gatsby-image: ^2.0.34 => 2.2.36 gatsby-plugin-netlify: ^2.0.0 => 2.1.30 gatsby-plugin-sharp: ^2.0.30 => 2.3.7 gatsby-source-filesystem: ^2.0.27 => 2.1.42 gatsby-source-graphql: ^2.0.0 => 2.1.28 gatsby-transformer-sharp: ^2.1.17 => 2.3.9 npmGlobalPackages: gatsby-cli: 2.8.8
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
Looks like double call of
createPages
is unrelated to fragments. The root cause is the following resolver:https://github.com/gatsbyjs/gatsby/blob/768df7dbc2c1dff9f0dd735f7585391a3c9d6ef9/examples/using-gatsby-source-graphql/gatsby-node.js#L57-L62
As you see a new node is created while the query is running (for a remote file). And
gatsby develop
re-runscreatePages
when data in the node store changes. If you try the same example withgatsby build
it will runcreatePages
only once.Unfortunately, this is the expected behavior for
gatsby-source-graphql
at the moment. See #15906 for some context.The current workaround is to create remote file nodes separately in the
sourceNodes
API and then fetch those nodes in the resolver mentioned above.You are correct, i had 2 graphql versions in my dependencies. Sorry for not reading the error well enough. Thanks so much! It works now. I will update my test repo so people can find a working solution if they encounter the same issue.