-
Notifications
You must be signed in to change notification settings - Fork 313
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
how to set header every request? #33
Comments
Hi @TinkGu. Thanks a lot for bringing this up. We'll consider this use case for the next version of For now, a workaround is to re-instantiate a new |
How's the progress on this? I have a GraphQL endpoint that requires client authentication with every call. We use JSON Web Tokens with a limited life span for authentication so we can't just reuse the same one. Creating a new client for every single request seems rather wasteful, in my opinion. |
This has been properly done using the new apollo-boost package. See the |
Is there any way to do this now? I don't want to use Apollo. Is the only way to re-instantiate a client on each request? Edit: Immediately after posting this I tried:
In my case, I'm referencing a Vuex store, so the property is reactive. You could easily pass, or get the token within this function though. |
@christopher-caldwell be careful with what you are doing. |
closes #33 There is a new third parameter on the `request` an `rawRequest` methods for passing headers particular to that request. For example: ```js import { GraphQLClient } from 'graphql-request' const client = new GraphQLClient(endpoint) const query = gql` query getMovie($title: String!) { Movie(title: $title) { releaseDate actors { name } } } ` const variables = { title: 'Inception', } const requestHeaders = { authorization: 'Bearer MY_TOKEN' } // Overrides the clients headers with the passed values const data = await client.request(query, variables, requestHeaders) ```
In apolloclient, I can do it like this:
How can I do it in gql-request?
Thanks.
The text was updated successfully, but these errors were encountered: