Sorting
This is the documentation of the GraphQL Library version 6. For the long-term support (LTS) version 5, refer to GraphQL Library version 5 LTS. |
A sorting input type is generated for every object type defined in your type definitions. It allows for query results to be sorted by each individual field.
Using this example type definition:
type Movie @node {
title: String!
runtime: Int!
}
The following sorting input type and query are generated:
type Movie @node {
title: String!
runtime: Int!
}
enum SortDirection {
ASC
DESC
}
input MovieSort {
title: SortDirection
runtime: SortDirection
}
type Query {
movies(where: MovieWhere, sort: [MovieSort!], limit: Int, offset: Int): [Movie!]!
}
The following query fetches all movies sorted by runtime in ascending order:
query {
movies(sort: [
{
runtime: ASC
}
]
) {
title
runtime
}
}
If there is a relationship between the Movie
and an Actor
type, you can also sort when fetching the actors
field:
query {
movies {
title
runtime
actors(sort: [
{
surname: ASC
}
]
) {
surname
}
}
}
You can only sort query results based on relationship properties when using the connection API. |