[英]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.