relate-app / gatsby-source-strapi-graphql

A Gatsby source plugin for building websites using Strapi as a data source
BSD Zero Clause License
32 stars 9 forks source link

Fetch dynamic zone data from multiple fragments #27

Closed youmeokay closed 2 years ago

youmeokay commented 2 years ago

Hi!

First of all, thanks to this great plugin I am able to use incremental builds on gatsby clouds. It solved so many problems and I am quite happy I made the change. Thank you!

Right now I am running into a problem regarding fetching dynamic zone data from multiple fragements. The idea is to render components on a dynamic zone called 'Modules'.

Working Example on a single module:

export const query = graphql`
  fragment Modules on StrapiComponentSharedRichText {
    __typename
    ... on StrapiComponentSharedRichText {
      body
    }
  }

What I want to achieve is to get all data in one query:

export const query = graphql`
  fragment Modules on StrapiComponentSharedQuoteStrapiComponentSharedRichTextUnion {
    __typename
    ... on StrapiComponentSharedRichText {
      body
    }
    ... on StrapiComponentSharedQuote {
      body
    }
  }
`

but it throws this trying to build;

GraphQLError: Unknown type "StrapiComponentSharedQuoteStrapiComponentSharedRichTextUnion".

Is there another way to combine them? Am I missing something?

timbrandin commented 2 years ago

The error tells me it can't find that type, check localhost:8080/__graphql if that type is available in the place your querying for it.

youmeokay commented 2 years ago

I wasn't preceise enough I guess. Anyway, I managed to fix and get around it and I think it's not a problem regarding this. Thank you anyway for the response.