The Experience Edge schema
Sitecore Experience Edge has a read-only GraphQL schema designed to accommodate common front-end use cases for headless Sitecore development. It exposes limited information about Sitecore items. For example, there are no Standard Fields available.
The following queries are available as entry points:
-
item
- allows querying an item by path or ID. -
layout
- allows querying an item by site and route path, typically for the purpose of accessing its Layout Service JSON (rendered
). -
search
- allows constructing a Boolean field search query for finding items by field value or common properties.
For more information, see the example queries and use the Docs tab in the GraphQL testing UI of the Preview endpoint IDE.
Template projection
The types available in the Experience Edge schema reflect the template definitions of the Sitecore instance that published to it. You can enable strongly-typed template fields by using inline fragments that select fields from specific types.
In Sitecore, multiple templates can have the same name and templates with field names that conflict with core fields on the item graph type. In GraphQL, the names of types and fields must be unique. When a naming collision occurs, the item or field item with the newest creation date has _{guid}
appended to the name. The creation date is used because the ordering must be stable, and a graph type name must never change after it has been referenced.
GraphQL types are only created for templates that follow the Helix content structure. This means that GraphQL types are generated only for templates under the following paths:
-
<foundation>/sitecore/templates/Foundation</foundation>
-
<feature>/sitecore/templates/Feature</feature>
-
<project>/sitecore/templates/Project</project>
-
<userdefined>/sitecore/templates/User Defined</userdefined>
Pagination
Paginated queries and fields in the Experience Edge schema, such as the search query, utilize a cursor-based system to request result pages.
For paginated queries:
-
Query arguments include
first
(number of results to return) andafter
(the beginning cursor).first
has a default value of10
. -
Query results include
pageInfo
withhasNext
(whether there are more results) andendCursor
(used in the after argument to obtain the next page). -
Query results also include
total
(provides the total number of available results).NoteThe first argument has a special meaning to query the complexity calculation used by the underlying GraphQL library of the
Preview
schema. In particular, using the nestedchildren
field on the Item graph type, can cause errors, such as Query is too complex to execute. The following section includes recommendations for handling query complexity.
Query complexity
The Experience Edge query complexity is limited to 250. We recommend you test your query before using it in a runtime environment, to make sure it meets the complexity requirements. If your query is too complex, try the following:
-
Break it into multiple smaller queries. For example, use one query to retrieve a data set, and apply subsequent queries to that dataset. Large queries of multiple objects increase query complexity substantially.
-
Remove unnecessary fields from the query.
Available fields for content search
In Experience Edge, you can use the GraphQL search
query on the special fields listed in the following table. When querying templates, you can only query user-defined fields and the following special fields. For example, you can query the user-defined title
field of the sample item template, but not _Sortorder
.
Field |
Description |
---|---|
|
Contains all template GUIDs, including base templates. Can be used to find all the items that use the template in the hierarchy. |
|
Contains parent items, and can be used to retrieve descendants of an item by its GUID. For example, if you use a contains clause and the ID of the |
|
The ID of the item’s immediate parent. |
|
The item name. |
|
The item language. |
|
Shows whether the item has presentation details/layout data. |
This is an example of searching for items using the CONTAINS
operator in a user defined field:
query Search {
search(
where: {
name: "title",
value: "Sitecore",
operator: CONTAINS
}
) {
results {
id
name
}
}
}
Here's an example of searching for items using an exact match in a user defined field:
query Search {
search(
where: {
name: "_parent"
value: "110D559FDEA542EA9C1C8A5DF7E70EF9"
operator: EQ
}
) {
results {
id
name
}
}
}
Here's an example of combining multiple clauses:
query Search {
search(
where: {
AND: [
{
name: "_parent"
value: "110D559FDEA542EA9C1C8A5DF7E70EF9"
operator: EQ
},
{
name: "title"
value: "another"
operator: CONTAINS
}
]
}
) {
results {
id
name
}
}
}