question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Per-request headers

See original GitHub issue

It 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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jgouxcommented, May 5, 2021

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.

0reactions
remorsescommented, Mar 24, 2021

This feature is currently not possible because the batching library i am using does not let me pass headers per request

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found