How to pass boolean expression to variable parameter of QueryOptions of GraphQL package in flutter?

Viewed 28

#gql #flutter Hi everyone, I am using graphQL with flutter and would like to pass boolean expression to my graphQL query. I am using the QueryOption object type of the graphQL flutter package to pass the query to graphql and to define my query parameters. The problem I have is that I don't know how to tell flutter that I am passing a boolean expression to the variable parameter of the QueryOption object. Is there a way to do that?

Future<QueryResult> FilteredQuery(
    final GraphQLClient client,
    final FilterModel filter,
    final bool isAvailable,
 
  ) async {
    final QueryOptions options = QueryOptions(
      document: gql(queryCreationsFiltered),
      variables: <String, dynamic>{

        'condition1': isAvailable== false ? {false}:{is_available: {_eq: true}} 

      }

Usually to be able to match the right type of the query variable I pass the associated dart type in flutter! The idea behind that is to apply conditional filtering. Any help will be welcomed! Thanks :slight_smile:

1 Answers

I managed to solve my problem. The syntax to use to express the boolean expression in dart should be the following.

{"is_available": {"_eq": true}} and not {is_available: {_eq: true}}

My only remaining question is how to easily pass a boolean expression that evaluates to false {false} doesnt' work!

Related