Ordering
By default all records are returned in ascending order by the createdAt
system field.
You can change the order (ASC
, DESC
) by updating the collection query using the orderBy
field.
Grafbase automatically generates an input type for ordering the results of a root or nested collection query based on the indexed fields in your schema.
type Post @model {
title: String
}
You can pass the field and direction to the orderBy
field of a collection query:
query {
userCollection(first: 100, orderBy: { createdAt: ASC }) {
edges {
node {
title
}
}
}
}
You can also update the order of any relations:
query {
userCollection(first: 100) {
edges {
node {
title
friends(first: 100, orderBy: { createdAt: ASC }) {
edges {
node {
body
}
}
}
}
}
}
}
createdAt
is the only field supported currently. You will soon be able to add your own indexes to fields to allow ordering by other fields.