【问题标题】:Graphql Cannot create property 'clientMutationId' error on mutation?Graphql无法在突变时创建属性'clientMutationId'错误?
【发布时间】:2018-02-28 02:16:43
【问题描述】:

这是我要执行的突变:

const GraphQLAddPlayerResponseMutation = mutationWithClientMutationId({
      name: 'AddPlayerResponse',
      inputFields: {
        cdx: { type: new GraphQLNonNull(GraphQLInt) },
      },
      mutateAndGetPayload: ({cdx}) => {
        var cdxAdded = addplayerResponse(cdx);
        console.log("cdxAdded = ",cdxAdded)
        return cdxAdded;
      }, // what u return on mutateAndGetPayload is available on outputFields
      outputFields: {
        playerResponse: {
          type: GraphQLInt,
          resolve: ({cdxAdded}) => {
            console.log("outputFields cdxAdded = ",cdxAdded)
            return cdxAdded
          },
        },
        viewer: {
          type: GraphQLUser,
          resolve: () => getViewer(),
        },
      },
    });

无法弄清楚代码有什么问题,它会登录 mutateAndPayload:

 mutateAndGetPayload: ({cdx}) => {
            var cdxAdded = addplayerResponse(cdx);
            console.log("cdxAdded = ",cdxAdded)
            return cdxAdded;
          },

但我认为 outputFields 没有被评估,因为它没有登录控制台,我收到了这个错误:

{
  "data": {
    "addPlayerResponse": null
  },
  "errors": [
    {
      "message": "Cannot create property 'clientMutationId' on number '3'",
      "locations": [
        {
          "line": 4,
          "column": 3
        }
      ],
      "path": [
        "addPlayerResponse"
      ]
    }
  ]
}

帮助?

【问题讨论】:

    标签: graphql relayjs graphql-js


    【解决方案1】:

    将return cdxAdded; 替换为return { cdxAdded };(猜测)

    【讨论】:

      猜你喜欢
      • 2017-04-26
      • 2021-08-27
      • 2021-06-23
      • 2019-07-26
      • 1970-01-01
      • 2016-02-23
      • 2019-11-21
      • 2016-10-18
      • 2018-09-19
      相关资源
      最近更新 更多