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
AscendingorDescending
SORTFIELD can be one of the following:
| Sort field name | Sort field description |
|---|---|
CREATION_DATE | The date on which the item was created |
INITIAL_PUBLISH_DATE | The date on which the item was published for the first time |
ITEM_ID | The unique identifier of the item |
ITEM_TYPE | The type of the item |
LAST_PUBLISH_DATE | The date on which the item was most recently published |
NAMESPACE_ID | The unique identifier of the namespace (1 representing Tridion Sites and 2 representing Tridion Docs) |
OWNING_PUBLICATION_ID | If this is a Tridion Sites item, the unique identifier of the owning Publication in the BluePrint hierarchy to which this item belongs |
PUBLICATION_ID | The unique identifier of the Publication that contains this item |
TITLE | The title of the item |
UPDATED_DATE | The date on which the item was most recently updated |