codeflood logo

Experience Edge Schema for Content Hub ONE Tenants

The GraphQL schema used by Content Hub ONE is the same as that used by Content Hub. But there are a few differences between the two systems and the resultant GraphQL schema used by the Experience Edge tenants for these systems. In this post I'm going to explore the key differences you'll find when working with an Experience Edge tenant for each of these systems.

In my last post I detailed the Experience Edge Schema for Content Hub Tenants. Experience Edge dynamically generates the GraphQL schema for tenants of both Content Hub and Content Hub ONE the same way. They both iterate all the entity definitions and add fields to the top-level query field to allow retreiving an entity by ID, or for searching for entities by type. Associated types such as "sorts" and predicates are also generated for each entity definition.

The main areas in which the two systems differ are in how relations work and the lack of interfaces for CMP content types, as CMP is a feature of Content Hub.

Relations

In Content Hub, relations have a single type on either side. For example, the assetTypeToAsset relation links an entity of type M.Asset to an entity (or entities) of type M.AssetType. When traversing the assetTypeToAsset relation, we know there is only a single type on the other side of the relation, so the GraphQL schema uses that type.

However, Content Hub ONE supports multiple types on relations. When adding a reference field to a content type, no content types are selected to limit which content types are allowed to be selected for the reference field. The reference field allows selecting any other content item, regardless of the content type the item is based on.

In the GraphQL schema, this is achieved by generating a union type, which includes all content types that have been defined for the tenant.

For example, let's say I have a content type named Navigation which has a reference field named pages.

Reference field in Content Hub ONE

And I also have 4 other content types defined: Bio, Section Title, Text and Title.

Content types in Content Hub ONE

Using the Experience Edge GraphQL IDE I can inspect the pages field of the Navigation type to find it's type is Navigation__pages_Parent_Types_List!.

GraphQL type of Content Hub ONE references field

Because reference fields allow multiple selections the type of the field is a list, which allows for paging over the results. The actual results themselves are in the results field and are an array of Navigation__pages_Parent_Types. This type is a union type, which defines that the items appearing in this list can be any of the available content types.

union Navigation__pages_Parent_Types =
    Navigation
  | Title
  | Bio
  | SectionTitle
  | Text

To query the items included in the pages field, we must use GraphQL Fragments to specify the fields of each type that we're interested in.

query {
  navigation(id:"N3JdAUo91UuP9DhQSV0QAg") {
    pages {
      results {
        __typename
        ... on Title {
          id
          name
        }
        ... on Bio {
          id
          author
        }
        ... on Text {
          id
          title
        }
        ... on SectionTitle {
          id
          name
        }
      }
    }
  }
}

No CMP

The other major difference between in the GraphQL schema of a Content Hub and Content Hub ONE tenant is the lack of the CMP interfaces. CMP is a feature of Content Hub and isn't required in Content Hub ONE, so no need for the interfaces. Content Hub ONE itself is quite similar to CMP in how it works. In Content Hub, all CMP entities use the same entity definition M.Content, and then the content type is defined through the contentTypeToContent relation. The interfaces make it easier to work with CMP entities and treat them more like separate entity definitions, so we can query directly for specific content types:

query {
  allM_Content_Blog {
    results {
      id
      content_Name
    }
  }
}

But this isn't necessary in Content Hub ONE, where each content type is a separate definition.

query {
  allSectionTitle {
    results {
      id
      title
      subtitle
    }
  }
}

Conclusion

Although Content Hub and Content Hub ONE generate the GraphQL schema in the same manner, where the types and queries are generated based on the entity definition (and content types), Content Hub ONE supports multiple types on relations. This has an impact on how the relation field is generated in the GraphQL schema and how we go about querying for items included in the reference field. Apart from that and the lack of need for the CMP interfaces, the schemas are generated the same way.

Comments

Leave a comment

All fields are required.