Query with filter

I’m a beginner, half a day I’ve been racking my brains, I can’t think of how to make a request

type Review  {
	id: ID! 
	userId: User! 
	productId: Product! 
	rate: Int! 
    buyTime: DateTime! @search
	comment: String 
    dignity: String
    flaws: String
    conclusion: String
}

My wrong option -

query MyQuery($filter: ProductFilter) {
        queryReview {
            productId(filter: $filter) {
                id
            }
            buyTime
            comment
            dignity
            flaws
            conclusion
            id
            rate
            userId{
                user_name
            }
        }
    }

Need to do queryReview filtered by productId
Please help!!!

1 Like

Try by having an inverse edge on Product:

type Product {
  ...
  reviews: [Review] @hasInverse(field: productID)
}

Then you could do:

query {
  getProduct(id: '0x1') {
    reviews {
      id
      userId
      ...
    }
}

Otherwise you get into the nested filter territory, which you can’t yet do in GraphQL. The workaround is custom dql, which you would have to learn as a separate query language.

J

2 Likes

Thanks