How can I add a condition in GraphQL NOT to search for a null string in Hygraph?

28 views Asked by At

I have a mobile application which searches a barcode database in Hygraph Headless CMS.

If the barcode is not found then the database will search for a name that is part of the string and also try to search the brand keyword too - but I only want it to check for brand if the value is not empty.

Example:

{"name":"AJMAL Body Powder 100 Gm Rain Drops","barcode":[6293708009176],"brand":""}

It should not do anything with "brand":"" as it is empty. But for this query value:

{"name":"AJMAL Body Powder 100 Gm Rain Drops","barcode":[6293708009176],"brand":"Ajmal"}

It will for search for the barcode, then the name and the brand. My code:

query getScannedBrands($barcode: [Float!], $brand: String, $name: String) {
  brands(
    # orderBy: 
    first: 1
    where: {
      OR: [
        { barcodes: $barcode }
        { OR: [
            { name_contains: $name },
            {name_not: [{_empty: $brand}]}
          ]
        }
      ]
    }
  ) {
    id
    barcodes
    description
    name
    icon {
      url
    }
    path
  }
}
0

There are 0 answers