How to pass graphql filter arguments dynamically?

20 Views Asked by At

I'm working on an event calendar application that uses GraphQL and Hasura to get events from the Db and renders the data on the front end using react big calendar. One of the features in the application is a Filters Pane where users can specifically input data that will re-render the calendar component to filter out any specific events that don't match the inputs that the user chose. My issue is regarding how I can set up my query so that dynamic filter values will work. For example, queries like this aren't working for me if title or dates are left out or null.

export const GET_FILTERED_EVENTS = graphql`
  query GetFilteredEvents($startDate: timestamptz!, $endDate: timestamptz!, $eventName: String) {
    Events(
      where: {
        start_date: { _gte: $startDate },
        end_date: { _lte: $endDate },
        title: { _ilike: $eventName }
      }
    ) {
      // fields
        id
        title
        location
        etc...
    }
  }
`;

Essentially, I do not know what fields a user wants to filter on. How can I set up my query to handle this case?

0

There are 0 best solutions below