validator

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InlineRule

type InlineRule interface {
	EnterField(ctx *WalkContext, parentDef *ast.Definition, field *ast.Field) gqlerror.List
	EnterFragment(ctx *WalkContext, parentDef *ast.Definition, frag ast.Selection) gqlerror.List
	EnterDirective(ctx *WalkContext, parentDef *ast.Definition, dir *ast.Directive) gqlerror.List
	EnterArgument(ctx *WalkContext, argDef *ast.ArgumentDefinition, arg *ast.Argument) gqlerror.List
}

InlineRule is called by the walker during AST traversal at each node.

type Option

type Option func(*Validator)

Option configures a Validator.

func WithInlineRule

func WithInlineRule(r InlineRule) Option

WithInlineRule adds an inline rule to the validator.

func WithPostRule

func WithPostRule(r PostRule) Option

WithPostRule adds a post-walk rule to the validator.

type PostRule

type PostRule interface {
	Validate(ctx *WalkContext, document *ast.QueryDocument) gqlerror.List
}

PostRule is called after the walker completes its full traversal.

type TypeResolver

type TypeResolver interface {
	ForName(ctx context.Context, name string) *ast.Definition
	DirectiveForName(ctx context.Context, name string) *ast.DirectiveDefinition
	QueryType(ctx context.Context) *ast.Definition
	MutationType(ctx context.Context) *ast.Definition
	SubscriptionType(ctx context.Context) *ast.Definition
	PossibleTypes(ctx context.Context, name string) iter.Seq[*ast.Definition]
	Implements(ctx context.Context, name string) iter.Seq[*ast.Definition]
}

TypeResolver resolves types and directives from the schema. Matches a subset of schema.Provider methods but is defined here to avoid circular dependency between pkg/schema and pkg/schema/validator.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator validates and enriches GraphQL query documents. Rules are injected via the constructor.

func New

func New(opts ...Option) *Validator

New creates a Validator with the given rules. Without options the validator only performs enrichment (no validation checks). For standard usage: New(DefaultRules()...)

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, provider TypeResolver, document *ast.QueryDocument) gqlerror.List

Validate walks the QueryDocument, enriches the AST, and applies validation rules. The document is mutated: field.Definition, field.ObjectDefinition, etc. are filled in. Returns a list of errors (empty = valid).

type WalkContext

type WalkContext struct {
	Context          context.Context
	Provider         TypeResolver
	Document         *ast.QueryDocument
	CurrentOperation *ast.OperationDefinition
}

WalkContext provides context accessible to all rules during validation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL