分组 graphql 突变
Grouping graphql mutations
我正在尝试将我的突变分组为二级类型。架构已正确解析,但解析器未在 Apollo 中触发。这可能吗?这是我想要的查询:
mutation {
pets: {
echo (txt:"test")
}
}
这是我正在尝试的方法
架构:
type PetsMutations {
echo(txt: String): String
}
type Mutation {
"Mutations related to pets"
pets: PetsMutations
}
schema {
mutation: Mutation
}
解析器:
...
return {
Mutation: {
pets : {
echo(root, args, context) {
return args.txt;
}
},
}
假设您使用的是 apollo-server
或 graphql-tools
,您不能像那样在解析器映射中嵌套解析器。解析器映射中的每个 属性 都应该对应于您的模式中的一个类型,并且它本身是一个字段名称到解析器函数的映射。尝试这样的事情:
{
Mutation: {
// must return an object, if you return null the other resolvers won't fire
pets: () => ({}),
},
PetsMutations: {
echo: (obj, args, ctx) => args.txt,
},
}
旁注,您的查询无效。由于 echo
字段是一个标量,您不能为其选择字段的子选择。您需要删除空括号。
我正在尝试将我的突变分组为二级类型。架构已正确解析,但解析器未在 Apollo 中触发。这可能吗?这是我想要的查询:
mutation {
pets: {
echo (txt:"test")
}
}
这是我正在尝试的方法
架构:
type PetsMutations {
echo(txt: String): String
}
type Mutation {
"Mutations related to pets"
pets: PetsMutations
}
schema {
mutation: Mutation
}
解析器:
...
return {
Mutation: {
pets : {
echo(root, args, context) {
return args.txt;
}
},
}
假设您使用的是 apollo-server
或 graphql-tools
,您不能像那样在解析器映射中嵌套解析器。解析器映射中的每个 属性 都应该对应于您的模式中的一个类型,并且它本身是一个字段名称到解析器函数的映射。尝试这样的事情:
{
Mutation: {
// must return an object, if you return null the other resolvers won't fire
pets: () => ({}),
},
PetsMutations: {
echo: (obj, args, ctx) => args.txt,
},
}
旁注,您的查询无效。由于 echo
字段是一个标量,您不能为其选择字段的子选择。您需要删除空括号。