This content originally appeared on DEV Community and was authored by Omar Dulaimi
Here's what you need to do:
1- Install the generator
- Using npm
npm install prisma-yup-generator
- Using yarn:
yarn add prisma-yup-generator
2- Add the generator to your Prisma schema
generator yup {
provider = "prisma-yup-generator"
}
3- Run npx prisma generate
for your schema(or the example below)
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
content String?
published Boolean @default(false)
viewCount Int @default(0)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}
Now you will have all possible Yup schemas generated for you!
This content originally appeared on DEV Community and was authored by Omar Dulaimi
Omar Dulaimi | Sciencx (2022-05-12T19:07:27+00:00) How to automatically generate Yup schemas from your Prisma schema. Retrieved from https://www.scien.cx/2022/05/12/how-to-automatically-generate-yup-schemas-from-your-prisma-schema/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.