Per-request headers
See original GitHub issueIt is possible to setup headers at construction time, but not possible to set headers for a particular request.
It is possible to work around this by wrapping Genql with a function that creates an instance anew for each request, but obviously not ideal.
type EnhancedGenqlClient = {
mutation<R extends Genql.MutationRequest>(
request: R & { __name?: string },
config?: { headers?: Record<string, string> }
): Promise<GenqlRuntime.FieldsSelection<Genql.Mutation, R>>
query<R extends Genql.QueryRequest>(
request: R & { __name?: string },
config?: { headers?: Record<string, string> }
): Promise<GenqlRuntime.FieldsSelection<Genql.Query, R>>
}
const enhancedGenql: EnhancedGenqlClient = {
mutation(selectionSet, config) {
const genql = Genql.createClient({
url: `http://localhost:${serverPort}/api/graphql`,
headers: {
Authorization: `Bearer ${token}`,
...config?.headers,
},
})
return genql.mutation(selectionSet)
},
query(selectionSet, config) {
const genql = Genql.createClient({
url: `http://localhost:${serverPort}/api/graphql`,
headers: {
Authorization: `Bearer ${token}`,
...config?.headers,
},
})
return genql.query(selectionSet)
},
}
Open to a pull-request for this?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Modify request headers per request C# HttpClient PCL
It seems that I can only manipulate the "DefaultRequestHeaders" which will be send with each request. Is there an option when actually making ......
Read more >HTTP headers - MDN Web Docs - Mozilla
Request headers contain more information about the resource to be fetched, or about the client requesting the resource. Response headers hold ...
Read more >C# HttpClient - How to add request headers per request
This post describes how you can set headers on a HTTP request instead of setting it on the HttpClient and for all requests...
Read more >[API] Add per request headers override to HttpClient ... - GitHub
The way to send custom per request headers with HttpClient is via SendAsync and adding them to the HttpRequestMessage . However that isn't...
Read more >Too Many Headers per Request | Imperva
Each HTTP request may contain various headers. These headers contain additional attributes of the request, such as the destination host, the encoding language ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @GavinRay97, you must think about Hasura’s use case? We’re in the same boat, we need to send a
x-hasura-role
per request. We use the createClient() trick currently but it’s not that convenient.This feature is currently not possible because the batching library i am using does not let me pass headers per request