plugins
plugins copied to clipboard
bug(gatsby-source-strapi): GraphQL fragment queries only work if all possible components of a dynamic zone are actually used in the current content
Describe the bug
The GraphQL API exposed by Gatsby considers only existing content. This leads to errors when building/running the project if the current content is not using a certain component in a dynamic zone. But is has to be mentioned/queried to handle it.
To Reproduce
- Create a new Gatsby/Strapi project with the given template (see https://github.com/strapi/starters-and-templates/tree/main/packages/starters/gatsby-blog)
- Remove all components of (e.g.) "slider" from all example articles
- Try to build/run your project
You will get this error:
GraphQLError: Unknown type "STRAPI__COMPONENT_SHARED_MEDIASTRAPI__COMPONENT_SHARED_QUOTESTRAPI__COMPONENT_SHARED_RICH_TEXTSTRAPI__COMPONENT_SHARED_SLIDERUnion". Did you mean "STR
API__COMPONENT_SHARED_MEDIASTRAPI__COMPONENT_SHARED_QUOTESTRAPI__COMPONENT_SHARED_RICH_TEXTUnion"?
Expected behavior
Project should build and run like before, just without the image slider components
System Info
See versions in https://github.com/strapi/starters-and-templates/tree/main/packages/starters/gatsby-blog
I am not completely sure where this bug is supposed to be addressed. Am I doing something wrong? Is the example starter buggy? Is it something in strapi? Or in Gatsby?
This is a well-known problem: an empty field in an entity (Single type or Collection type) is not detected, and so is not added, or is removed if the field is empty, to the schema.gql file. There are two ways to solve the problem: either fill all fields for an entity, generate the schema, then block its regeneration (use the gatsby-plugin-schema-snapshot plugin). Or use the 2 plugins I've developed. One for Strapi https://market.strapi.io/plugins/nova-datas-mocker to mock APIS and the other for Gatsby https://github.com/NovaGaia/gatsby-plugin-strapi-datas-mocker#readme to "simplify" the management of this problem.
I even manually add all my types, the same shape they would be created if they were filled. 🥲 So yes, this is documented. We know.