How do I write a query using "_and" & "_or" at the same time

21 views Asked by At

I'm trying to write a query that takes a start date and end date to filter out a list of events to a specific date range. At the same time, I also would like to filter for fields that include whatever the user provides (in my example code I chose fields like "title" or "location"). My application is an Event Calendar and I want this query to be used with a filter pane component where each input in the filter pane can be used to dynamically get a filtered list of data.

query MyQuery {
  events(where: {
    _and: [
      {
        _or: [
          { title: {_ilike: "%test title%"} },
          { location: {_ilike: "%test location%"} }
        ]
      },
      { start_date_time_utc: {_gte: "2024-01-08T04:05:06.605+00:00"} },
      { end_date_time_utc: {_lte: "2024-02-28T21:52:09+00:00"}}
    ]
  }
    
  ) {
    id
    title
    start_date_time_utc
  }
}

My issue is the above query works fine if I only use the "_and" operator or the "_or" operator but if I try to use them together, I'm not getting anything. I've tried it a few different ways and feel like I'm missing something syntactically. I'm new to GraphQL and Hasura so it could be something simple (and I hope it is tbh), but I haven't seen any documentation on how to use them together.

0

There are 0 answers