Hello guys, I’m using `graphql-yoga` with prisma ...
# orm-help
o
Hello guys, I’m using
graphql-yoga
with prisma 2, and I have some issues when creating items with
Enums
I got this error when I execute my mutation :
Copy code
Argument type: Provided value 
{
  set: [
    'CLOTHES'
  ]
}
of type Json on prisma.createOneItem is not a enum.
→ Possible values: Type.CLOTHES, Type.SHOES, Type.ACCESSORIES, Type.DECORATION
anyone have an idea on how enums works with mutations ? thanks you
r
@Omar Harras 👋 Could you share your schema if possible?
o
Copy code
model Item {
  id          String     @default(cuid()) @id
  title       String
  description String
  images      String[]
  thumbnail   String
  price       Float
  user        User        @relation(fields: [id], references: [id])
  condition   Condition   @default(NEW)
  type        Type        @default(CLOTHES)
}
Copy code
enum Type {
  CLOTHES
  SHOES
  ACCESSORIES
  DECORATION
}
@Ryan here is a part of my schema.prisma
r
Enums can be used directly like this then:
Copy code
await prisma.item.create({
    data: {
      description:'description',
      price: 10,
      thumbnail: 'thumbnail',
      title: 'title', 
      type: 'ACCESSORIES'
    }
  })
No
set
is required.
o
and in my mutation defintion should I set Type to a String ?
because now it’s like this :
Copy code
input TypeInput {
    set: [Type!]
  }
r
And what’s the definition of
Type
?
o
Copy code
enum Type {
    CLOTHES
    SHOES
    ACCESSORIES
    DECORATION
  }
r
Yes then this should work
o
I got this error instead :
Copy code
Argument type: Provided value 
{
  set: [
    'CLOTHES'
  ]
}
of type Json on prisma.createOneItem is not a enum.
→ Possible values: Type.CLOTHES, Type.SHOES, Type.ACCESSORIES, Type.DECORATION
r
What are you passing in Prisma?
o
mutation { createItem( title: “t shirt Adidas” brand: “Adidas” description: “T shirt Adidas blanc” color: “Rouge” categories: { set: MEN } type: { set: CLOTHES } ) }
Copy code
async createItem(parent, args, context) {
    console.log("createItem -> context", context)
    const item = await context.prisma.item.create(
      {
        data: { ...args },
      },
    );
    return item;
  },
did I miss something ?
r
Copy code
mutation {
  createItem(
    title: "t shirt Adidas"
    brand: "Adidas"
    description: "T shirt Adidas blanc"
    color: "Rouge"
    categories: "MEN"
    type: "CLOTHES"
)
}
The
categories
and
type
should be just like this. No
set
.
o
I got
Expected value of type TypeInput found CLOTHES
r
Copy code
mutation {
  createItem(
    title: "t shirt Adidas"
    brand: "Adidas"
    description: "T shirt Adidas blanc"
    color: "Rouge"
    categories: MEN
    type: CLOTHES
)
}
How about this?
o
same error 😕
r
Then I guess one thing you would need to do is pass this:
Copy code
mutation {
  createItem(
    title: "t shirt Adidas"
    brand: "Adidas"
    description: "T shirt Adidas blanc"
    color: "Rouge"
    categories: {
      set: MEN
    }
    type: {
      set: CLOTHES
    }
)
}
And at Prisma’s end, convert it to this:
Copy code
async createItem(parent, args, context) {
    console.log("createItem -> context", context)
    const item = await context.prisma.item.create(
      {
        data: { 
    title: args.title
    brand: args.brand
    description: args.description
    categories: args.categories.set
    type: args.type.set },
      },
    );
    return item;
  },
This is because Prisma accepts a direct value without
set
. If this still doesn’t work, it would be great if you could share a reproduction repo
o
thank you @Ryan it works
💯 1
but I did this :
Copy code
type: args.type.set[0]
because it did not accept an array of string
💯 1