Using GraphQL Fragments and Slices together

When using GraphQL fragments to query slices, the content type name, “body”, and slice type name are combined to form a fragment type. This is described here:

https://prismic.io/docs/graphql/query-the-api/retrieve-slice-content

However, this makes reusing these slices for other content types impossible. For example, say I have 2 content types and one slice type I want to share between them. One fragment will be:

fragment SliceFragment on ContentTypeABodySliceType {
field 1,
field 2,

}

fragment SliceFragment on ContentTypeBBodySliceType {
field 1,
field 2,

}

As you can see, these types are different and therefore requires the repetition of the slice’s fields. Is there a way around this, or does Prismic plan to support this in the future?

2 Likes

Hi @dturkington, thanks for reaching out about this. As far as I’m aware, you are correct that you’ll need to duplicate the fragment at the moment if you share a slice between Custom Types.

I agree that this can be approved, but I don’t believe that this is something that is planned for now. But I will pass this over to the @features-team to take a look at and add to our feature request tracker as a possible improvement for the future.

Thanks for the reply Levi. Can you provide an estimation of when this will be planned?

Unfortunately I can’t promise that it will be done, but the @features-team can tell you more.