graphql-client
graphql-client copied to clipboard
Headers into GraphQLHttpRequest
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?
Create your own custom GraphQLHttpRequest class and override ToHttpRequestMessage...
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
),