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
| Parameter | Type | Required | Description |
|---|---|---|---|
builder | TraxGraphQLClientBuilder | Yes | The client's builder |
assemblies | Assembly[] | Yes | The assemblies whose request types are validated. At least one |
Returns
The same TraxGraphQLClientBuilder.
Behavior
- Throws
ArgumentNullExceptionwhenbuilderorassembliesisnull, andArgumentExceptionwhenassembliesis 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 inassemblies, 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
Runof each request does not validate again.
Example
services
.AddTraxGraphQLClient(new Uri("https://api.example.com/graphql"))
.UseFileSchema("schema.graphql")
.UseStartupValidation(typeof(Program).Assembly);