Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在颤振中使用GraphQLClient区分错误_Flutter - Fatal编程技术网

Flutter 如何在颤振中使用GraphQLClient区分错误

Flutter 如何在颤振中使用GraphQLClient区分错误,flutter,Flutter,我的应用程序有一个graphql服务层,如下所示 class GraphQLService { GraphQLClient client; GraphQLService({String jwt}) { createClient(jwt); } Future<QueryResult> performQuery(String query, {Map<String, dynamic> variables}) async { Que

我的应用程序有一个graphql服务层,如下所示

class GraphQLService {
  GraphQLClient client;

  GraphQLService({String jwt}) {
    createClient(jwt);
  }

  Future<QueryResult> performQuery(String query,
      {Map<String, dynamic> variables}) async {
    QueryOptions options = QueryOptions(
        documentNode: gql(query),
        variables: variables,
        errorPolicy: ErrorPolicy.all);
    QueryResult result = await client.query(options);
    if (result.exception != null){

    }
    return result;
  }

  Future<QueryResult> performMutation(String query,
      {Map<String, dynamic> variables}) async {
    MutationOptions options = MutationOptions(
        documentNode: gql(query),
        variables: variables,
        update: (Cache cache, QueryResult result) {
          if (result.hasException) {
            print(['optimistic', result.exception.toString()]);
          }
        });
    QueryResult result = await client.mutate(options);
    if (result.exception != null){
      // refresh token here... what if no internet connection ?
    }
    return result;
  }
}
GraphQLService类{
graphql客户端;
GraphQLService({String jwt}){
createClient(jwt);
}
未来性能查询(字符串查询,
{Map variables})异步{
QueryOptions选项=QueryOptions(
documentNode:gql(查询),
变量:变量,
errorPolicy:errorPolicy.all);
QueryResult result=wait client.query(选项);
if(result.exception!=null){
}
返回结果;
}
未来性能置换(字符串查询,
{Map variables})异步{
MutationOptions选项=MutationOptions(
documentNode:gql(查询),
变量:变量,
更新:(缓存,查询结果){
if(result.hasException){
打印(['optimistic',result.exception.toString()]);
}
});
QueryResult结果=等待客户机.mutate(选项);
if(result.exception!=null){
//在此刷新令牌…如果没有internet连接怎么办?
}
返回结果;
}
}
然而,当我让我的应用程序闲置大约一个小时后,我注意到jwt令牌过期了,所以我想添加检查,看看错误是否确实是由过期的令牌引起的。但是我似乎无法区分错误的原因,因为
结果。异常
不会给出任何错误代码

还有更好的办法吗