Comments (5)
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.
from graphql-request.
Hi @TinkGu. Thanks a lot for bringing this up. We'll consider this use case for the next version of graphql-request
.
For now, a workaround is to re-instantiate a new GraphQLClient
whenever you need to change your headers.
from graphql-request.
This has been properly done using the new apollo-boost package. See the request
option in the configuration section.
from graphql-request.
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:
const client = new GraphQLClient(endPoint, { headers: { Authorization: INITIAL_TOKEN } })
const runQuery = async (query, variables) => {
client.options.headers = {
Authorization: NEW_TOKEN,
}
try {
return await client.request(query, variables)
} catch (error) {
...
}
}
export default runQuery
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.
from graphql-request.
@christopher-caldwell be careful with what you are doing.
If you are sharing the client, then you might end up in an unwanted state.
from graphql-request.
Related Issues (20)
- [5.2.0] broke the typings of graphql-codegen generation HOT 10
- Can't build project on React Native + Metro HOT 2
- Changes to `Variables` introduces type unsafety/churn HOT 2
- Typescript 5.0.2 complains about `AbortSignal` structure (works fine with TS 4.9.5) HOT 4
- Running multiple instances in the same machine leads to strange behaviours
- Serverless function crashing on express app hosted on Vercel. HOT 1
- Custom Fetch w/ Custom Options? HOT 1
- Error thrown when graphql-request 5.2.0 used with Nuxt 3 HOT 11
- Is "custom fetch" still possible? HOT 2
- ReactNative/Expo - file upload does not work HOT 1
- Missing "Main" in package.json HOT 1
- Remove file handling HOT 3
- Support for Next.js 13 App Directory HOT 16
- Better error handling HOT 10
- [6.0.0] version no longer has "types.dom" for graphql-codegen generation HOT 3
- 500 Internal server error when importing to Deno
- When returning error, you should also return for which query or mutation this error occured
- Add Support for Batching Mutations HOT 3
- Cannot read properties of undefined (reading 'filter') HOT 3
- MockedProvider for Testing? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-request.