1. Experience Edge APIs

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.
  • site - allows querying content sites for site information.

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 the Sitecore back end, you can give the same name to templates and fields. However, 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.

Note

GraphQL types are generated 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) and after (the beginning cursor). first has a default value of 10.

  • Query results include pageInfo with hasNext (whether there are more results) and endCursor (used in the after argument to obtain the next page).

  • Query results also include total (provides the total number of available results).

    Note

    The 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 nested children 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

Query complexity refers to a numerical score assigned to a GraphQL query based on how resource-intensive it is to execute. This score helps prevent overly complex queries from degrading performance or risking denial-of-service. Experience Edge queries have a complexity limit. 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:

Note

The cost of Experience Edge (delivery) queries can't be configured.

  • 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.

Because of an inherent difference in data structure, complexity is calculated differently between the delivery endpoint and preview endpoint (the content management back end). We have introduced default settings so that complexity calculations will match as closely as possible; however, it's impossible to match them completely.

Some configuration options for the preview endpoint are available in the sitecore.config file, in the complexityConfiguration object:

<!--
  COMPLEXITY CONFIGURATION
  It is possible to conduct denial of service attacks by constructing extremely expensive to run GraphQL queries.
  The complexity configuration defeats that by limiting how complex of a query will be run.

  maxDepth: the maximum nesting depth in a query. maxDepth values lower than 15 will prevent /ui from running.
  fieldImpact: the average impact of adding a list field to a query (e.g. how many average items it would return).
  maxComplexity: the maximum field impact a query can have before it's rejected. With a fieldImpact at 2, values of maxComplexity less than 250 will prevent /ui from running.
-->
<complexityConfiguration type="GraphQL.Validation.Complexity.ComplexityConfiguration, GraphQL" patch:source="Mvp.Environment.GraphQL.config">
  <maxDepth>15</maxDepth>
  <maxComplexity>10000</maxComplexity>
  <fieldImpact>2</fieldImpact>
</complexityConfiguration>

Alternatively, in non-production environments, you can raise the complexity limitation of the preview endpoint to large numbers that can’t be reached, and run queries to estimate what the cost would be for Experience Edge (delivery) queries in a production environment.

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.

FieldDescription
_templatesContains all template GUIDs, including base templates. Can be used to find all the items that use the template in the hierarchy.
_pathContains 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 /home path, the results include /home and its children, such as /home/about_us.
_parentThe ID of the item’s immediate parent.
_nameThe item name.
_languageThe item language.
_hasLayoutShows whether the item has presentation details/layout data.
_latestversionBoolean that determines whether only the latest version of the item is shown.
Note

The _latestversion field is processed differently in the Preview and Delivery schemas. If you set _latestversion to true in a query to the Delivery API, it returns the latest publishable version of the item. The value of _latestversion can only be set to true in calls to the Delivery API. If it is set to false, it returns an error. If you set _latestversion to true in a query to the Preview API, it returns the latest available version. If it is set to false, it returns all versions of the item.

Search operator behavior

The search query supports the following operators.

Note

Search operator behavior differs depending on whether you are querying the Delivery endpoint or the Preview endpoint (which uses a tokenized search index).

  • EQ (Equals) - matches only user defined fields whose value is an exact match.

    • On the Delivery endpoint, this operator matches only user defined fields whose value is an exact match. The entire field must match the search value exactly, and partial matches are not returned.

      For example, searching for ipsum with the EQ operator will not match a field containing lorem ipsum dolor sit amet, but it will match a field whose value is exactly ipsum.

    • On the Preview endpoint, works as the CONTAINS operator for text fields because all text fields in the Solr search index are tokenized by default. This means it may return multiple results, even when an exact match is expected.

      For example, searching for ipsum with the EQ operator might return results for fields containing lorem ipsum dolor sit amet.

      To ensure exact matching with EQ in the Preview endpoint, use the SearchQueryFieldMapping feature to map tokenized fields to non-tokenized computed fields. See also the related support article KB1003665.

    Use this operator when you need precise, whole-field matching, but be aware of tokenization behavior on the Preview endpoint.

  • CONTAINS - performs a substring match within a field.

    • On the Delivery endpoint, the value is matched as-is without tokenization or ranking.

      For example, searching for ipsum with the CONTAINS operator matches any field where the value appears anywhere within the text, such as lorem ipsum dolor sit amet.

    • On the Preview endpoint, the CONTAINS operator can return multiple results based on tokenized field values. This is because the Preview endpoint uses a tokenized search index.

    Use this operator for partial text matches and filtering content based on words or phrases within a field.

Note

The GraphQL search field is designed for filtering content, not for implementing full-text or site search functionality. For more advanced search capabilities, consider using a dedicated search service.

Search query examples

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
    }
  }
}

Working with media

You can apply changes to an image directly in Edge. The following options are supported for image manipulation:

Query parameterDescription
wThe image width.
hThe image height.
mwThe maximum width of the image.
mhThe maximum height of the image.
fThe image file format. The following values are supported
- generates images in an avif format, if possible, and if not, falls back to webp.webp - generates images in a Google webp format.jpeg - generates images in interlaced progressive JPEG format, in which data is compressed in multiple passes of progressively higher detail.baseline-jpeg - generates images in a baseline sequential JPEG format. Use in cases when target devices don't support progressive JPEG or other modern file formats.json - instead of generating an image, outputs information about the image in JSON format. The JSON object contains data such as image size (before and after resizing), the source image MIME type, and file size.
If you have suggestions for improving this article, let us know!