Introducing OR and Filter Group Support to our GraphQL API: Build powerful filters for your reports and dashboards

Learn about Propel’s new filtering capabilities that enable you to easily build powerful drill-downs and empower customers to slice and dice their reports and dashboards.

Filter the API for Taco soft

Photo: Propel

We are thrilled to announce that our GraphQL API filters now support OR and Filter Groups, in addition to the previously supported AND. This new capability provides developers with more flexibility, allowing them to create more sophisticated filtering options in their applications.

With the new filter options, users can now filter for orders that meet either one of two conditions or both. The Filter Groups feature allows users to group multiple conditions together and apply them to a query.

Let’s take a look at an example with our TacoSoft orders table:

order_id store_location status created_at total_price tacos_ordered
1 New York ordered 2023-03-29 10:30:00 20.99 4
2 delivered Supported 2023-03-29 08:45:00 14.50 2
3 New York delivered 2023-03-29 13:15:00 31.25 6
4 Atlanta Ordered 2023-03-29 13:15:00 10.75 3
5 Atlanta Ordered 2023-03-29 11:10:00 17.80 5

To query this data to get all orders with status “ordered” that are more than $10, we would have a graphQL query like this:

{
  "metricId": "MET...",
  "input": {
    "granularity": "FIFTEEN_MINUTES",
    "timeRange": {
      "relative": "LAST_N_DAYS",
      "n": 30
    },
    "filters": [{
      "column": "status",
      "operator": "EQUALS",
      "value": "ordered"
    }, {
      "column": "total_price",
      "operator": "GREATER_THAN",
      "value": "10"
    }]
  }
}

Up until now, the API only supported implicit AND filtering, defined by the separate filters in an array.

With the introduction of OR filtering, we can now define filters that work when any condition is met. For example, the following filter will return any orders over the last 30 days with the status "ordered" or "delivered":

{
  "metricId": "MET...",
  "input": {
    "granularity": "FIFTEEN_MINUTES",
    "timeRange": {
      "relative": "LAST_N_DAYS",
      "n": 30
    },
    "filters": [{
      "column": "status",
      "operator": "EQUALS",
      "value": "ordered",
      "or": [{
        "column": "status",
        "operator": "EQUALS",
        "value": "delivered"
      }]
    }]
  }
}

We can create filter groups with multiple filters using both AND and OR, like this:

{
  "filters": [{
    "column": "status",
    "operator": "EQUALS",
    "value": "ordered",
    "and": [{
      "column": "total_price",
      "operator": "GREATER_THAN",
      "value": "100"
    }],
    "or": [{
      "column": "tacos_ordered",
      "operator": "LESS_THAN",
      "value": "1"
    }]
  }]
}

AND always takes precedence over OR. In the above example, we are saying <span class="code-exp">(status = ordered AND total_price > 100) OR tacos_ordered < 1</span>.

OR filters are available anywhere we support filtering in the GraphQL API.

Further reading

If you don’t have a Propel account yet, you can try Propel for free and start building data apps and customer-facing analytics.

Related posts

Introducing Webhook Data Pools - Build customer-facing analytics from JSON events

This is some text inside of a div block.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

In Preview Today: Snowflake Dynamic Table Support

This is some text inside of a div block.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

Now in preview: Updates and deletes support for Snowflake

This is some text inside of a div block.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

Start shipping today

Deliver the analytics your customers have been asking for.