Contentful logo

Contentful Community

Inheritance/polymorphism

Hello,

Does anyone know WHY Contentful (and most other headless CMS products like GraphCMS) do not support inheritance by interface, but the concept of polymorphism at field level by using a union as both seems to be useful and add value for different use cases?

Sometimes it is important to know the type and make sure the object has some fields (interface inheritance) and sometimes it is not important and polymorphism by a union field is useful.

Also any other solution/model design patterns?

So I want to achieve this (at the GraphQL layer):

interface ContentItem {
  title: string;
}

type SpecificContentItemA implements ContentItem {
  body: string;
}

type SpecificContentItemB implements ContentItem {
  body: string;
}

type Space {
  items: ContentItem;
}

Instead of the current feature of Contentful:

type SpecificContentItemA {
  body: string;
}

type SpecificContentItemB {
  body: string;
}

type Space {
  items: SpecificContentItemA | SpecificContentItemB;
}

Thanks!