Closed Refaat2020 closed 2 years ago
I would expect upgrading two major versions may break your app. It looks like the error is pretty obvious from your error message, try and have a look at how your links are set up and if the authorisation tokens are properly passed.
Please I couldn't find the error so please have a look at my code and tell me where the error could be found https://i.ibb.co/mcvVMPc/screen-1.png
@budde377 class GraphQLService { late GraphQLClient _client; GraphQLService() { initClient(); } // Setup the apollo client on initialize initClient() { try {
String serverUrl = AppUrls.getServerUrl(appFlavor);
Logger().i("Server Url: $serverUrl");
final HttpLink _httpLink = HttpLink("$serverUrl/graphql");
final token = Preference.getString(PrefKeys.accessToken) ?? "";
Logger().i("graph token: $token");
//
final AuthLink _authLink =
AuthLink(getToken: () async => Preference.getString(PrefKeys.accessToken));
Link _link = _authLink.concat(_httpLink);
final GraphQLClient client = GraphQLClient(cache: GraphQLCache(store: InMemoryStore()), link: _link,);
// readRepositories(client);
return this._client = client;
} catch (e) {
print(e);
print('error initializing graphql');
}
}
/// Use this for cached queries
Future
final QueryResult result = await _client.query(options);
return result.handleResponse();
}
/// Use this for mutations
Future
return result.handleResponse();
}
}
I don't know what kind of token your API requires. Maybe you'll need to prefix your token with Bearer
?
I.e.,
AuthLink(getToken: () async => "Bearer ${Preference.getString(PrefKeys.accessToken)}");
Please I couldn't find the error so please have a look at my code and tell me where the error could be found
@Refaat2020 You are 2 years late, that with software is history! What we suggest is try to follow https://github.com/zino-hofmann/graphql-flutter/blob/main/changelog-v3-v4.md that is easily found in the repository.
If the error persists, take an empty project and start a graph_flutter project from scratch. debugging your code with difference between the new and old version is an easy job more than you are asking to us
Have you found a solution?
my previous version 3.10 was working fine but when updated to the current version it returns an error
OperationException(linkException: ServerException(originalException: null, parsedResponse: Response(data: null, errors: null, context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}), response {error: Unauthorized, message: Access token invalid})), graphqlErrors: [])