Skip to content
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

Headers into GraphQLHttpRequest #575

Open
manishpatel42 opened this issue Jun 7, 2023 · 2 comments
Open

Headers into GraphQLHttpRequest #575

manishpatel42 opened this issue Jun 7, 2023 · 2 comments

Comments

@manishpatel42
Copy link

GraphQLHttpRequest.ToHttpRequestMessage method creates new HttpRequestMessage but there is no way to pass custom header to this new HttpRequestMessage. For our unit tests, we need to pass auth header into HttpRequestMessage. Is this something possible to get fixed in future releases?

@manishpatel42 manishpatel42 changed the title Headers into GraphQLRequest Headers into GraphQLHttpRequest Jun 7, 2023
@rose-a
Copy link
Collaborator

rose-a commented Jun 11, 2023

Create your own custom GraphQLHttpRequest class and override ToHttpRequestMessage...

@Theauxm
Copy link

Theauxm commented Jun 11, 2024

I solved this issue by adding my Request Headers to the HttpClient when the GraphQLClient was made. This will now add the x-api-key as a header to every GraphQL request.

var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", ...);

...

var graphQLHttpClient = new GraphQLHttpClient(
                ...
                httpClient: client
            ),

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants