Gatsby: [Discussion] gatsby-source-contentful requires at least one instance for schema

Created on 2 Jul 2019  路  7Comments  路  Source: gatsbyjs/gatsby

gatsby-source-contentful has a requirement that:

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

This obviously makes it hard to create empty states where there are no published content models. For example a job listing with no current open positions or a blog with no published posts yet. Currently I get the following build errors:

Cannot query field "allContentfulBlogPost" on type "Query". Did you mean "allContentfulPerson", "allContentfulTag", "allContentfulContentType", "contentfulPerson", or "contentfulTag"?

How do you normally handle these situations?

Would it not be possible to download the structure of the content models from contentful api and create empty graphql models so the build does not break?

E.g. an empty query for all blog posts could look like.

{
  data: {
    allContentfulBlogPost {
      edges: []
    }
  }
}
stale? question or discussion

Most helpful comment

Please reopen this. Urgent topic and there is an endless discussion about minor things in the PR so will take a while to get merged. Please advise with a workaround for the time being.

All 7 comments

Thank you for the detailed and well written issue, @marcuslindfeldt 馃檶

The schema customisation feature we added in Gatsby 2.2.0 makes it possible to solve this by the defining known schema shapes ahead of time (and not depending no inference and therefore content).

We currently have a work in progress PR for a rewrite of gatsby-source-contentful with support for this in https://github.com/gatsbyjs/gatsby/pull/12816

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

We will no longer have this limitation once https://github.com/gatsbyjs/gatsby/pull/12816 is merged and published 馃挭

Hiya!

This issue has gone quiet. Spooky quiet. 馃懟

We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 馃挭馃挏

Hey again!

It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.

Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!

Please reopen this. Urgent topic and there is an endless discussion about minor things in the PR so will take a while to get merged. Please advise with a workaround for the time being.

Any update or a possible workaround?

Got stuck in this issue for several days straight. The gatsby documentation doesn't provide the proper guide to solve this issue with a schema. The documentation contains just a lot of examples and for a new guy, it doesn't make sense at all. I would like to see a better explanation of why it breaks, how it actually works and where+how should user create a schema.
This is my StackOverflow post covering the issue and code I had.
https://stackoverflow.com/questions/64455525/cannot-query-field-x-on-type-y/64456887?noredirect=1#comment114086798_64456887

I managed to solve this a few months ago and this bug started showing up again for no reason when I didn't give any changes to my code :( This has to be fixed and I'm stuck as well.

Was this page helpful?
0 / 5 - 0 ratings