Documentation Center

GraphQL query result sorting

By (optionally) adding a sort expression to your query, you can specify that your query results must be returned to you with some kind of sorting applied.

By default, query results are returned with the following sorting applied:
  • Items other than Publications are returned sorted first by namespace ID, then by item ID.
  • Publications are returned sorted first by namespace ID, then by Publication ID.
For root fields and dynamic (metadata) fields (but not for language-separated fields), you can override this behavior by specifying a sort expression in your query, directly after the filter expression:
{
  items(
    filter {
      FILTEREXPRESSION
    },
    sort: {
      SORTEXPRESSION
    }

  ) {
      RETURNEDFIELDS
}

If you are querying Component Presentations, replace items with componentPresentations.

In this query, SORTEXPRESSION has the following structure:
sort: {
  sortBy: SORTFIELD
  order: SORTORDER
}
where:
  • SORTFIELD is the name of a field to sort on
  • SORTORDER is either Ascending or Descending
SORTFIELD can be one of the following:
Sort field nameSort field description
CREATION_DATEThe date on which the item was created
INITIAL_PUBLISH_DATEThe date on which the item was published for the first time
ITEM_IDThe unique identifier of the item
ITEM_TYPEThe type of the item
LAST_PUBLISH_DATEThe date on which the item was most recently published
NAMESPACE_IDThe unique identifier of the namespace (1 representing Tridion Sites and 2 representing Tridion Docs)
OWNING_PUBLICATION_IDIf this is a Tridion Sites item, the unique identifier of the owning Publication in the BluePrint hierarchy to which this item belongs
PUBLICATION_IDThe unique identifier of the Publication that contains this item
TITLEThe title of the item
UPDATED_DATEThe date on which the item was most recently updated