gatsby-uc / plugins

Monorepo for plugins in the Gatsby User Collective.
https://gatsbyuc.dev
MIT License
58 stars 34 forks source link

bug(gatsby-source-strapi): GraphQL fragment queries only work if all possible components of a dynamic zone are actually used in the current content #475

Closed paulwellnerbou closed 1 month ago

paulwellnerbou commented 5 months ago

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

  1. Create a new Gatsby/Strapi project with the given template (see https://github.com/strapi/starters-and-templates/tree/main/packages/starters/gatsby-blog)
  2. Remove all components of (e.g.) "slider" from all example articles
  3. 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?

hrenaud commented 4 months ago

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.

laurenskling commented 1 month ago

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.