GraphQL:猫鼬updateMany的突变返回类型是什么?

时间:2018-06-27 10:40:07

标签: javascript reactjs graphql relay

考虑以下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返回的正确类型是什么?

0 个答案:

没有答案