-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom HttpClient for GraphQLClient #32
Comments
Well, if you specify better what is your use case i can give help. If you need to add a Header you can use something like this: var graphClient = new GraphQLClient("https://api.github.com/graphql");
graphClient.DefaultRequestHeaders.Add("Authorization", $"bearer {gitHubAccessToken}");
//var test = await graphClient.GetIntrospectionQueryAsync();
var request = new GraphQLRequest
{
Query = @"query { viewer { login } }"
};
var test = await graphClient.PostAsync(request); IDK if this solves your issue or you have a better idea of how to implement your case |
thanks that did the trick! my use case is integration testing a graphql endpoint which is started as a .net core TestServer. it was a bit tricky because it's not an endpoint which is accessible as any other real endpoint. |
I can't add DefaultRequestHeaders with IGraphQLClient, how can this be done, please? @Version of GraphQL.Client is 3.1.3 |
Try: GraphQLHttpClient client = new GraphQLHttpClient("https://example.com/graphql", new NewtonsoftJsonSerializer()); |
I had to use the HttpClient Library to get around this party issue as IGraphQLClient didn't seem to have a direct support for adding Default HTTP Headers, you can try this example on this GitHub gist : https://gist.github.com/Adebayo-Adesegun/0bc086050625a1e5f30fbba8a697ca35: You can just treat it like a normal HTTP request. The GraphQL server endpoint figures the rest out from your structure. |
It would be very helpful to supply my own instance of HttpClient to the GraphQLClient constructor. Currently it allows to supply a HttpMessageHandler. But this way I can't specify authorization tokens.
Or is there another way to acomplish this?
The text was updated successfully, but these errors were encountered: