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 S
field.Cedalio automatically generates an input type for ordering the results of a root or nested collection query based on the indexed fields in your schema.
Schema
Generated types
type Post @model {
title: String
}
type Post {
id: ID!
title: String
}
type PostOrderByInput {
createdAt: OrderByDirection
}
enum OrderByDirection {
ASC
DESC
}
You can pass the field and direction to the
orderBy
field of a collection query:ASC
DESC
query {
userCollection(first: 100, orderBy: { createdAt: ASC }) {
edges {
node {
title
}
}
}
}
query {
userCollection(first: 100, orderBy: { createdAt: DESC }) {
edges {
node {
title
}
}
}
}
You can also update the order of any relations:
ASC
DESC
query {
userCollection(first: 100) {
edges {
node {
title
friends(first: 100, orderBy: { createdAt: ASC }) {
edges {
node {
body
}
}
}
}
}
}
}
query {
userCollection(first: 100) {
edges {
node {
title
friends(first: 100, orderBy: { createdAt: DESC }) {
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.
Last modified 4mo ago