Query filters

Learn how to narrow down your GraphQL searches using Bunny's filters.

Bunny's GraphQL API follows standard practices and allows you to use first, limit, cursors etc. But filters make it possible to get very specific in a simple way.

The admin UI's table filters give a good idea of what's possible as they are using the GraphQL filters. You can search for ranges, relative dates and much more. For example:

{
  invoices(filter: "createdAt is after 2024-07-14") {
    nodes {
      number
    }
  }
}

You can also combine conditions.

{
  accounts(filter: "createdAt is after 2024-01-14 and billingState = 'CA'") {
    nodes {
      name
    }
  }
}

The operators vary by data type.

Field type
Operators

Boolean

is, is_not

Integer

<. >, =, <=, =>, !=, in [ ], not in [ ]

String

begins_with, ends_with, contains, contains_not, equals, not_equals, !=, =, in [ ], not in [ ]

You can also test for null values using is blankand is not blank.

Dates

Dates have the most complex syntax and are best explained in the simplified grammar below.

date_condition  : field (is|is_not) specific_date
                | field (is|is not) relative date

specific_date   : yesterday | today | tomorrow
                | ((before | on | after | on or after | on or before ) date) 
                | in 
                | ago

in              : in int period

ago             : int period ago

relative_date   : which period[s]

which           : current
                | (past | next) [int] 

period          : day[s] | week[s] | month[s] | quarter[s] | year[s]

date            : “yyyy-mm-dd” | "yyyy-mm-ddThh:mm:ss"

The date syntax is very powerful and allows you to easily express relative times, such as:

  • in three weeks

  • last month

  • is current week

  • on or after '2024-10-10'

  • next quarter

Grouping

The filter syntax also allows you do group expressions using parenthesis and combine them with and and or, for example:

{
  accounts(filter: "revenue > 100 and (billing_state = 'CA' or billing_state = 'WA') {
    nodes {
      id
    }
  }
}

Last updated

Was this helpful?