Collection Order

The GraphQL Content API allows users to specify the fields and direction to sort on root collection queries.

For example, for the type FriendlyUser structured in the following way:

type FriendlyUser {
sys: Sys
name: String
age: Int
}

The schema defines the following order input enum type:

enum FriendlyUserOrder {
name_ASC
name_DESC
age_ASC
age_DESC
sys_id_ASC
sys_id_DESC
}

Order enum values can be passed to collection queries of their corresponding type to sort the result set.

For example, to find the oldest FriendlyUser, write the following query:

query {
friendlyUserCollection(order: [age_DESC], limit: 1) {
items {
name
}
}
}

Collections can be sorted by multiple fields, each of them with a direction information.

For example, to order FriendlyUsers by their age (descending) first and for items with same age it should sort by name (ascending), write the following query:

query {
friendlyUserCollection(order: [age_DESC, name_ASC]) {
items {
name
age
}
}
}

You can order collections in linkedFrom:

query {
catCollection {
items {
name
linkedFrom {
friendlyUserCollection(order: [age_DESC, name_ASC]) {
items {
firstName
}
}
}
}
}
}

Note: You cannot order the entryCollection field.

query {
catCollection {
items {
name
linkedFrom {
friendlyUserCollection(order: [age_DESC, name_ASC]) {
items {
firstName
}
entryCollection {
__typename
}
}
}
}
}
}

Limitations

It is not possible to order on fields of type Link, Text, Location, Object, or RichText.

Note: When using allowedLocales, the order argument that you have passed will not be applied to the fallback values, which might make the result seem to be unordered.