Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Question on implementation practice in a more realistic environment perhaps... #86

Closed
sjmcdowall opened this issue Sep 4, 2018 · 4 comments
Labels
next Feature or report is related to next question Further information is requested

Comments

@sjmcdowall
Copy link

sjmcdowall commented Sep 4, 2018

Is your feature request related to a problem? Please describe.
Reading your documentation -- I am not certain how to implement this is my Flutter App. Specifically, our App has quite a long and lengthy signup/login process before we can get the JWT for the Auth token that is needed to access the GraphQL server.

In fact, it's not for a little while before we even know where the GraphQL server side is located...

So it's not feasible to put all that startup logic, etc. in the Main App ...

Also -- our JWTs expire after N minutes and get renewed -- so we need to modify the HttpLink when that happens and have no idea how to do so...

Also -- we currently have quite a bit of code in our scoped-model logic -- and there are places for sure where I'd like to execute some GraphQL queries .. but .. that code really is independent of any Widget per se .. so not sure how to use the GraphQL / client in that context either ...

Describe the solution you'd like

More examples or more documentation on OTHER implementation that don't depend on it happening right at the start -- with variable plugins that can change over time in the same app..

There is probably a way to -- once ready -- do the "init" and grab and save the client to some static class area that can be retrieved later .. and then .. hmm.. use GraphQLClient all over the place (or at least at the highest level Routes?) .. Can it be used within the routing mechanism somehow?

Anyway -- now you can see why I have so many questions on how to actually use this.. ! LOL

Cheers and nice work on this BTW -- We are using ApolloClient in our Vue web app and love it there.. and obviously this looks very promising too !

@HofmannZ HofmannZ added question Further information is requested next Feature or report is related to next labels Sep 5, 2018
@HofmannZ
Copy link
Member

HofmannZ commented Sep 5, 2018

Hi @sjmcdowall,

We are aware there is still a lack of documentation for this project. We're planning on creating some static docs.

Until then here are some pointers:

Updating http options though the context

You can update the http options (like headers) by passing them to context in the query. That would look something like this:

Query(
  options: QueryOptions(
    document: queries.readRepositories,
    pollInterval: 4,
    context: <String, dynamic>{
      'headers': <String, String>{
        'Authorization': 'Bearer <YOUR_PERSONAL_ACCESS_TOKEN>',
      },
    },
  ),
  builder: (QueryResult result) {
    ...
  },
);

Calling the client from outside a Flutter context

Although not (yet) documented, you can call the the client directly. The client exposes two methods: GraphQLClient.query and GraphQLClient.mutate. They both resolve a single query according to the options specified and return a Future which resolves with the resulting data or throws an error.

HttpLink link = HttpLink(
  uri: 'https://api.github.com/graphql',
  headers: <String, String>{
    'Authorization': 'Bearer <YOUR_PERSONAL_ACCESS_TOKEN>',
  },
);

GraphQLClient client = GraphQLClient(
  cache: InMemoryCache(),
  link: link,
);

Future<QueryResult> queryResult = client.query(
  QueryOptions(
    document: queries.readRepositories,
  ),
);

Hope that helps! ✌🏻

@sjmcdowall
Copy link
Author

That is perfect and awesome doc! Can't wait to give it a whirl later today!!

@sjmcdowall
Copy link
Author

sjmcdowall commented Sep 20, 2018 via email

@Moanrisy
Copy link

why this is not on documented yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next Feature or report is related to next question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants