FgForrest / evitaDB

evitaDB is a specialized database with an easy-to-use API for e-commerce systems. It is a low-latency NoSQL in-memory engine that handles all the complex tasks that e-commerce systems have to deal with on a daily basis. evitaDB is expected to act as a fast secondary lookup/search index used by front stores.
https://evitadb.io
Other
61 stars 7 forks source link

Support `filterBy` in hierarchy extra results #656

Open novoj opened 1 month ago

novoj commented 1 month ago

When developers create menus, they often want to exclude some categories from listed hierarchy. Inuitive approach would be:

query megamenu(
  $locale: CatalogLocale
  $currency: CatalogCurrency
  $priceType: QueryPriceMode = WITH_TAX
  $priceInPriceLists: [String!] = []
  $stocks: [String!] = []
  $productType: [String!] = ["BASIC", "SET", "MASTER"]
  $distance: Int = 3
) {
  queryProduct(
    filterBy: {
      entityLocaleEquals: $locale
      priceInCurrency: $currency
      priceInPriceLists: $priceInPriceLists
      priceValidInNow: true
      attributeStatusEquals: "ACTIVE"
      attributeProductTypeInSet: $productType
      referenceStockVisibilitiesHaving: {
        entityHaving: { attributeCodeInSet: $stocks }
      }
    }
    require: { priceType: $priceType }
  ) {
    extraResults {
      hierarchy {
        categories(
          emptyHierarchicalEntityBehaviour: REMOVE_EMPTY        
          # this could have filtering constraint
          filterBy: { attributeVisibilityEquals: "VISIBLE" }
          orderBy: { attributeOrderNatural: ASC }
        ) {
          fromRoot(stopAt: { distance: $distance }) {
            level
            entity {
              primaryKey
              parentPrimaryKey
              attributes {
                name
                url
              }
              representedCategory {
                referencedEntity {
                  attributes {
                    url
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

But actually they need to do this query which is not so intuitive to the developers.

When both these filters are defined, they needs to be combined using AND relation.