logo
logo

GraphQL schema

Schemas describe the way that data is organized and structured. The GraphQL server uses a schema to describe your data as a graph. This schema defines a hierarchy of types with fields that are populated from your backend data stores. The schema also specifies exactly which queries are available for clients to execute against your data graph.

Important

You cannot use mutations in the Sitecore Content Hub implementation of GraphQL.

It is from the GraphQL schema that you know which data types are available. If you need to check, you can use GraphQL by querying the __schema field. This way, you can see the schema and the types.

The __schema field is always available on the root type of a query.

To display the schema, run the following command in the IDE of either the Preview API or the Delivery API:

{
  __schema {
    types {
      name
    }
  }
}

Note

You can also access the schema from the Schema tab available on the right-hand side of both the Delivery and Preview API IDEs.

Types

The GraphQL types show how the entities in Content Hub are mapped in GraphQL. The following table shows examples of Content Hub and GraphQL types:

GraphQL typeContent Hub entity definition
M_AssetM.Asset
M_BrandM.Brand
M_ContentM.Content
M_ContentTypeM.ContentType
M_PCM_ProductM.PCM.Product
M_PCM_ProductCategoryM.PCM.ProductCategory
Tip

To find the associated GraphQL type of a Content Hub entity definition, replace the . with _.

There are also virtual types, created for CMP content type entities, with a list type:

CMP content typeGraphQL typeGraphQL list type
BlogM_Content_BlogM_Content_BlogList
Social mediaM_Content_SocialMediaMessageM_Content_SocialMediaMessageList
WhitePaperM_Content_WhitePaperM_Content_WhitePaperList
RecipeM_Content_RecipeM_Content_RecipeList
WebinarM_Content_WebinarM_Content_WebinarList
EmailM_Content_EmailM_Content_EmailList
AdvertisementM_Content_AdvertisementM_Content_AdvertisementList

Scalar types

Scalar types are similar to primitive types in your favorite programming language. They always resolve to concrete data.

GraphQL's default scalar types are:

Scalar typeDescription
IntA signed 32‐bit integer.
FloatA signed double-precision floating-point value.
StringA UTF‐8 character sequence.
BooleanA true or false value.
ID (serialized as a string)A unique identifier used to fetch an object, or as key for a cache. Although it is serialized as a string, an ID is not intended to be human‐readable.

GraphQL includes the following custom scalar types:

Scalar typeDescription
MultiplierPathThe multiplier path type represents a valid GraphQL multiplier path string.
DateTimeProvides the date time in 2021-01-19T17:33:00.000Z format.
LongLong variables are extended size variables for number storage.
DecimalDecimal variables are stored as 96-bit (12-byte) unsigned integers, together with a scaling factor and a value indicating whether the decimal number is positive or negative.

Object types

Most of the types you define in a GraphQL schema are object types. An object type contains a collection of fields, each of which can be either a scalar type or another object type.

With a REST-based API, different entities would probably be returned by different endpoints (for example, http://hostname/api/m.asset and http://hostname/api/m.content). The flexibility of GraphQL enables clients to query both resources with a single request.

Docs

The IDE docs define the use of schema and types.

Can we improve this article ? Provide feedback