updateNode mutation: Field \"where\" is not defined by type

prisma

#1

I’m trying to setup the updateNode mutation in graphql with Prisma running on GraphQL-yoga server. Here’s the error I’m receiving when I try to run the mutation:

“Variable “$_v0_data” got invalid value { data: { name: “Test” }, where: { id: “cjqulnr0yftuh0a71sdkek697” } }; Field “data” is not defined by type CocktailUpdateInput.\nVariable “$_v0_data” got invalid value { data: { name: “Test” }, where: { id: “cjqulnr0yftuh0a71sdkek697” } }; Field “where” is not defined by type CocktailUpdateInput.”

Here’s my mutation resolver:

const Mutation = {
  async updateCocktail(parent, args, ctx, info) {
    const data = { ...args };
    delete data.id;
    const where = {id: args.id};
    return await ctx.db.mutation.updateCocktail({ data, where }, info);
  },
}

datamodel.prisma:

type Cocktail {
  id: ID! @unique
  name: String!
  info: String
  glass: Glass
  ingredients: [Ingredient]
  steps: [Step]
}

schema.graphql

type Mutation {
  updateCocktail(data: CocktailUpdateInput!, where: CocktailWhereUniqueInput!): Cocktail
}

and finally here’s what I’m trying to execute in playground:

mutation{
  updateCocktail(
    where: {id: "cjqulnr0y0tuh0a71sdkek697"},
    data: {
      name: "Test"
    }
  ){
    id
    name
  }
}

Variable X got invalid value. Field “0” is not defined by type
#2

I think you are giving the data object the wrong values, try this:

const Mutation = {
  async updateCocktail(parent, { data : {id, ...data}}, ctx, info) {
    const where = {id: args.id};
    return await ctx.db.mutation.updateCocktail({ data, where }, info);
  },
}

#3

Thanks for getting me on the right track! In the end I just ended up going with:

async updateCocktail(parent, args, ctx, info) {
  return await ctx.db.mutation.updateCocktail({ args }, info);
},

#4

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.