gatsby: `getNode` returns null on upgrade from gatsby-source-contentful 2.1.88 to 2.2.5

Description

Upgrading gatsby-source-contentful from 2.1.88 to 2.2.5 resulted in build errors, as we’re unable to use gatsby’s getNode function with a valid node id string. Using the graphql search I can find the node.

Of note: it’s a parent node to the current node we’re inspecting

Expected result

I should be able to fetch a node by getNode on gatsby-source-contentful 2.2.5

Actual result

getNode returns null

Environment

System: OS: macOS 10.15.2 CPU: (16) x64 Intel® Core™ i9-9980HK CPU @ 2.40GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node Yarn: 1.19.2 - /usr/local/bin/yarn npm: 6.4.1 - ~/.nvm/versions/node/v10.13.0/bin/npm Languages: Python: 3.7.6 - /usr/local/opt/python/libexec/bin/python Browsers: Chrome: 80.0.3987.163 Safari: 13.0.4 npmPackages: gatsby: ^2.20.12 => 2.20.12 gatsby-image: ^2.0.13 => 2.0.33 gatsby-plugin-canonical-urls: ^2.1.5 => 2.1.5 gatsby-plugin-catch-links: ^2.1.5 => 2.1.17 gatsby-plugin-favicon: ^3.1.6 => 3.1.6 gatsby-plugin-google-gtag: ^1.0.17 => 1.0.17 gatsby-plugin-hotjar: ^1.0.1 => 1.0.1 gatsby-plugin-netlify-cache: ^1.0.0 => 1.0.0 gatsby-plugin-polyfill-io: ^1.1.0 => 1.1.0 gatsby-plugin-react-helmet: ^3.0.12 => 3.0.12 gatsby-plugin-robots-txt: ^1.3.0 => 1.3.0 gatsby-plugin-sass: ^2.0.1 => 2.0.7 gatsby-plugin-sharp: ^2.4.5 => 2.4.5 gatsby-plugin-sitemap: ^2.0.5 => 2.0.5 gatsby-plugin-typescript: ^2.0.15 => 2.0.15 gatsby-plugin-webpack-bundle-analyzer: ^1.0.5 => 1.0.5 gatsby-source-contentful: ^2.2.5 => 2.2.5 gatsby-source-filesystem: ^2.0.2 => 2.0.5 gatsby-source-stripe: ^3.0.4 => 3.0.4 gatsby-transformer-sharp: ^2.3.14 => 2.3.14 npmGlobalPackages: gatsby-cli: 2.11.5 I’ve also updated node to 12.16.1 – and still fails

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 22 (5 by maintainers)

Most upvoted comments

You should open an issue if this is still a problem with the latest contentful source plugin

I can confirm that gatsby-source-contentful@2.1.100 has solved my problem but it’s not the latest version of course.

Curious, any progress of this case?

Not stale. Still waiting to be fixed.

Same here, though I am querying the other way around, from parent to child. 2.2.x did not work, getNode returns undefined for me. I downgrade to 2.1.100 which works perfectly fine.

Thanks for taking a look! Let me know if you need more information!

So, internally, we have a gatsby plugin that adds some fields to our content/node (this case in particular is generating the path for the page and adding it as a field on the content/node).

We have a content model that has another content model as a child. When we are doing our transformations on the child node, we get the reference to the parent node like so

  const parentNode = rest.getNode(
    node['name of content type of parent node___NODE'][0]
  )

It’s important to note that node['name of content type of parent node___NODE'][0] does return a node ID, and in graphiql, we’re able to find a node with that ID when querying in allContentfulNameOfContentTypeOfParentNode and filtering for IDs matching the one returned above.

If it helps, you can look at our branch builds on gatsby builds: upgrade/gatsby-source-contentful