Gatsby: [gatsby-source-contentful] Invariant violation in build-node-types.js

Created on 18 Oct 2017  Â·  8Comments  Â·  Source: gatsbyjs/gatsby

I am encountering issues in formulating queries using graphql queries when speaking to contentful.

In particular the stacktrace I get is the following:

success source and transform nodes — 0.661 s
error UNHANDLED REJECTION


  Error: Invariant Violation: Encountered an error trying to infer a GraphQL type for: "images___NODE".   There is no corresponding node with the id field matching: "null"

  - invariant.js:42 invariant
    [ooni-website]/[invariant]/invariant.js:42:15

  - infer-graphql-type.js:258 validateLinkedNode
    [ooni-website]/[gatsby]/dist/schema/infer-graphql-type.js:258:5

  - infer-graphql-type.js:333 inferFromFieldName
    [ooni-website]/[gatsby]/dist/schema/infer-graphql-type.js:333:3

  - infer-graphql-type.js:562
    [ooni-website]/[gatsby]/dist/schema/infer-graphql-type.js:562:23

  - lodash.js:4944
    [ooni-website]/[lodash]/lodash.js:4944:15

  - lodash.js:3001 baseForOwn
    [ooni-website]/[lodash]/lodash.js:3001:24

  - lodash.js:4913
    [ooni-website]/[lodash]/lodash.js:4913:18

  - lodash.js:9359 Function.forEach
    [ooni-website]/[lodash]/lodash.js:9359:14

  - infer-graphql-type.js:536 inferObjectStructureFromNodes
    [ooni-website]/[gatsby]/dist/schema/infer-graphql-type.js:536:5

  - build-node-types.js:239 createNodeFields
    [ooni-website]/[gatsby]/dist/schema/build-node-types.js:239:34

  - build-node-types.js:79 fields
    [ooni-website]/[gatsby]/dist/schema/build-node-types.js:79:26

This error message is quite cryptic and I believe it's not related to my code, but rather to the contentful -> graphql transformation layer.

To reproduce the issue you can run the code from this repository at this commit: https://github.com/OpenObservatory/ooni-website/tree/df04defdf83a223ac4d9b8b130b20dc7907b5f27 via:

yarn run develop

Most helpful comment

I ran into the exact same error message. If the error occurred after you made changes to your Contentful models, rm -rf .cache might help.

All 8 comments

Hmm so the problem is that there's apparently a broken reference between two of your content in Contentful. I thought Contentful would enforce that but apparently not? In any case, source-contentful should double-check that a referenced node exists before creating the link.

If you want to try fixing this, look at the source for source-contentful and search for ___NODE which is how the links between nodes are created.

I ran into the exact same error message. If the error occurred after you made changes to your Contentful models, rm -rf .cache might help.

Hmm so the problem is that there's apparently a broken reference between two of your content in Contentful. I thought Contentful would enforce that but apparently not?

This was quite useful knowledge to further debugging. I had created all the content programmatically by querying the API, but had marked it as "draft" instead of "published".

Marking it all as published resolved the above error, but now I get:

error Plugin default-site-plugin returned an error

  Error:

The error message is empty, yet I still do see the content on the site.

@KyleAMathews is right about that, I wanna add the __NODE means the a property in a model type.

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

I am always having this issue unless I clear cache. Are there any more specific hints so we can fix this in the plugin?

same here, this is second issue I find it's closed because there is a "workaround" instead of being really fixed, way to build trust around your platform.

@itdsntwork @ryudice Could you open a new issue for this? The original report is from 2017, and the schema related parts of the code base have since been rewritten (e.g. the infer-graphql-type.js file mentioned in the above error message does not exist anymore). Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

magicly picture magicly  Â·  3Comments

kalinchernev picture kalinchernev  Â·  3Comments

KyleAMathews picture KyleAMathews  Â·  3Comments

andykais picture andykais  Â·  3Comments