[英]How to pass boolean expression to variable parameter of QueryOptions of GraphQL package in flutter?
#gql #flutter Hi everyone, I am using graphQL with flutter and would like to pass boolean expression to my graphQL query. #gql #flutter 大家好,我正在使用 graphQL 和 flutter 并想将 boolean 表达式传递给我的 Z5B5CA01421A81DC435EC16636 查询。 I am using the QueryOption object type of the graphQL flutter package to pass the query to graphql and to define my query parameters. 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.我遇到的问题是我不知道如何告诉 flutter 我正在将 boolean 表达式传递给 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.通常为了能够匹配查询变量的正确类型,我在 flutter 中传递关联的 dart 类型。 The idea behind that is to apply conditional filtering: Any help will be welcomed: Thanks :slight_smile:其背后的想法是应用条件过滤:欢迎任何帮助:谢谢:slight_smile:
I managed to solve my problem.我设法解决了我的问题。 The syntax to use to express the boolean expression in dart should be the following. dart 中用于表达 boolean 表达式的语法应如下所示。
{"is_available": {"_eq": true}}
and not {is_available: {_eq: true}}
{"is_available": {"_eq": true}}
而不是{is_available: {_eq: true}}
My only remaining question is how to easily pass a boolean expression that evaluates to false {false}
doesnt' work!我剩下的唯一问题是如何轻松传递一个 boolean 表达式,该表达式的计算结果为 false {false}
不起作用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.