I have a graphql service layer for my app as follows
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;
}
}
However after I leave my app idle for about an hour I notice the jwt token expired, so I am thinking to add checking to see if the error is indeed due to the expired token. But I cant seem to differentiate the cause of error since result.exception
does not give any error code whatsoever.
Any better way to go about this ?