Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Nested Filtering with prisma-bindings #5073

Closed
AnthonyMagnus opened this issue Apr 15, 2020 · 1 comment
Closed

Nested Filtering with prisma-bindings #5073

AnthonyMagnus opened this issue Apr 15, 2020 · 1 comment
Labels
status/stale Marked as state by the GitHub stalebot

Comments

@AnthonyMagnus
Copy link

I've working on a food order platform and I would like to query all the added dishes (cartitems) inside a customers cart from a given restaurant.

My datamodel looks like this:

type 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?

@AnthonyMagnus AnthonyMagnus changed the title Nested Filtering with prisma-client Nested Filtering with prisma-bindings Apr 16, 2020
@stale
Copy link

stale bot commented May 31, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status/stale Marked as state by the GitHub stalebot label May 31, 2020
@stale stale bot closed this as completed Jun 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/stale Marked as state by the GitHub stalebot
Projects
None yet
Development

No branches or pull requests

1 participant