Closed zhesha closed 1 year ago
Hey @zhesha , I have encountered the same problem. This is the problem that can NOT be handled by gatsby source strapi but the solution that worked for me is here.
{
// Path where the type definitions will be saved to
path: `schema.gql`,
update: true,
}
yarn build
after that you would see schema.gql
in the root of your gatsby project.update: true,
to update: false,
in the gatsby-plugin-schema-snapsho config.NOTE: never switch to update: true with empty fields because schema.gql would not create with all fields.
hope it works for you.
assuming your component is named elements-background
, change to this:
createTypes(`
type STRAPI__COMPONENT_ELEMENTS_BACKGROUND implements Node {
color: String
}
type STRAPI_TOP_BAR implements Node {
background: STRAPI__COMPONENT_ELEMENTS_BACKGROUND @link(from: "id", by: "background___NODE")
}
`)
because the component is a relation, you need to link it
The solution with gatsby-plugin-schema-snapshot works fine. Thanks, @everythinginjs. But I have a bunch of problems so I decided not to update, and stay in the previous version.
Thanks for your interest in this project. This plugin is moving into the Gatsby User Collective and this repo will be archived. Please open an issue in that repository, submit a PR if you'd like to see this implemented, or join us on Discord if you have questions!v
It's not working with optional fields. As I try to query data in my template like:
It gives error
Cannot query field "color" on type "STRAPI_TOP_BAR".
if the color field is not set in strapi. It's an optional field so I expect that it can be queried and give menull
if it's not set.It can be fixed by defining custom types, but they are not working with nested types.
In this case,
color
works just fine, butbackground
is alwaysnull
. So I end up in a situation where I can't have optional fields, or when I can't reuse elements in strapi, both are not good.gatsby-source-strapi version: 2.0.0.
It happens after updating strapi and plugin versions. I had strapi version "3.6.5", gatsby version "^3.1.2" and gatsby-source-strapi version "1.0.2", and it works fine. After updating strapi to version "4.3.9", and gatsby-source-strapi version to "^2.0.0" it stop working. It would be great if it will be fixed, or some workaround given, thanks.