When building a GraphQL API, is it possible to allow arguments on nested query properties? i.e. I've implemented an orderBy
arg for a top-level tasks
query like so:
query {
tasks(orderBy: { order: asc }) {
title
}
}
and this works fine, but I would like to be able to query a collection
of task
s and add the query arguments to the nested tasks
property like this:
query {
collection {
id
name
tasks(orderBy: { order: asc }) {
title
}
}
}
It doesn't recognize the arguments by default, so I assume if it is possible, then there is some further set up required. I get this error when I try that query: "Unknown argument \"orderBy\" on field \"tasks\" of type \"Collection\"."
P.S. I'm using graphql-yoga
with prisma
on the backend.
Do you use nexus/schema and nexus-plugin-prisma ? If you do, you have to activate ordering in your collection task model like this
t.model.tasks({ ordering: true })