GraphQL: Каков тип возврата мутации для mongoose updateMany? - PullRequest
0 голосов
/ 27 июня 2018

Рассмотрим следующую мутацию 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?

...