Sorting Query Results
GraphQLize enables sorting the query results using the orderBy
argument. By default any of the table columns can be used to sort the query results.
Sorting by single column
query languagesSortedByName {
# sorts using the `name` column in the `language` table
languages(orderBy: {name: ASC}) {
name
}
}
If you'd like to sort it in descending order, replace ASC
with DESC
.
query languagesSortedByNameInDescOrder {
languages(orderBy: {name: DESC}) {
name
}
}
Sorting by multiple columns
You can sort by multiple columns as well!
query {
# sorts the `actor` table by the `first_name` column
# and then by `last_name` column in descending order
actors(orderBy: {firstName: ASC, lastName: DESC}) {
firstName
lastName
}
}
Sorting nested objects
GraphQLize also supports sorting nested objects.
query {
countryByCountryId(countryId: 2) {
country
# sorting one-to-many relationship
cities(orderBy: {city: DESC}) {
city
}
}
}
query {
actorByActorId(actorId: 148) {
firstName
# sorting many-to-many relationship
films(orderBy: {title: DESC}) {
title
}
}
}
note
Currently, sorting nested objects in MySQL is not supported. in a later release.