Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

graphql-flutter #11

Closed
0x6a74 opened this issue Jun 19, 2019 · 3 comments
Closed

graphql-flutter #11

0x6a74 opened this issue Jun 19, 2019 · 3 comments

Comments

@0x6a74
Copy link

0x6a74 commented Jun 19, 2019

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 implement graphql-flutter within the proposed architecture. I have a service (ApiGraphqlService) which depends on the AuthenticationService and should be consumed in e.g. PostViewModel.

I've already found a possible solution: zino-hofmann/graphql-flutter#339. But i thought it could be done a more "proper way"?

@FilledStacks
Copy link
Owner

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.

@0x6a74
Copy link
Author

0x6a74 commented Jun 19, 2019

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..
  }
}

@FilledStacks
Copy link
Owner

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants