Help us shape the future of Go! Take the 2026 Go Developer Survey

validator

package
v2.5.64 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 15 Imported by: 148

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Message      = core.Message
	QuotedOrList = core.QuotedOrList
	OrList       = core.OrList
)
View Source
var ErrUnexpectedType = errors.New("Unexpected Type")
View Source
var Prelude = &ast.Source{
	Name:    "prelude.graphql",
	Input:   preludeGraphql,
	BuiltIn: true,
}

Prelude is the GraphQL source of the types and directives the spec declares implicitly. gqlparser.LoadSchema adds it ahead of the caller's sources.

Functions

func AddRule

func AddRule(name string, ruleFunc RuleFunc)

AddRule adds a rule to the rule set. ruleFunc is called once each time `Validate` is executed.

func IsValidFloatString added in v2.4.2

func IsValidFloatString(val reflect.Value, kind reflect.Kind) bool

func IsValidIntString added in v2.4.2

func IsValidIntString(val reflect.Value, kind reflect.Kind) bool

func LoadSchema

func LoadSchema(inputs ...*Source) (*Schema, error)

func PreludeDocument added in v2.5.64

func PreludeDocument() *ast.SchemaDocument

PreludeDocument returns the parsed Prelude: the built-in scalars, directives and introspection types that LoadSchema adds to every schema. Use it to find out what this version of gqlparser declares, instead of keeping a copy of those names.

Each call parses Prelude again, so the caller owns the result and may modify it. It panics if the embedded prelude does not parse, which is a gqlparser bug.

func QueryIntrospectionFields added in v2.5.64

func QueryIntrospectionFields() ast.FieldList

QueryIntrospectionFields returns the __schema and __type fields that the spec adds to the query root type. ValidateSchemaDocument appends them to the query type it finds; a caller that supplies its own query type needs them too.

Each call returns new definitions, so the caller owns the result.

func RemoveRule added in v2.5.18

func RemoveRule(name string)

RemoveRule removes an existing rule from the rule set if one of the same name exists. The rule set is global, so it is not safe for concurrent changes.

func ReplaceRule added in v2.5.21

func ReplaceRule(name string, ruleFunc RuleFunc)

ReplaceRule replaces an existing rule from the rule set if one of the same name exists. If no match is found, it will add a new rule to the rule set. The rule set is global, so it is not safe for concurrent changes.

func Validate deprecated

func Validate(schema *Schema, doc *QueryDocument, rules ...Rule) gqlerror.List

Deprecated: use ValidateWithRules instead.

func ValidateSchemaDocument

func ValidateSchemaDocument(sd *SchemaDocument) (*Schema, error)

func ValidateWithRules added in v2.5.29

func ValidateWithRules(
	schema *Schema,
	doc *QueryDocument,
	rules *validatorrules.Rules,
) gqlerror.List

func ValidateWithRulesWithSources added in v2.5.37

func ValidateWithRulesWithSources(
	schema *Schema,
	doc *QueryDocument,
	rules *validatorrules.Rules,
) gqlerror.SourceList

ValidateWithRulesWithSources is the source-aware counterpart to ValidateWithRules.

func ValidateWithSources added in v2.5.37

func ValidateWithSources(schema *Schema, doc *QueryDocument, rules ...Rule) gqlerror.SourceList

ValidateWithSources is the source-aware counterpart to Validate. It keeps source documents for every location recorded by the built-in At option while leaving Error and the regular validation API unchanged.

func VariableValues

func VariableValues(
	schema *ast.Schema,
	op *ast.OperationDefinition,
	variables map[string]any,
) (map[string]any, error)

VariableValues coerces and validates variable values.

func Walk

func Walk(schema *Schema, document *QueryDocument, observers *Events)

Walk is an alias for core.Walk.

Types

type AddErrFunc

type AddErrFunc = core.AddErrFunc

type EmptyDefinitionError added in v2.5.59

type EmptyDefinitionError struct {
	Definition *ast.Definition
}

func (*EmptyDefinitionError) Error added in v2.5.59

func (n *EmptyDefinitionError) Error() string

Error implements [error].

type ErrorOption

type ErrorOption = core.ErrorOption

type Events

type Events = core.Events

type Rule added in v2.5.17

type Rule = core.Rule

type RuleFunc added in v2.5.17

type RuleFunc = core.RuleFunc

type Walker

type Walker = core.Walker

Directories

Path Synopsis
internal
preludegen command
Command preludegen writes validator/prelude_directives.go, which reports the directives validator/imported/prelude.graphql declares.
Command preludegen writes validator/prelude_directives.go, which reports the directives validator/imported/prelude.graphql declares.

Jump to

Keyboard shortcuts

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