Hello everyone, I have a settings page where the...
# orm-help
j
Hello everyone, I have a settings page where the user can update their email, first name, and last name. I am getting the following error when I submit the data from the settings page:
Copy code
[GraphQL error]: Message: You provided an invalid argument for the where selector on User., Location: , Path: updateUser

Uncaught (in promise) Error: GraphQL error: You provided an invalid argument for the where selector on User.
schema.graphql
Copy code
...
# import * from './generated/prisma-client/prisma.graphql'

updateUser(email: String, firstName: String, lastName: String, password: String): User!
...
Mutation.js
Copy code
async updateUser(parent, args, ctx, info) {
    // First check if there is a user with that email
    const user = await ctx.db.query.user({ where: { email: args.email } });
    if (user) {
      throw new Error(`The email ${args.email} is already being used`);
    }
    const updatedUser = await ctx.db.mutation.updateUser({
      where: { id: args.id },
      data: {
        email: args.email,
        firstName: args.firstName,
        lastName: args.lastName
      }
    });
    return updatedUser;
  }
Frontend Mutation:
Copy code
const UPDATE_USER_MUTATION = gql`
  mutation UPDATE_USER_MUTATION(
    $email: String!
    $firstName: String!
    $lastName: String!
  ) {
    updateUser(email: $email, firstName: $firstName, lastName: $lastName) {
      id
      email
      firstName
      lastName
    }
  }
`;
What am I doing wrong here?
j
You do not pass the “id” arg in the mutation, thus, where: { id: args.id } does not work
you should either add id in the mutation, or get the id from your first user query