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 type | Content Hub entity definition |
---|---|
M_Asset | M.Asset |
M_Brand | M.Brand |
M_Content | M.Content |
M_ContentType | M.ContentType |
M_PCM_Product | M.PCM.Product |
M_PCM_ProductCategory | M.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 type | GraphQL type | GraphQL list type |
---|---|---|
Blog | M_Content_Blog | M_Content_BlogList |
Social media | M_Content_SocialMediaMessage | M_Content_SocialMediaMessageList |
WhitePaper | M_Content_WhitePaper | M_Content_WhitePaperList |
Recipe | M_Content_Recipe | M_Content_RecipeList |
Webinar | M_Content_Webinar | M_Content_WebinarList |
M_Content_Email | M_Content_EmailList | |
Advertisement | M_Content_Advertisement | M_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 type | Description |
---|---|
Int | A signed 32‐bit integer. |
Float | A signed double-precision floating-point value. |
String | A UTF‐8 character sequence. |
Boolean | A 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 type | Description |
---|---|
MultiplierPath | The multiplier path type represents a valid GraphQL multiplier path string. |
DateTime | Provides the date time in 2021-01-19T17:33:00.000Z format. |
Long | Long variables are extended size variables for number storage. |
Decimal | Decimal 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