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
- Query
- Response
- cURL
query getProjects {
me {
accounts(first: 1) {
nodes {
projects(
first: 3
orderBy: [
{ field: name, direction: ASC }
{ field: maxLinks, direction: DESC }
]
) {
nodes {
name
maxLinks
}
}
}
}
}
}
{
"data": {
"me": {
"accounts": {
"nodes": [
{
"projects": {
"nodes": [
{
"name": "100k Marathon",
"maxLinks": 250
},
{
"name": "212 Project",
"maxLinks": 150
},
{
"name": "A New Hope",
"maxLinks": 100
}
]
}
}
]
}
}
}
}
curl -X POST -H "Content-Type: application/json" -H "apollographql-client-name: docs-example-client" -H "apollographql-client-version: 1.0.0" -H "x-auth-token: YOUR_API_SESSION_TOKEN" --data '{"query":"query getProjects { me { accounts(first: 1) { nodes { projects( first: 3 orderBy: [ { field: name, direction: ASC } { field: maxLinks, direction: DESC } ] ) { nodes { name maxLinks } } } } } }"}' https://api.lumar.io/graphql