Closed 0x6a74 closed 5 years ago
Hi there, thanks for the kind words.
I don't see where your confusion is so maybe I'm missing something. You are right that it can be done in a more "service-wrapped" way. Services just wrap functionality so to keep your code less dependent on a third party library you can create your GraphQLService
and wrap the client functionality you need. Something like this:
class GraphQLService {
GraphQLClient _client;
Future<Posts> getPosts() {
var result = _client.query(...);
return Post.fromResult(results);
}
}
And then you inject your Service as a normal independent provider
Provider.value(value: GraphQLService());
Then you just inject that into the model as we do with all the other services. Does that answer your question. If it doesn't please be a bit more specific on what you're doing, what's happening and what you're expecting in terms of your architecture then I'll see if I can come up with a better solution.
Thanks for the quick response. My major issue was to get the token (created/saved by the AuthService) into the GraphQLService
. I'll now something like this:
class GraphQLService {
GraphQLClient _client;
GraphQLService({storageService...})
Future _createClient(...) {}
Future<Posts> getPosts() {
_client = _createClient..
}
}
Yes that should definitely work. Goodluck, I'm happy to see the architecture being used. If you run into any kind of architectural limitations please let me know so that I can see what the best way would be to handle that situation.
hey there. first of all, thank you so much for you effort on bringing flutter architecture to the next level.
I've just followed your tutorial
#14
and i am trying to implementgraphql-flutter
within the proposed architecture. I have a service (ApiGraphqlService
) which depends on theAuthenticationService
and should be consumed in e.g.PostViewModel
.I've already found a possible solution: https://github.com/zino-app/graphql-flutter/issues/339. But i thought it could be done a more "proper way"?