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

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

Open
paulwellnerbou opened this issue Apr 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@paulwellnerbou
Copy link

paulwellnerbou commented Apr 15, 2024

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?

@paulwellnerbou paulwellnerbou added the bug Something isn't working label Apr 15, 2024
@hrenaud
Copy link

hrenaud commented May 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants