Skip to main content

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!
}
Operation: query getProjects { me { accounts(first: 1) { nodes { projects( first: 3 orderBy: [ { field: name, direction: ASC } { field: maxLinks, direction: DESC } ] ) { nodes { name maxLinks } } } } } }Response Example: { "data": { "me": { "accounts": { "nodes": [ { "projects": { "nodes": [ { "name": "100k Marathon", "maxLinks": 250 }, { "name": "212 Project", "maxLinks": 150 }, { "name": "A New Hope", "maxLinks": 100 } ] } } ] } } } }
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.

Operation: query GetCrawlsSorted($projectId: ObjectID!) { getProject(id: $projectId) { crawls( first: 5 orderBy: [ { field: status, direction: ASC } { field: finishedAt, direction: DESC } ] ) { nodes { id status finishedAt } } } }Variables: { "projectId": "TjAwN1Byb2plY3Q2MTMy" }Response Example: { "data": { "getProject": { "crawls": { "nodes": [ { "id": "TjAwNUNyYXdsMTU4MzI0Ng", "status": "Crawling", "finishedAt": null }, { "id": "TjAwNUNyYXdsMTU4MzI0NQ", "status": "Finished", "finishedAt": "2025-01-15T10:30:00.000Z" }, { "id": "TjAwNUNyYXdsMTU4MzI0NA", "status": "Finished", "finishedAt": "2025-01-14T09:00:00.000Z" } ] } } } }
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 orderBy argument is always an array, even when sorting by a single field.
  • Not all fields are sortable. Check the corresponding OrderField enum 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.