gatsby-source-contentful production build breaking if content is removed from Contentful field

Created on 11 Nov 2017  ·  9Comments  ·  Source: gatsbyjs/gatsby

os version: windows 10 (10.0.15063 Build 15063)
node version: v8.4.0
gatsby version: 1.9.108
gatsby-source-contentful version: 1.3.17

Summary

Production build breaks with a graphql schema error when Contentful optional field is empty in all entries.

success update schema — 0.100 s
⠂ extract queries from componentsTrace: GraphQLParser: Unknown field `price` on type `ContentfulGiftBox`. Source: document `boxQuery` file: `GraphQL request`.
    at graphqlError (C:\Projects\Supagifts\node_modules\gatsby\dist\internal-plugins\query-runner\graphql-errors.js:196:11)
...

Reproduction Steps

  1. Set up a basic site using gatsby-source-contentful
  2. Set up an optional (non required) field in Contentful
  3. Add data to this field in at least one entry
  4. Utilise this field in graphql layer
  5. Run gatsby build and note that site builds as expected.
  6. Remove data from the optional field
  7. Run gatsby build and note that the site build fails.

Notes:

I've started investigating this on a local PR branch, but need a little assistance in choosing an approach to fix, as I'm very new to graphql. Options:

  • In packages\gatsby-source-contentful\src\normalize.js, coalesce all field values (entryItemFields[entryItemFieldKey]) from null to an empty string or other flagged value.
  • Override gatsby-source-contentful's gatsby-node.js createPage behaviour
  • I've been reading through gatsby's graphql implementation but I'm not really able to make sense of whether there are any entrypoints for the gatsby-source-contentful to override this

Most helpful comment

Hey Folks,
I haven't tested this but this might be a p[otential Clean workaround that does not require creating dummy content.

https://medium.com/@Zepro/contentful-reference-fields-with-gatsby-js-graphql-9f14ed90bdf9

All 9 comments

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues as many of them have already been resolved with the latest updates or explained in a previous issue.

Feel free to open a new one if you still experience this problem or a similar one! 👍

I think it's fine to close this one. Issue #4847 is the same thing and it links to #4261 and #3344.

Hey Folks,
I haven't tested this but this might be a p[otential Clean workaround that does not require creating dummy content.

https://medium.com/@Zepro/contentful-reference-fields-with-gatsby-js-graphql-9f14ed90bdf9

@Khaledgarbaya Doesn't seem to work with a single reference type (rather than one-to-many) since the field (contentSections in the example) doesn't exist in the schema at all.

+1 watching this

I'm also having this issue.

Also having this issue

Same here, deleting a post on contentful breaks the app. Any workarounds?

Running into this issue as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jimfilippou picture jimfilippou  ·  3Comments

ghost picture ghost  ·  3Comments

benstr picture benstr  ·  3Comments

theduke picture theduke  ·  3Comments

totsteps picture totsteps  ·  3Comments