validation

package
v0.365.15 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type InvalidManyToManyDetails

type InvalidManyToManyDetails struct {
	InverseModel *parser.ModelNode
	InverseField *parser.FieldNode
	ThisModel    *parser.ModelNode
	ThisField    *parser.FieldNode
}

type ManyToOneRelation

type ManyToOneRelation struct {
	ManyModel string
	ManyField string
	OneModel  string
	OneField  string
}

type Validator

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

func NewValidator

func NewValidator(asts []*parser.AST) *Validator

func (*Validator) RunAllValidators

func (v *Validator) RunAllValidators() (errs *errorhandling.ValidationErrors)

type Visitor

type Visitor struct {
	EnterModel func(n *parser.ModelNode)
	LeaveModel func(n *parser.ModelNode)

	EnterModelSection func(n *parser.ModelSectionNode)
	LeaveModelSection func(n *parser.ModelSectionNode)

	EnterMessage func(n *parser.MessageNode)
	LeaveMessage func(n *parser.MessageNode)

	EnterField func(n *parser.FieldNode)
	LeaveField func(n *parser.FieldNode)

	EnterAction func(n *parser.ActionNode)
	LeaveAction func(n *parser.ActionNode)

	EnterWith func(n *parser.ActionNode)
	LeaveWith func(n *parser.ActionNode)

	EnterActionInput func(n *parser.ActionInputNode)
	LeaveActionInput func(n *parser.ActionInputNode)

	EnterEnum func(n *parser.EnumNode)
	LeaveEnum func(n *parser.EnumNode)

	EnterRole func(n *parser.RoleNode)
	LeaveRole func(n *parser.RoleNode)

	EnterAttribute func(n *parser.AttributeNode)
	LeaveAttribute func(n *parser.AttributeNode)

	EnterAttributeArgument func(n *parser.AttributeArgumentNode)
	LeaveAttributeArgument func(n *parser.AttributeArgumentNode)

	EnterAPI func(n *parser.APINode)
	LeaveAPI func(n *parser.APINode)

	EnterJob func(n *parser.JobNode)
	LeaveJob func(n *parser.JobNode)

	EnterJobInput func(n *parser.JobInputNode)
	LeaveJobInput func(n *parser.JobInputNode)
}

Visitor lets you define "enter" and "leave" functions for AST nodes. This struct may not have fields for all AST nodes, so if you need to visit a node that is not currently supported add the necessary fields to this struct. For your functions to get called you must name these fields correctly.

For a node type called "SomethingNode" the hooks would be:

EnterSomething: func(n *parser.SomethingNode)
LeaveSomething: func(n *parser.SomethingNode)

func AttributeArgumentsRule

func AttributeArgumentsRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

Validates the arguments to any attribute expression.

func CasingRule

func CasingRule(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

Casing checks that entities in the schema conform to our casing conventions.

Models, enums, enum values, roles, and API's must written in UpperCamelCase. Fields, actions, and inputs must be written in lowerCamelCase.

func ConflictingInputsRule

func ConflictingInputsRule(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

ConflictingInputsRule checks for model inputs that are also used in @set or @where attributes. In this case one usage would cancel out the other, so it doesn't make sense to have both.

For example in the getThing operation `id` is listed as a model input but is also used in a @where expression.

func DirectManyToManyRule

func DirectManyToManyRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

DirectManyToManyRule checks that a direct many to many relationship between two models hasn't been defined, and recommends creating a join model.

func DuplicateDefinitionRule

func DuplicateDefinitionRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

DuplicateDefinitionRule checks the uniqueness of model, enum and message names.

Model, enum, and message names need to be globally unique.

func DuplicateInputsRule

func DuplicateInputsRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

DuplicateInputsRule checks that input names are not duplicated for an action.

func FunctionDisallowedBehavioursRule

func FunctionDisallowedBehavioursRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

FunctionDisallowedBehavioursRule will validate against usages of @set, @where and nested inputs for any actions marked with the @function attribute as we do not support these sets of functionality in @function's

func InvalidWithUsage

func InvalidWithUsage(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

InvalidWithUsage checks that the 'with' keyword is only used for actions that receive write values

func Jobs

func Jobs(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func NameClashesRule

func NameClashesRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

NameClashes checks that the names of entities defined in a schema do not clash with built-in types or reserved keywords

func OnAttributeRule

func OnAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func OrderByAttributeRule

func OrderByAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func RepeatedScalarFieldRule

func RepeatedScalarFieldRule(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

RepeatedScalarFieldRule validates that you cannot define a repeated scalar field This will be temporary until we can support repeated fields at the database level

func RequiredFieldOfSameMessageType

func RequiredFieldOfSameMessageType(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

RequiredFieldOfSameMessageType ensures that a message cannot have a field of the same type, as this results in an infinite recursion.

func RequiredFieldOfSameModelType

func RequiredFieldOfSameModelType(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

RequiredFieldOfSameModelType ensures that a model cannot have a field of the same type, as this results in an infinite recursion.

func ScheduleAttributeRule

func ScheduleAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func SortableAttributeRule

func SortableAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

func UniqueAttributeRule

func UniqueAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

UniqueAttributeRule validates that unique attributes are valid according to the following rules: - @unique can't be used on Timestamp fields - @unique can't be used on has-many relations - composite @unique attributes must not have duplicate field names - composite @unique can't specify has-many fields

func UnusedInputRule

func UnusedInputRule(_ []*parser.AST, errs *errorhandling.ValidationErrors) Visitor

UnusedInputRule checks that all named action inputs are used in either @set or @where expressions in the action.

type VisitorFunc

type VisitorFunc func([]*parser.AST, *errorhandling.ValidationErrors) Visitor

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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