I am creating an ecommerce api using GraphQL. My prisma schema is
model Product {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
name String
price Int
stocks Int
}
model User {
id Int @id @default(autoincrement())
name String
email String @unique
password String
Orders Order[]
}
model Order{
id Int @id @default(autoincrement())
product Product @relation(fields: [productId], references: [id])
productId Int
user User @relation(fields: [userId], references: [id])
userId Int
@@unique([productId, userId])
}
What should be my graphql schema and resolver function in order to create a relation whenever a user orders a product?