byme8 / ZeroQL

C# GraphQL client with Linq-like syntax
MIT License
278 stars 13 forks source link

CancellationToken support on Query and Mutation operations #23

Closed be1223 closed 1 year ago

be1223 commented 1 year ago

Currently there is no way to way to provide a CancellationToken instance to the async operation of invoking a query/mutation operation.

Since the generated client is backed by a regular .Net HttpClient then an optional CancellationToken should be accepted and forwarded to the request issued by the underlying client.

The general pattern is to declare a cancellationToken parameter on the method and set it to default so invoking a query could look something like this:

var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://localhost:10000/graphql");

var client = new TestServerGraphQLClient(httpClient);

using CancellationTokenSource cts = new(); 

var response = await client.Query(static o => o.Me(o => new { o.Id, o.FirstName, o.LastName }), cts.Token);
byme8 commented 1 year ago

Version v3.2.0 has support for the cancelation tokens.