Omar Harras
09/06/2020, 8:15 PMgraphql-yoga
with prisma 2, and I have some issues when creating items with Enums
I got this error when I execute my mutation :
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 youRyan
09/07/2020, 6:10 AMOmar Harras
09/07/2020, 6:59 AMmodel 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)
}
Omar Harras
09/07/2020, 6:59 AMenum Type {
CLOTHES
SHOES
ACCESSORIES
DECORATION
}
Omar Harras
09/07/2020, 7:00 AMRyan
09/07/2020, 7:03 AMawait prisma.item.create({
data: {
description:'description',
price: 10,
thumbnail: 'thumbnail',
title: 'title',
type: 'ACCESSORIES'
}
})
No set
is required.Omar Harras
09/07/2020, 7:14 AMOmar Harras
09/07/2020, 7:15 AMinput TypeInput {
set: [Type!]
}
Ryan
09/07/2020, 7:15 AMType
?Omar Harras
09/07/2020, 7:17 AMenum Type {
CLOTHES
SHOES
ACCESSORIES
DECORATION
}
Ryan
09/07/2020, 7:18 AMOmar Harras
09/07/2020, 7:21 AMArgument 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
Ryan
09/07/2020, 7:21 AMOmar Harras
09/07/2020, 7:23 AMOmar Harras
09/07/2020, 7:24 AMasync createItem(parent, args, context) {
console.log("createItem -> context", context)
const item = await context.prisma.item.create(
{
data: { ...args },
},
);
return item;
},
Omar Harras
09/07/2020, 7:24 AMRyan
09/07/2020, 7:25 AMmutation {
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
.Omar Harras
09/07/2020, 7:26 AMExpected value of type TypeInput found CLOTHES
Ryan
09/07/2020, 7:28 AMmutation {
createItem(
title: "t shirt Adidas"
brand: "Adidas"
description: "T shirt Adidas blanc"
color: "Rouge"
categories: MEN
type: CLOTHES
)
}
How about this?Omar Harras
09/07/2020, 7:28 AMRyan
09/07/2020, 7:32 AMmutation {
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:
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 repoOmar Harras
09/07/2020, 7:52 AMOmar Harras
09/07/2020, 7:53 AMtype: args.type.set[0]
because it did not accept an array of string