Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-source-contentful] Invariant violation in build-node-types.js #2518

Closed
hellais opened this issue Oct 18, 2017 · 9 comments
Closed

[gatsby-source-contentful] Invariant violation in build-node-types.js #2518

hellais opened this issue Oct 18, 2017 · 9 comments

Comments

@hellais
Copy link

hellais commented Oct 18, 2017

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
@hellais hellais changed the title [contentful] Invariant violation in build-node-types.js [gatsby-source-contentful] Invariant violation in build-node-types.js Oct 18, 2017
@KyleAMathews
Copy link
Contributor

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.

@ghost
Copy link

ghost commented Oct 19, 2017

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.

@hellais
Copy link
Author

hellais commented Oct 19, 2017

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.

@ptchiangchloe
Copy link

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

@KyleAMathews
Copy link
Contributor

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!

@itdsntwork
Copy link

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

@ryudice
Copy link

ryudice commented Aug 9, 2019

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.

@stefanprobst
Copy link
Contributor

@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!

@HuyAms
Copy link

HuyAms commented Jan 30, 2022

I face up with the same issue with gatsby 4. How did you solve the issue @hellais ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants