IGraphQLClientExecutor
Package Trax.Api.GraphQL.ClientNamespace Trax.Api.GraphQL.ClientSource IGraphQLClientExecutor.cs, GraphQLClientExecutor.cs
Runs an IGraphQLClientRequest:
validates its query, sends it and reads the result. GraphQLClientExecutor is the implementation
AddTraxGraphQLClient registers as a
singleton (keyed, for AddKeyedTraxGraphQLClient).
Signature
public interface IGraphQLClientExecutor
{
Task<TReturn> Run<TReturn>(
IGraphQLClientRequest<TReturn> request,
CancellationToken cancellationToken = default);
}
public class GraphQLClientExecutor : IGraphQLClientExecutor
{
public GraphQLClientExecutor(
IGraphQLClientValidator validator,
IGraphQLClientConfiguration configuration,
ILogger<GraphQLClientExecutor>? logger = null);
}Returns
The result of the request's Extract.
Behavior
Run:
- Throws
ArgumentNullExceptionfor anullrequest, andOperationCanceledExceptionwhen the token is already cancelled. - Validates
Querywith the client's validator. The first validation of a query text loads the schema when needed; later ones hit the cache. - Sends the request as a query or a mutation, according to the operation, through the
configuration's
GraphQLHttpClient. - Throws when the server returned errors or no data.
- Checks the response shape when the client's strictness is not
Lenientand the request'sUsesDefaultExtractoristrue. Drift is logged at Warning underILogger<GraphQLClientExecutor>forWarnOnDrift. - Returns
request.Extract(data, options).
| Exception | When |
|---|---|
GraphQLValidationException | The query does not validate, has no operation or more than one, or is a subscription against a schema without a subscription type (the default). Nothing is sent |
GraphQLSchemaIntrospectionException | The schema could not be loaded |
GraphQLExecutionException | The server returned GraphQL errors (Errors), the response had no data, or Extract produced null (Errors is empty) |
JsonException | The default extractor could not read the data as TReturn. Not wrapped |
GraphQLResponseShapeException | The response shape differs from TReturn under ThrowOnDrift |
NotSupportedException | The operation is a subscription and the schema kept its subscription type (RemoveSubscriptionsFromSchema = false) |
Transport failures surface as the exceptions GraphQL.Client and HttpClient throw.
Example
public class PlayerLookup(IGraphQLClientExecutor graphql)
{
public async Task<PlayerProfile?> Find(string id, CancellationToken ct)
{
try
{
return await graphql.Run(new GetPlayerRequest { Id = id }, ct);
}
catch (GraphQLExecutionException)
{
return null;
}
}
}