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] Optional fields #29556

Closed
lambert-velir opened this issue Feb 17, 2021 · 1 comment
Closed

[gatsby-source-contentful] Optional fields #29556

lambert-velir opened this issue Feb 17, 2021 · 1 comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@lambert-velir
Copy link

Description

I'd like to have optional fields in my Contentful models. The problem is stated on https://www.gatsbyjs.com/plugins/gatsby-source-contentful/:

At the moment, fields that do not have at least one populated instance will not be created in the GraphQL schema.

If there doesn't exist an entry with a certain optional field, and the graphql query is expecting that field, then the gatsby build will break.

Here's our real world example:

We have our build triggered by a Contentful webhook whenever an Entry changes in contentful. Imagine we have some entries that have an optional field, eg, email. We add some entries with email populated, write our graphql queries and build the site, everything works.

One day, the content authors decided that they don't want to have the emails show on the frontend, so they delete the emails from all the entries. The webhook fires and it starts a build. At this point, no entry has an email in it, so the schema doesn't have email in it either. The graphql query was written to include an email, but it's no longer in the schema, so the build will break.

Our current workaround involves using gatsby-plugin-schema-snapshot and maintaining a whole host of stub content in Contentful that we need to publish every time we want to update any Contentful models and schema.gql. To say the least, it's not a very efficient workflow.

The "At the moment" in the documentation suggests this might change in the future. Is it on the roadmap to include all possible fields in the graphql schema to avoid this situation? Is it possible to build the schema based on the model instead of the data?

Steps to reproduce

  1. Create a Contentful model with a name and email.
  2. Create an entry with just a name (leave email blank)
  3. Run project and open graphiql, email is not available in graphql

Expected result

All possible fields should be available in graphql, including email

Actual result

Only name is available

@lambert-velir lambert-velir added the type: bug An issue or pull request relating to a bug in Gatsby label Feb 17, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 17, 2021
@LekoArts
Copy link
Contributor

This is a duplicate of #28892

@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

2 participants