Search code examples
schemagraphqlmutationprisma

graphql error: mutation with where not working


I am using Prisma GraphqQL and I got this error for a mutation with where selector: "You provided an invalid argument for the where selector on User"

Mutation:

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

Variables:

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

Result:

{
  "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"
    }
  ]
}

Schema:

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


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

Why this mutation is not working?

With colors: Mutation GraphQL Mutation GraphQL Schema Graphql Schema Graphql


EXTRA INFORMATION

Full code of this Project is here:

Graphql playground is here:

Console view (variable are empty): console view (variable are empty):

Query for user (with id: cjfsvcaaf00an08162sacx43i). So user can be found with "where" operator in query, but not in mutation. enter image description here


Solution

  • Your updateUser resolver is not implemented correctly:

    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},
      })
    }
    

    Your mutation has the two parameters data and where, but you expect the parameter list { id, name, email, role }.

    Either update your schema, or your resolver accordingly.

    Source: https://github.com/graphcool/prisma/issues/2211