Reference

IGraphQLClientConfiguration

Package Trax.Api.GraphQL.ClientNamespace Trax.Api.GraphQL.ClientSource IGraphQLClientConfiguration.cs, GraphQLClientConfigurationBuilder.cs

The settings one GraphQL client runs with: the endpoint, the HTTP and JSON plumbing, and how strictly responses are checked. Built once from a GraphQLClientConfigurationBuilder the first time it is resolved, and registered as a singleton (keyed, for a keyed client).

Signature

public interface IGraphQLClientConfiguration
{
    Uri BaseAddress { get; }
    HttpClient HttpClient { get; }
    GraphQLHttpClient GraphQLHttpClient { get; }
    IGraphQLWebsocketJsonSerializer WebsocketJsonSerializer { get; }
    JsonSerializerOptions JsonSerializerOptions { get; }
    GraphQLHttpClientOptions GraphQLClientOptions { get; }
    bool DisposeHttpClient { get; }
    bool RemoveSubscriptionsFromSchema { get; }
    ResponseStrictness ResponseStrictness { get; }
}
 
public class GraphQLClientConfigurationBuilder
{
    public GraphQLClientConfigurationBuilder(Uri baseAddress);
    public IGraphQLWebsocketJsonSerializer WebsocketJsonSerializer { get; set; }
    public JsonSerializerOptions JsonSerializerOptions { get; set; }
    public GraphQLHttpClientOptions GraphQLClientOptions { get; set; }
    public HttpClient? HttpClient { get; set; }
    public bool DisposeHttpClient { get; set; }
    public bool RemoveSubscriptionsFromSchema { get; set; }
    public ResponseStrictness ResponseStrictness { get; set; }
    public IGraphQLClientConfiguration Build();
}

Properties

PropertyDescription
BaseAddressThe GraphQL endpoint every request is sent to
HttpClientThe HTTP client requests go through: the IHttpClientFactory client named for this GraphQL client, or the one supplied. Its BaseAddress is not used or changed
GraphQLHttpClientThe GraphQL.Client HTTP client built over HttpClient, used for requests and introspection
WebsocketJsonSerializerThe serializer the GraphQL.Client transport uses for request and response envelopes
JsonSerializerOptionsThe options responses are deserialized with, which response-shape checks also use to name properties
GraphQLClientOptionsThe GraphQL.Client options the HTTP client was built with. Their EndPoint is set to BaseAddress
DisposeHttpClientWhether disposing the configuration also disposes HttpClient
RemoveSubscriptionsFromSchemaWhether every schema provider drops the subscription type before queries are validated
ResponseStrictnessHow strictly responses are checked against the request's response type

GraphQLClientConfigurationBuilder

The mutable options AddTraxGraphQLClient creates and TraxGraphQLClientBuilder sets. TraxGraphQLClientBuilder.Configure hands it out for options without a method of their own.

PropertyDefaultSet by
WebsocketJsonSerializerGraphQL.Client's SystemTextJsonSerializerConfigure
JsonSerializerOptionsPropertyNameCaseInsensitive = true, a JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseUpper) (so GOLD_TIER reads into GoldTier) and a DateOnly converterConfigureJson
GraphQLClientOptionsnew GraphQLHttpClientOptions()Configure
HttpClientnull: the client IHttpClientFactory creates under the client's nameConfigureHttpClient
DisposeHttpClientfalseDisposeHttpClient()
RemoveSubscriptionsFromSchematrueConfigure
ResponseStrictnessLenientWithStrictness

Behavior

  • The constructor throws ArgumentNullException for a null address.
  • Build() creates a configuration from the current options. With no HttpClient set it creates a long-lived one of its own, whose pooled connections are replaced every two minutes, and disposes it with the configuration. A client registered with AddTraxGraphQLClient gets its HttpClient from IHttpClientFactory instead.
  • Build() throws InvalidOperationException when GraphQLClientOptions.EndPoint is set to an address other than the client's. Leave it unset.
  • The registered configuration is built when first resolved; changes to the builder after that are not seen. Disposing it disposes the GraphQLHttpClient, and HttpClient too when DisposeHttpClient is set.

Example

services
    .AddTraxGraphQLClient(new Uri("https://api.example.com/graphql"))
    .Configure(o =>
    {
        o.RemoveSubscriptionsFromSchema = false;
        o.ResponseStrictness = ResponseStrictness.WarnOnDrift;
    });

See also