0

I am using Prismic, and I have two identical custom types, one is called Content and one is called Theme. Their data is identical so I would like to reuse my fragments, is it possible?

An example fragment looks like:

import { graphql } from 'gatsby'

export const CollectionFragment = graphql`
    fragment CollectionFragment on PrismicContentBodyCollection {
    ...
    }
`

So right now it is hardcoded to PrismicContentBodyCollection.

A GraphiQL example would look like:

query MyQuery {
  allPrismicTheme {
    nodes {
      data {
        body {
          ... on PrismicThemeBodyHero {
            slice_type
          }
        }
      }
    }
  }
  allPrismicContent {
    nodes {
      data {
        body {
          ... on PrismicContentBodyHero {
            slice_type
          }
        }
      }
    }
  }
}
fuzz
  • 195
  • 13

1 Answers1

0

I'm not 100% sure, but I don't think this is possible because it needs to be specified with the type that matches the type of document you're looking for to make sure that your query is valid and that the fields you are trying to receive actually exist on the object.

So in your case, if you're looking for the Collection Slice, the fragments would need to be PrismicThemeBodyCollection and PrismicContentBodyCollection respectively.

I have made a few tests myself and I keep getting errors that say I'm missing the correct content type name

Pawichi
  • 66
  • 5