[英]apollo graphql pass arguments to resolve function
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();
}
}
}
Ie 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 https://learngraphql.com/basics/query-variables/3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.