How to write a graphql fragment for contenful generic RichText

Viewed 184

contentful automatically creates a schema based on the content of the backend. So if I have two entries A and B with both a richtext field it will create something like this:

type A {
  text: AText
}

type B {
  text: BText
}

type AText {
  json: JSON!,
  links: ATextLinks!
}
type BText {
  json: JSON!,
  links: BTextLinks!
}

In my case AText and BText are the same so I try to create a fragment like this

union GenericText = AText | BText
fragment on GenericText {
  json
}

but it does not know that the types overlap and throws an error. If I don't use fragments but create the query via simple string interpolation the "fragement" works fine for all RichText types.

Can I somehow declare a interface to which all theses rich text types conform on the client?

0 Answers
Related