Anthony Magnus
04/15/2020, 6:01 PMtype Customer {
id: ID! @id
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
name: String
email: String
phone: String
user: User
cart: [CartItem]!
orders: [Order]!
}
type CartItem {
id: ID! @id
quantity: Int! @default(value: 1)
dish: Dish!
customer: Customer!
}
type Dish {
id: ID! @id
name: String!
price: Float!
description: String!
isAvailable: Boolean! @default(value: true)
category: String
restaurant: Restaurant!
}
type Restaurant {
id: ID! @id
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
user: User
name: String!
street: String!
number: String !
addition: String
zip: String!
city: String!
dishes: [Dish]!
orders: [Order]!
}
I can query the data inside the playground area with the following query
query {
customer(where: { id: "ck8zwslgs00da0712cq88e3oh" } ) {
id
cart(where: { dish: { restaurant: { id: "ck904gwl400mz0712v0azegm3" } } }) {
quantity
dish {
name
price
restaurant {
id
name
}
}
}
}
}
But I can't figure out how to do this nested filter with the prisma client.
Tried some things
const data = await ctx.db.query.customer({
where: {
AND: [
{
id: args.customerID
},
{
cart: {
dish : {
restaurant: {
id: args.restaurantID
}
}
}
}
]
}
}, info);
const data = await ctx.db.query.customer({
where: {
id: args.customerID
cart: {
dish : {
restaurant: {
id: args.restaurantID
}
}
}
}
}, info);
const data = await ctx.db.query.customer({
where: {
id: args.customerID
},
cart: {
where: {
dish : {
restaurant: {
id: args.restaurantID
}
}
}
}
}, info);
const data = await ctx.db.query.customer({
where: {
id: args.customerID
},
cart: {
dish : {
restaurant: {
where: {
id: args.restaurantID
}
}
}
}
}, info);
The first one returns an error "Field \"cart\" is not defined by type CustomerWhereUniqueInput".
The last two are returning every cartItem from the customer.
Someone can help me out with this?