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
| Parameter | Type | Required | Description |
|---|---|---|---|
services | IServiceProvider | Yes | The built container, usually app.Services |
serviceKey | object | Keyed overload | The key the client was registered with by AddKeyedTraxGraphQLClient |
assemblies | Assembly[] | Yes | The assemblies to scan |
Returns
A Task that completes when every request has validated.
Behavior
- The scan covers every concrete, closed class in
assembliesthat implementsIGenericGraphQLClientRequest. 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 itsQueryis validated, so aQuerymust 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.
| Exception | When |
|---|---|
ArgumentNullException | An argument is null |
GraphQLValidationException | A query does not validate, has no operation, or has more than one. Query holds the failing text and Errors the validator's errors |
GraphQLSchemaIntrospectionException | The schema could not be loaded |
InvalidOperationException | No 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
- UseStartupValidation, the same check from a hosted service
- IGraphQLClientValidator, whose
ValidateAssembliesAsyncscans without the ownership rule - Check outbound queries against a schema snapshot