【问题标题】:graphql error: mutation with where not workinggraphql 错误:突变与 where 不工作
【发布时间】:2018-09-20 10:58:52
【问题描述】:

我正在使用 Prisma GraphqQL,但在 where 选择器的突变中出现此错误: "你为用户的 where 选择器提供了一个无效的参数"

变异:

mutation UpdateUserMutation($data: UserUpdateInput!, $where: UserWhereUniqueInput!) {
  updateUser(data: $data, where: $where) {
    id
    name
    email
    role
  }
}

变量:

{
  "data": {
    "name": "alan", "email": "alan@gmail.com", "role": "ADMIN"
  },
  "where": {
    "id": "cjfsvcaaf00an08162sacx43i"
  }
}

结果:

{
  "data": {
    "updateUser": null
  },
  "errors": [
    {
      "message": "You provided an invalid argument for the where selector on User.",
      "locations": [],
      "path": [
        "updateUser"
      ],
      "code": 3040,
      "requestId": "api:api:cjftyj8ov00gi0816o4vvgpm5"
    }
  ]
}

架构:

updateUser(
  data: UserUpdateInput!
  where: UserWhereUniqueInput!
): User


type UserWhereUniqueInput {
  id: ID
  resetPasswordToken: String
  email: String
}

为什么这个突变不起作用?

颜色: 突变图QL Schema Graphql


额外信息

本项目的完整代码here

Graphql Playgroundhere:

控制台视图(变量为空):

查询用户(ID:cjfsvcaaf00an08162sacx43i)。因此,可以在查询中使用“where”运算符找到用户,但不能在突变中找到。

【问题讨论】:

    标签: schema graphql mutation prisma


    【解决方案1】:

    您的 updateUser 解析器未正确实现:

    async function updateUser(parent, { id, name, email, role }, ctx, info) {
       // console.log( id, name, email)
      await ctx.db.mutation.updateUser({
        where: { id: id },
        data: {name: name, email: email, role: role},
      })
    }
    

    您的突变有两个参数 data 和 where,但您期望参数列表 { id, name, email, role }。

    要么更新你的架构,要么相应地更新你的解析器。

    来源:https://github.com/graphcool/prisma/issues/2211

    【讨论】:

    • 您可以将您的答案标记为解决问题:)
    • 是的 :) 我会这样做的!
    猜你喜欢
    • 2021-09-26
    • 2018-12-03
    • 1970-01-01
    • 2016-10-18
    • 2020-04-15
    • 2018-07-23
    • 2020-11-23
    • 2020-02-16
    • 2017-10-25
    相关资源
    最近更新 更多