Goal
My goal is to be able to via Apollo Studio, Filter my products based on the category they have. Here is my Prisma Schema followed by my graphql schema.
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[]
moveActive Boolean @default(false)
price Float
category Category[]
}
model Category {
id String @id @default(uuid())
createdAt DateTime @default(now())
name String
product Product[]
}
Apollo Schema
type Category {
id:ID
name: String
product: [Product]
},
input CategoryFilterInput {
id:ID
name: String
},
type Product {
id: ID
name: String
description: String
ingredients: [String]
moveActive: Boolean
price: Float
category: [Category]
},
type Query {
allCategories: [Category]
allProducts: [Product]
productById(id:ID): Product
categoryById(id:ID): Category
productsByCategory(categoryFilterInput: CategoryFilterInput): [Product]
# categoryByProduct(product: Product): Category
},
When I run the server, I get this error when trying to filter for “Mixed Drink”
Thus, I go to my resolver
productsByCategory:(_parent:any, {category, categoryFilterInput: CategoryFilterInput}, context: Context) => {
return context.prisma.product.findMany({
where: {
category: CategoryFilterInput.name || undefined,
}
})
}
I have been trying to figure this out for like 2 days and wanted to reach out for assistance.