Sorting your data
Sorting in our GraphQL API is done using the sort parameter on top of your connections. In which you can specify the fields and the direction of the sorting for each field.
The structure of a sort parameter look like this:
field- the name of the field from your content type that you want to sort the data based on. It's an enum based on the fields that your content type contains.direction- the direction of the sorting: ASC/DESC
Example:
query {
allPost(
first: 5,
sort: [
{
field: publishedDate,
direction: DESC,
}
]
) {
edges {
node {
id
title
publishedDate
}
}
}
}
Since the sort accepts a list of sorting parameters, you can also sort based on multiple fields at the same time.