Reference

IPersistedOperationValidator

Package Trax.Api.GraphQL.PersistedOperationsNamespace Trax.Api.GraphQL.PersistedOperations.Storage.ValidationSource IPersistedOperationValidator.cs, HotChocolateSchemaValidator.cs, NoOpPersistedOperationValidator.cs

Validates a candidate GraphQL document before IPersistedOperationStore.UpsertAsync writes a row.

Signature

public interface IPersistedOperationValidator
{
    Task ValidateAsync(string document, CancellationToken ct);
}
 
public sealed class HotChocolateSchemaValidator : IPersistedOperationValidator
{
    public HotChocolateSchemaValidator(IServiceProvider services, string schemaName = "trax");
}
 
public sealed class NoOpPersistedOperationValidator : IPersistedOperationValidator
{
    public NoOpPersistedOperationValidator();
}

Implementations throw one of the PersistedOperationException subclasses on failure. The storage layer lets these propagate; no row is written and no broadcast fires when validation throws.

Members

ImplementationRegistered byBehavior
HotChocolateSchemaValidatorUsePersistedOperations(...) on TraxGraphQLBuilderParses with Utf8GraphQLParser, then runs HotChocolate's DocumentValidator against the live schema. Throws PersistedOperationParseException for syntax errors and PersistedOperationValidationException for schema mismatches (unknown field, wrong variable type, missing required variable, etc.).
NoOpPersistedOperationValidatorAddPersistedOperationStore(...) (standalone admin path)Accepts any input. The shape-diff guardrail still runs in the store.

Behavior

HotChocolateSchemaValidator validates against the schema named schemaName, Trax's by default. It resolves HotChocolate's IRequestExecutorProvider lazily on first call so the validator can be constructed before GraphQL composition is final. The resolved executor and the schema's own DocumentValidator are cached for the lifetime of the validator.

Example

UpsertAsync calls the validator; it can also be resolved directly:

var validator = serviceProvider.GetRequiredService<IPersistedOperationValidator>();
 
try
{
    await validator.ValidateAsync(candidateDocument, ct);
}
catch (PersistedOperationValidationException ex)
{
    foreach (var failure in ex.Failures)
        Console.Error.WriteLine($"{failure.Message} (line {failure.Locations.FirstOrDefault().Line})");
}

See also