The goal is simple, I want to query enum field in the where clause. Example
prisma version is: "prisma": "3.11.0"
schema.prisma
model Todo {
id Int @default(autoincrement()) @id
title String
content String
status TodoStatus @default(IN_PROGRESS)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
enum TodoStatus {
IN_PROGRESS
DONE
}
api call
app.get('/todos', (req, res){
const { status } = req.query
const todos = await prisma.todo.findMany({
where: { status: status },
orderBy: {
id: "asc",
},
});
res.json(todos);
})
Frontend I use Next.js and it is a select option
example
<select
id="todo"
name="todo"
onChange={(e) => setSelectedStatus(e.target.value as Status)}
>
{[Status.IN_PROGRESS, Status.DONE].map((status: Status) => {
return (
<option value={status}>{todoStatusToString[status]}</option>
);
})}
</select>
The enum value from Next.js
export enum Status {
IN_PROGRESS = "IN_PROGRESS",
DONE = "DONE",
ALL = "ALL",
}
export const todoStatusToString = {
[Status.IN_PROGRESS]: "In progress",
[Status.DONE]: "Done",
[Status.ALL]: "All",
};
the req.query will be sent from clientside in this format
localhost:3000/todos?status=DONE
{ status: "DONE" }
or localhost:3000/todos?status=IN_PROGRESS
{ status: "IN_PROGRESS" }
I know that Prisma is built-in to be typesafe. So my assumption is because the data that we get from the frontend is a string type while the enum on Prisma is looking for either IN_PROGRESS or DONE specifically if we send "DECLINED" to status where clause it will spit the same error.
Any help would be appreciated!

DONEorIN_PROGRESSas string should work. I just tried it out and it worked for me. What version of Prisma and Database are you using? I tried it and it worked in PostgreSQL and prisma client verison of3.7.0"@prisma/client": "3.10.0"this is my prisma version.