valid

package
v0.0.0-...-deb699c Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: BSD-3-Clause Imports: 4 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(ctx context.Context, field string, msg string) error

Returns a new GraphQL error attached to the given field.

func Errorf

func Errorf(ctx context.Context, field string, msg string, items ...interface{}) error

Returns a new GraphQL error attached to the given field.

Types

type Validation

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

func New

func New(ctx context.Context) *Validation

Creates a new validation context.

func (*Validation) Error

func (valid *Validation) Error(msg string,
	items ...interface{}) *ValidationError

Creates a validation error unconditionally.

func (*Validation) Expect

func (valid *Validation) Expect(cond bool,
	msg string, items ...interface{}) *ValidationError

Asserts that a condition is true, recording a GraphQL error with the given message if not.

func (*Validation) NullableString

func (valid *Validation) NullableString(name string, fn func(s *string))

Fetches a nullable string from the validation context, which must have an input registered. If the field is not present, the callback is not run. If present, but null, the function is called with null set to true. Otherwise, the function is called with the string for the user to conduct further validation with.

func (*Validation) Ok

func (valid *Validation) Ok() bool

Returns true if no errors were found.

func (*Validation) Optional

func (valid *Validation) Optional(name string, fn func(i interface{}))

Fetches an item from the validation context, which must have an input registered. If the field is not present, the callback is not run. Otherwise, the function is called with the value for the user to conduct further validation with.

func (*Validation) OptionalBool

func (valid *Validation) OptionalBool(name string, fn func(b bool))

Fetches a boolean from the validation context, which must have an input registered. If the field is not present, the callback is not run. If present, but not a boolean, an error is recorded. Otherwise, the function is called with the boolean for the user to conduct further validation with.

func (*Validation) OptionalString

func (valid *Validation) OptionalString(name string, fn func(s string))

Fetches a string from the validation context, which must have an input registered. If the field is not present, the callback is not run. If present, but not a string, an error is recorded. Otherwise, the function is called with the string for the user to conduct further validation with.

func (*Validation) WithInput

func (valid *Validation) WithInput(input map[string]interface{}) *Validation

Adds an input map to a validation context.

type ValidationError

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

func (*ValidationError) And

func (err *ValidationError) And(cond bool,
	msg string, items ...interface{}) *ValidationError

Composes another assertion onto the same validation context which initially created an error. Short-circuiting is used, such that if the earlier condition failed, the new condition is not considered.

func (*ValidationError) WithField

func (err *ValidationError) WithField(field string) *ValidationError

Associates a field name with an error.

Jump to

Keyboard shortcuts

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