Reference

ValidateGraphQLClientAssembliesAsync

Package Trax.Api.GraphQL.ClientNamespace Trax.Api.GraphQL.ClientSource ServiceExtensions.cs, GraphQLClientValidatorExtensions.cs

Validates every request type a client owns in a set of assemblies against that client's schema. Called on the built container. Declared on the static class ServiceExtensions.

Signatures

public static Task ValidateGraphQLClientAssembliesAsync(
    this IServiceProvider services,
    params Assembly[] assemblies)
 
public static Task ValidateGraphQLClientAssembliesAsync(
    this IServiceProvider services,
    object serviceKey,
    params Assembly[] assemblies)

Parameters

ParameterTypeRequiredDescription
servicesIServiceProviderYesThe built container, usually app.Services
serviceKeyobjectKeyed overloadThe key the client was registered with by AddKeyedTraxGraphQLClient
assembliesAssembly[]YesThe assemblies to scan

Returns

A Task that completes when every request has validated.

Behavior

  • The scan covers every concrete, closed class in assemblies that implements IGenericGraphQLClientRequest. The unkeyed overload validates the types with no [GraphQLClient] mark against the unkeyed client's schema; the keyed overload validates the types marked [GraphQLClient(serviceKey)] against the keyed client's schema.
  • Each type is created with RuntimeHelpers.GetUninitializedObject, without running a constructor, and its Query is validated, so a Query must not depend on constructor state. A literal string, a GraphQLResourceRequest and a TypedRequest qualify.
  • Validation stops at the first failure. Each query that passes is cached by the validator, which is the cache the executor uses.
ExceptionWhen
ArgumentNullExceptionAn argument is null
GraphQLValidationExceptionA query does not validate, has no operation, or has more than one. Query holds the failing text and Errors the validator's errors
GraphQLSchemaIntrospectionExceptionThe schema could not be loaded
InvalidOperationExceptionNo request type in assemblies belongs to this client; a request in assemblies is marked with a key no client is registered under; or (keyed overload) no client is registered under serviceKey

Example

var app = builder.Build();
 
await app.Services.ValidateGraphQLClientAssembliesAsync(typeof(Program).Assembly);
await app.Services.ValidateGraphQLClientAssembliesAsync("billing", typeof(Program).Assembly);
 
app.Run();

See also