Reference

UseStartupValidation

Package Trax.Api.GraphQL.Client.TraxNamespace Trax.Api.GraphQL.Client.TraxSource TraxBuilderExtensions.cs, StartupValidator.cs

Registers a hosted service that validates this client's request types in assemblies when the host starts. Declared on the static class TraxBuilderExtensions.

Signature

public static TraxGraphQLClientBuilder UseStartupValidation(
    this TraxGraphQLClientBuilder builder,
    params Assembly[] assemblies)

Parameters

ParameterTypeRequiredDescription
builderTraxGraphQLClientBuilderYesThe client's builder
assembliesAssembly[]YesThe assemblies whose request types are validated. At least one

Returns

The same TraxGraphQLClientBuilder.

Behavior

  • Throws ArgumentNullException when builder or assemblies is null, and ArgumentException when assemblies is empty.
  • The hosted service runs once, in StartAsync, and performs the same check as ValidateGraphQLClientAssembliesAsync for this builder's client: an unkeyed client validates the request types with no [GraphQLClient] mark, a keyed client those marked with its key.
  • Any failure propagates out of StartAsync, so the host does not start: a query the schema rejects (GraphQLValidationException, logged at Error with the query), a schema that cannot be loaded (GraphQLSchemaIntrospectionException), no request type for this client in assemblies, or a request marked with a key no client is registered under (InvalidOperationException).
  • Progress is logged at Information under ILogger<GraphQLClientStartupValidator>.
  • Every validated query is cached by the client's validator, so the first Run of each request does not validate again.

Example

services
    .AddTraxGraphQLClient(new Uri("https://api.example.com/graphql"))
    .UseFileSchema("schema.graphql")
    .UseStartupValidation(typeof(Program).Assembly);

See also