graphql-dotnet / graphql-dotnet/graphql-client
Cannot access disposed object.
- Dominant language
- C#
- Stars
- 648
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
Code -
```csharp
// startup/registration DI code -
services.AddHttpClient("GraphQLClient")
.ConfigureHttpClient(client =>
{
client.BaseAddress = new Uri("https://api.example.com/graphql");
});
services.AddScoped(sp =>
{
var httpClientFactory = sp.GetRequiredService();
var httpClient = httpClientFactory.CreateClient("GraphQLClient");
return new GraphQLHttpClient(
new GraphQLHttpClientOptions { EndPoint = new Uri("https://api.example.com/graphql") },
new SystemTextJsonSerializer(),
httpClient
);
});
public class Client
{
private readonly GraphQLHttpClient _graphqlClient;
public Client(GraphQLHttpClient graphqlClient)
{
this._graphqlClient = graphqlClient;
}
public async Task SomeMethod()
{
var request1 = new GraphQLRequest
{
Query = "{ students { id name } }"
};
var request2 = new GraphQLRequest
{
Query = "{ courses { id title } }"
};
var t = CallApi(request1);
var m = CallApi(request2); // This throws Cannot access a disposed object Object name: System.Net.Http.StringContent exception
await Task.WhenAll(t, m);
}
private async Task CallApi(GraphQLRequest request)
{
var response = await _graphqlClient.SendQueryAsync(request); // exception thrown here
Console.WriteLine(response.Data);
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.