Tryign to do I am trying to Query my Products and to also show what Categories they are under.
Here is my Prisma Schema
model Product {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @db.VarChar(80)
description String @db.VarChar(240)
ingredients String[]
price Float
category Category[]
}
model Category {
id String @id @default(uuid())
createdAt DateTime @default(now())
name String
product Product[]
}
This shows that there is a relationship between the Products and Categories
However, when I query in Apollo Studio, it doesn't show up.
Here is my schema in my Prisma Studio as well to show the relationship
Any information would be greatly appreciated!
Here is also the resolver.
export const resolvers = {
Query: {
allCategories:(_parent:any, _args:any, context: Context) => {
return context.prisma.category.findMany()
},
allProducts:(_parent:any, _args:any, context:Context) => {
return context.prisma.product.findMany()
},
productById:(_parent: any, {id}, context: Context) => {
return context.prisma.product.findUnique({
where: {
id
}
})
},
categoryById:(_parent:any, {id}, context: Context) => {
return context.prisma.category.findUnique({
where: {
id
}
})
},
productsByCategory:(_parent:any, {category}, context: Context) => {
return context.prisma.product.findMany({
select: {
category: true
}
})
}
},