Sorting
To sort our results we can make use of the orderBy parameter, which takes as a value an array of the corresponding Order types. These types are defined as:
type ExampleOrder {
field: ExampleOrderField!
direction: OrderDirection!
}
Where ExampleOrderField is the group (an enum) of available fields to sort a particular entity, and OrderDirection is defined as follows:
enum OrderDirection {
ASC
DESC
}
For example, for Project it would be:
type ProjectOrder {
field: ProjectOrderField!
direction: OrderDirection!
}
Example - getting projects sorted by name and maxLinks
getProjectsTry in Explorer
GraphQL
query getProjects {
me {
accounts(first: 1) {
nodes {
projects(
first: 3
orderBy: [
{ field: name, direction: ASC }
{ field: maxLinks, direction: DESC }
]
) {
nodes {
name
maxLinks
}
}
}
}
}
}
Multi-field sorting
You can sort by multiple fields by passing an array of order objects. The first field is the primary sort key, and subsequent fields break ties.
GetCrawlsSortedTry in Explorer
GraphQL
query GetCrawlsSorted($projectId: ObjectID!) {
getProject(id: $projectId) {
crawls(
first: 5
orderBy: [
{ field: status, direction: ASC }
{ field: finishedAt, direction: DESC }
]
) {
nodes {
id
status
finishedAt
}
}
}
}
In this example, crawls are first sorted by status alphabetically, then by finishedAt in descending order within each status group.
Sorting tips
- The
orderByargument is always an array, even when sorting by a single field. - Not all fields are sortable. Check the corresponding
OrderFieldenum in the schema for available sort fields (e.g.,ProjectOrderField,CrawlOrderField). - Sorting is applied server-side before pagination, so the first page always contains the top-ranked results.