-1

How can i solve this problem with complex searching in products?

This is what i have now as a standard get products and search on them.

query getProducts($limit: Int, $offset: Int, $searchQuery: String) {
  products_products(limit: $limit, offset: $offset, where: {_or: [{title: {_ilike: $searchQuery}}, {shortDescription: {_ilike: $searchQuery}}], active: {_eq: true}}) {
    __typename
    id
    shortDescription
    title
    likes {
      userId
    }
    images(where: {main: {_eq: true}}) {
      image
    }
    categories {
      category {
        title
      }
    }
  }
}

i have products table, categories table, join table(productId, categoryId), later on there would be reviews table, wishlist table

  1. how to show products only in any category (record in join table)?
  2. how to show products with reviews 3.5+ ?

You know how it is with complex filtration.

Can someone show me how it could be done? Lastly .. im using flutter with optimistic results, so thats why i chose this structure of query. it makes sense when "replicating" the state of wishlist.

Ne Xen
  • 1
  • 2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 08 '22 at 02:03

1 Answers1

1
  1. how to show products only in any category (record in join table)?

You can filter on related data as well

query {
  product(where: { category: { name: { _eq: "Kitchen" } } })
}
  1. how to show products with reviews 3.5+ ?

I assume you mean an average review of 3.5 stars or greater?

There is a brand new feature in Hasura called Aggregation Predicates that lets you do this

See last month's community call demo for how to use it:

By the way, if you are building an e-commerce type application, there is a sample application which already implements much of this functionality so you can see how it is done:

Gavin Ray
  • 595
  • 1
  • 3
  • 10
  • Oh thank you for the resources, ill look into that. 1) i was not clear on this question.. i have two products, one in category, one without.. i want to see only those in category.. then do the filtration etc.. – Ne Xen Sep 06 '22 at 18:05
  • products_products(where: { categories { category { title: { _eq: "Some Category" } } } }) – Gavin Ray Sep 06 '22 at 18:45
  • in any category modified it to _ilike: "%%" thank you ! – Ne Xen Sep 06 '22 at 19:56