question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gatsby-source-graphql plugin re-runs createPage when using fragments

See original GitHub issue

Description

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

  1. In gatsby-node.js console.log() the blog title.
  2. gatsby develop and see that it outputs the titles twice
  3. in blog-post.js remove the titleImage fields from the exported query which includes a GatsbyImageSharpFixed fragment.
  4. 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:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vladarcommented, Dec 23, 2019

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-runs createPages when data in the node store changes. If you try the same example with gatsby build it will run createPages 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.

0reactions
rburgstcommented, May 11, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby Changelog | 5.3.0
This means that changes to highly-shared components (such as headers, footers, and common layouts) no longer require a rebuild of all pages that...
Read more >
Using GraphQL Fragments - Gatsby
Fragments allow you to reuse parts of GraphQL queries. It also allows you to split up complex queries into smaller, easier to understand...
Read more >
gatsby-graphql-source-toolkit - npm
A toolkit designed to simplify data sourcing from a remote GraphQL API into Gatsby.. Latest version: 2.0.3, last published: 9 days ago.
Read more >
Creating a Gatsby Site with WordPress Data - CSS-Tricks
OK, now it's time to configure the gatsby-source-graphql plugin. ... Gatsby make use of two APIs, onCreateNode and createPages , and ...
Read more >
Use GraphQL with Gatsby and Oracle Content Management
Task 2: Connect to the Gatsby Source GraphQL plugin ... slug 'people' to the proper path with component and context using the createPage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found