'Postgraphil Graphql - how to filter query only if the input is not null and not empty

Im using postgraphile and i have this query:

query Products($categories: [String]){
  products(
    filter: {
       category: { in: $categories } 
    }) {
    id
    name
    category
  }
}

is there a way to not use the filter if the $categories array is empty ?

In case the array is not set or it's empty, i want to get all the results.

i saw there is an option to pass filter as an argument, but I wonder if there is another support.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source