I have a schema with associated categories and markers
type Category {
id: Int
name: String
parent: Category
children: [Category]
markers: [Marker]
}
type Marker {
id: Int
name: String
categories: [Category]
}
type Query {
category(limit: Int, offset: Int): [Category]
marker(limit: Int, offset: Int): [Marker]
}
schema {
query: Query
}
I can now write a query like this:
query{
category(limit: 3){
name
markers{
name
}
}
}
How can I define possible arguments for the markers as well? -->
query{
category(limit: 3){
name
markers(limit: 3){
name
}
}
}
so I can use the argument in the resolvers -->
export const resolvers = {
Query: {
async category(root, args, context) {
return Categories.findAll({limit: args.limit, offset: args.offset});
},
async marker(root, args, context) {
return Markers.findAll({limit: args.limit, offset: args.offset});
},
},
Category: {
async markers(category){
return category.getMarkers();
}
}
}
I.e. I can pass it into the query resolvers since it is defined in the schema, but I cannot apply it to the markers resolver within the category type
You can put query variables anywhere in your schema, not just at the top level:
https://learngraphql.com/basics/query-variables/3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With