简体   繁体   English

如何在 graphql_flutter 中重试对 GraphQLError 的请求

[英]How to retry a request on GraphQLError in graphql_flutter

I want to retry a graphql request when the graphql response has some particular errors.当 graphql 响应有一些特定错误时,我想重试 graphql 请求。 My current code:我当前的代码:

QueryResult result = await client.query(
              QueryOptions(
                documentNode: gql(queries.getNextEpisode),
                variables: <String, dynamic>{
                  'id': id,
                  'keyType': 'POSTER',
                },
              ),
            );
if (result.hasException && 
    result.exception.graphqlErrors
      .any((element) => element.message.contains("401"))) {
// retry the request 
}

I tried the retry package but I think it only works if there is an exception thrown, which I don't think is the case here.我尝试了重试 package 但我认为它只有在抛出异常时才有效,我认为这里不是这种情况。

I'm using graphql_flutter: ^3.0.0 .我正在使用graphql_flutter: ^3.0.0

For this you have to use fresh_graphql/fresh_graphql.dart package.为此,您必须使用fresh_graphql/fresh_graphql.dart package。

_initFreshLink() {
_freshLink = FreshLink<OAuth2Token>(
  tokenStorage: _easyInMemoryTokenStorage,
  refreshToken: _refreshToken,
  shouldRefresh: (FetchResult result) {
    var hasAuthError = result.errors != null &&
        result.errors
                .where((e) =>
                    e['extensions'] != null &&
                    e['extensions']['code'] != null &&
                    e['extensions']['code'] == 'UNAUTHENTICATED')
                .toList()
                .length !=
            0;
    return hasAuthError;
  },
)..authenticationStatus.listen(print);
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter with Firebase JWT 将 GraphQL (graphql_flutter) 请求发送到具有“格式错误的授权标头”的 Heroku Hasura - Flutter with Firebase JWT sends GraphQL (graphql_flutter) request to Heroku Hasura that has a “Malformed Authorization header” Websocket 重连循环,graphql_flutter - Websocket reconnection loop, graphql_flutter graphql_flutter 返回 LazyCacheMap,built_value deserializeWith JSON String,如何让它们协同工作 - graphql_flutter return LazyCacheMap, built_value deserializeWith JSON String, how to make them work together 使用 graphql_flutter 连接到 Graphql API 时出错 - Error when connecting to Graphql API using graphql_flutter 如何在每次构建Query()时禁用graphql_flutter查询后端 - How to disable graphql_flutter query backend every time build Query() graphql_flutter 突变查询需要返回语句 - 不确定如何添加它 - graphql_flutter mutation query expects return statement - not sure how to add it Flutter (graphql_flutter + gql):找到这个候选,但参数不匹配 - Flutter (graphql_flutter + gql): Found this candidate, but the arguments don't match 在操场上运行的 Graphql_flutter 突变在运行设备/模拟器上不起作用 - Graphql_flutter mutation running on playground doesn't work on running device/emulator graphql_flutter - 从 pub.dev 页面复制代码 - 仍然出错 - graphql_flutter - copied code from the pub.dev page - still getting error 如何在flutter中向graphql API发送post请求 - How to send post request to graphql API in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM