IGraphQLClientRequest
Package Trax.Api.GraphQL.ClientNamespace Trax.Api.GraphQL.ClientSource IGraphQLClientRequest.cs, IGenericGraphQLClientRequest.cs
An outbound GraphQL request whose result is read as TResponse, run with
IGraphQLClientExecutor.Run. Three
implementations exist: implement the interface with a literal query, derive from
GraphQLResourceRequest to load the
query from an embedded .graphql file, or derive from
TypedRequest to generate it from the response
type.
Signature
public interface IGenericGraphQLClientRequest
{
string Query { get; }
object? Variables => null;
}
public interface IGraphQLClientRequest<out TResponse> : IGenericGraphQLClientRequest
{
JsonElement UnwrapDataElement(JsonElement data); // default implementation
TResponse Extract(JsonElement data, JsonSerializerOptions options); // default implementation
bool UsesDefaultExtractor => true;
}Members
| Member | Default | Description |
|---|---|---|
Query | (required) | The GraphQL document. It holds exactly one operation, before or after any fragments: requests are sent without an operation name, so a second operation is refused at validation. Validation is cached per query text |
Variables | null | The operation's variables, serialized as the variables object. An anonymous object or a dictionary |
UnwrapDataElement(data) | When data is an object with exactly one property, returns that property's value; otherwise returns data | Navigates from the data envelope to the element that is deserialized |
Extract(data, options) | Calls UnwrapDataElement; returns default for a JSON null; otherwise deserializes with options, throwing GraphQLExecutionException when that yields null | Produces the result |
UsesDefaultExtractor | true | Whether Extract is the default. Response-shape checking (ResponseStrictness) runs only when it is true |
IGenericGraphQLClientRequest is the non-generic view the validator scans; a request implements
IGraphQLClientRequest<TResponse>.
Example
public sealed class GetPlayerRequest : IGraphQLClientRequest<PlayerProfile>
{
public required string Id { get; init; }
public string Query => """
query GetPlayer($id: String!) {
player(id: $id) { id name level }
}
""";
public object? Variables => new { id = Id };
}
public sealed record PlayerProfile(string Id, string Name, int Level);The response { "data": { "player": { ... } } } has one top-level field, so the default
UnwrapDataElement returns player and Extract deserializes it as PlayerProfile.