graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Headers into GraphQLHttpRequest

Open manishpatel42 opened this issue 2 years ago • 2 comments
trafficstars

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 avatar Jun 07 '23 18:06 manishpatel42

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

rose-a avatar Jun 11 '23 18:06 rose-a

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
            ),

Theauxm avatar Jun 11 '24 20:06 Theauxm