考虑以下GraphQL突变以更新数据库上的许多寄存器(mongodb和mongoose):
const activateCustomers = {
type: CustomerType,
description: "Activate multiple customers",
args: {
ids: {
name: "ids",
type: new GraphQLList(GraphQLID)
}
},
resolve(root, args, context) {
let criteria = {
_id: { $in: ids }
};
return CustomerModel.updateMany(
criteria,
{ status: "Active" },
{ multi: true }
);
}
};
运行时,出现以下GraphQL错误:
{
"errors": [
{
"message": "Expected value of type \"Customer\" but got: [object Object].",
"locations": [
{
"line": 4,
"column": 3
}
],
"stack": "Expected value of type \"Customer\" but got: [object Object].
GraphQL request (4:3)
3: ) {
4: activateCustomers(ids: $ids) {
^
5: id
at invalidReturnTypeError (/workspace/customer/node_modules/graphql/execution/execute.js:766:10)
at completeObjectValue (/workspace/customer/node_modules/graphql/execution/execute.js:758:13)
at completeValue (/workspace/customer/node_modules/graphql/execution/execute.js:660:12)
at /workspace/customer/node_modules/graphql/execution/execute.js:617:14
at process._tickCallback (internal/process/next_tick.js:68:7)",
"path": [
"activateCustomers"
]
}
],
"data": {
"activateCustomers": null
}
}
为了返回mutation
结果需要从我的updateMany
返回的正确类型是什么?