Skip to main content

Sorting

You can sort by one or more fields by using the sorting parameter.

The sorting parameter is an array where each item has the following options.

  • field! - The name of the field to sort by.
  • direction! - The direction to sort either ASC or DESC.
  • nulls? - Optional field to set nulls sort order NULLS_FIRST or NULLS_last

In this example we sort by title descending.

{
todoItems(sorting: [{ field: title, direction: DESC }]) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
node {
id
title
completed
created
updated
}
cursor
}
}
}

In this example we sort by completed and title.

{
todoItems(
sorting: [
{ field: completed, direction: ASC }
{ field: title, direction: DESC }
]
) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
node {
id
title
completed
created
updated
}
cursor
}
}
}

Setting a default sort

When querying the default is based on the persistence layer. You can override the default by using the QueryOptions decorator on your DTO.

You can find the documentation and an example in the QueryOptions reference.