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] Errors due to missing fields in GraphQL schema #3139

Closed
attfarhan opened this issue Dec 6, 2017 · 5 comments · May be fixed by danielres/gatsby#1
Closed

[gatsby-source-contentful] Errors due to missing fields in GraphQL schema #3139

attfarhan opened this issue Dec 6, 2017 · 5 comments · May be fixed by danielres/gatsby#1
Assignees

Comments

@attfarhan
Copy link
Contributor

attfarhan commented Dec 6, 2017

Suddenly ran into issues building and running my site with gatsby-source-contentful. I get several different errors, all of which stem from this error which occurs after the success update schema step:

GraphQL Error There was an error while compiling your site's GraphQL queries.
  Invariant Violation: GraphQLParser: Unknown field `file` on type `heroImage_2`. Source: document `BlogPosts` file: `GraphQL request`.

To explain this error, I have a field HeroImage on my content type in Contentful. Previously, I could access the file and url through a graphql request as follows:

heroImage{
  file {
     url
  }
}

Now, however, I cannot access the file and url, but I can only access a sys field on HeroImage_2. Why would this change? Is this based on the data coming through from Contentful?

The errors I see when building + developing my site:

When trying to deploy my site, I get the following error:

6:19:03 PM: error Building static HTML for pages failed
6:19:03 PM: See our docs page on debugging HTML builds for help https://goo.gl/yL9lND
6:19:03 PM: 
6:19:03 PM:   Error: Module build failed: SyntaxError: Unexpected end of JSON input
6:19:03 PM:   
6:19:03 PM:   - JSON.parse
6:19:03 PM:   
6:19:04 PM:   - index.js:4 Object.module.exports
6:19:04 PM:     [repo]/[json-loader]/index.js:4:49
6:19:04 PM:   
6:19:04 PM:   - @ ./.cache/sync-requires.js 37:13558-13667
6:19:04 PM:   

When running gatsby develop locally I get this error:


 ERROR  Failed to compile with 2 errors                                                                       18:45:22

 error  in ./.cache/json/file-path-file-name.json

Syntax Error: Unexpected end of JSON input
    at JSON.parse (<anonymous>)


 @ ./.cache/sync-requires.js 38:22893-23025
```.

This has happened twice today, and the first time it seemed to fix itself.  But it's come back now and I don't know how to move forward in debuggging this. 

Why would the GraphQL schema that Gatsby is referencing change when my content type in Contentful has not? Is this possibly an issue from Contentful themselves? 
@attfarhan attfarhan changed the title [gatsby-source-contentful] GraphQL Errors [gatsby-source-contentful] Errors due to missing fields in GraphQL schema Dec 6, 2017
@dbrookes
Copy link
Contributor

dbrookes commented Dec 9, 2017

Had the same Unexpected end of JSON input error from sync-requires.js, I upgraded Node to 8.9.3 and it seems to have fixed it

KyleAMathews added a commit that referenced this issue Dec 14, 2017
This bug was hard to track down as it manifested itself in a weird way.

Gatsby tracks external changes which indicate a need to re-run GraphQL
queries. Which is normally fine since Gatsby also is tracking which
queries would be dirtied by the external change (e.g. a query depends
on a file — when that file is changed, the query is "dirty" and needs
run again). But pages/layouts *without* queries weren't being tracked
which meant that on every external change, Gatsby would think it needed
to run those queries again.

During the build process. Gatsby assumes that external data won't change
so during the bootstrap, it waits for the initials set of queries to
finish running but during later stages, it doesn't.

Because sites with lots of pages with no queries were running their
queries over and over, this meant that occassionally webpack would try
to load a JSON file (queries are written out as JSON files) that wasn't
finished writing.

This PR fixes the problem as now during build, Gatsby only attempts to
run queries for page/layout components without queries during the
initial bootstrap.
@ghost ghost assigned KyleAMathews Dec 14, 2017
@ghost ghost added the review label Dec 14, 2017
@ghost ghost removed the review label Dec 14, 2017
@KyleAMathews
Copy link
Contributor

Should be fixed in #3218 lemme know if you're still seeing troubles!

@lsanwick
Copy link
Contributor

I'm still seeing this issue, but just the schema problem, nothing about JSON parsing problems.

@lsanwick
Copy link
Contributor

It's very strange, I don't usually see it in gatsby develop, but it's happening consistently on Netlify when building the site for deployment. Restarting the gatsby develop process seemed to fix it, but I'm not sure why. Maybe some sort of caching issue around the Contentful schema?

@lsanwick
Copy link
Contributor

Okay, attempting to link to unpublished media with the Delivery token in Contentful is the source of the problem here. Terribly hard to figure that out though, maybe there should be something about that in an FAQ for Gatsby and Contentful.

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

Successfully merging a pull request may close this issue.

5 participants