validator

package
v2.1.1-0...-c9e512f Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Prelude = &ast.Source{
	Name:    "prelude.graphql",
	Input:   "# This file defines all the implicitly declared types that are required by the graphql spec. It is implicitly included by calls to LoadSchema\n\n\"The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.\"\nscalar Int\n\n\"The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).\"\nscalar Float\n\n\"The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.\"\nscalar String\n\n\"The `Boolean` scalar type represents `true` or `false`.\"\nscalar Boolean\n\n\"\"\"The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID.\"\"\"\nscalar ID\n\n\"Directs the executor to include this field or fragment only when the `if` argument is true.\"\ndirective @include(\n  \"Included when true.\"\n  if: Boolean!\n) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT\n\n\"Directs the executor to skip this field or fragment when the `if` argument is true.\"\ndirective @skip(\n  \"Skipped when true.\"\n  if: Boolean!\n) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT\n\n\"Marks an element of a GraphQL schema as no longer supported.\"\ndirective @deprecated(\n  \"Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).'\"\n  reason: String = \"No longer supported\"\n) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE\n\n\"Exposes a URL that specifies the behaviour of this scalar.\"\ndirective @specifiedBy(\n  \"The URL that specifies the behaviour of this scalar.\"\n  url: String!\n) on SCALAR\n\n\"A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.\"\ntype __Schema {\n  description: String\n  \"A list of all types supported by this server.\"\n  types: [__Type!]!\n  \"The type that query operations will be rooted at.\"\n  queryType: __Type!\n  \"If this server supports mutation, the type that mutation operations will be rooted at.\"\n  mutationType: __Type\n  \"If this server support subscription, the type that subscription operations will be rooted at.\"\n  subscriptionType: __Type\n  \"A list of all directives supported by this server.\"\n  directives: [__Directive!]!\n}\n\n\"The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.\\n\\nDepending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByUrl`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.\"\ntype __Type {\n  kind: __TypeKind!\n  name: String\n  description: String\n\n  # should be non-null for OBJECT and INTERFACE only, must be null for the others\n  fields(includeDeprecated: Boolean = false): [__Field!]\n\n  # should be non-null for OBJECT and INTERFACE only, must be null for the others\n  interfaces: [__Type!]\n\n  # should be non-null for INTERFACE and UNION only, always null for the others\n  possibleTypes: [__Type!]\n\n  # should be non-null for ENUM only, must be null for the others\n  enumValues(includeDeprecated: Boolean = false): [__EnumValue!]\n\n  # should be non-null for INPUT_OBJECT only, must be null for the others\n  inputFields: [__InputValue!]\n\n  # should be non-null for NON_NULL and LIST only, must be null for the others\n  ofType: __Type\n\n  # should be non-null for custom SCALAR only, must be null for the others\n  specifiedBy: String\n}\n\n\"Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.\"\ntype __Field {\n  name: String!\n  description: String\n  args: [__InputValue!]!\n  type: __Type!\n  isDeprecated: Boolean!\n  deprecationReason: String\n}\n\n\"Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.\"\ntype __InputValue {\n  name: String!\n  description: String\n  type: __Type!\n  \"A GraphQL-formatted string representing the default value for this input value.\"\n  defaultValue: String\n}\n\n\"One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.\"\ntype __EnumValue {\n  name: String!\n  description: String\n  isDeprecated: Boolean!\n  deprecationReason: String\n}\n\n\"An enum describing what kind of type a given `__Type` is.\"\nenum __TypeKind {\n  \"Indicates this type is a scalar.\"\n  SCALAR\n  \"Indicates this type is an object. `fields` and `interfaces` are valid fields.\"\n  OBJECT\n  \"Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields.\"\n  INTERFACE\n  \"Indicates this type is a union. `possibleTypes` is a valid field.\"\n  UNION\n  \"Indicates this type is an enum. `enumValues` is a valid field.\"\n  ENUM\n  \"Indicates this type is an input object. `inputFields` is a valid field.\"\n  INPUT_OBJECT\n  \"Indicates this type is a list. `ofType` is a valid field.\"\n  LIST\n  \"Indicates this type is a non-null. `ofType` is a valid field.\"\n  NON_NULL\n}\n\n\"A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.\\n\\nIn some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.\"\ntype __Directive {\n  name: String!\n  description: String\n  locations: [__DirectiveLocation!]!\n  args: [__InputValue!]!\n  isRepeatable: Boolean!\n}\n\n\"A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.\"\nenum __DirectiveLocation {\n  \"Location adjacent to a query operation.\"\n  QUERY\n  \"Location adjacent to a mutation operation.\"\n  MUTATION\n  \"Location adjacent to a subscription operation.\"\n  SUBSCRIPTION\n  \"Location adjacent to a field.\"\n  FIELD\n  \"Location adjacent to a fragment definition.\"\n  FRAGMENT_DEFINITION\n  \"Location adjacent to a fragment spread.\"\n  FRAGMENT_SPREAD\n  \"Location adjacent to an inline fragment.\"\n  INLINE_FRAGMENT\n  \"Location adjacent to a variable definition.\"\n  VARIABLE_DEFINITION\n  \"Location adjacent to a schema definition.\"\n  SCHEMA\n  \"Location adjacent to a scalar definition.\"\n  SCALAR\n  \"Location adjacent to an object type definition.\"\n  OBJECT\n  \"Location adjacent to a field definition.\"\n  FIELD_DEFINITION\n  \"Location adjacent to an argument definition.\"\n  ARGUMENT_DEFINITION\n  \"Location adjacent to an interface definition.\"\n  INTERFACE\n  \"Location adjacent to a union definition.\"\n  UNION\n  \"Location adjacent to an enum definition.\"\n  ENUM\n  \"Location adjacent to an enum value definition.\"\n  ENUM_VALUE\n  \"Location adjacent to an input object type definition.\"\n  INPUT_OBJECT\n  \"Location adjacent to an input object field definition.\"\n  INPUT_FIELD_DEFINITION\n}",
	BuiltIn: true,
}
View Source
var UnexpectedType = fmt.Errorf("Unexpected Type")

Functions

func AddRule

func AddRule(name string, f ruleFunc)

addRule to rule set. f is called once each time `Validate` is executed.

func LoadSchema

func LoadSchema(inputs ...*Source) (*Schema, *gqlerror.Error)

func OrList

func OrList(items ...string) string

Given [ A, B, C ] return 'A, B, or C'.

func QuotedOrList

func QuotedOrList(items ...string) string

Given [ A, B, C ] return '"A", "B", or "C"'.

func SuggestionList

func SuggestionList(input string, options []string) []string

Given an invalid input string and a list of valid options, returns a filtered list of valid options sorted based on their similarity with the input.

func Validate

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

func ValidateSchemaDocument

func ValidateSchemaDocument(ast *SchemaDocument) (*Schema, *gqlerror.Error)

func VariableValues

func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables map[string]interface{}) (map[string]interface{}, *gqlerror.Error)

VariableValues coerces and validates variable values

func Walk

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

Types

type AddErrFunc

type AddErrFunc func(options ...ErrorOption)

type ErrorOption

type ErrorOption func(err *gqlerror.Error)

func At

func At(position *ast.Position) ErrorOption

func Message

func Message(msg string, args ...interface{}) ErrorOption

func SuggestListQuoted

func SuggestListQuoted(prefix string, typed string, suggestions []string) ErrorOption

func SuggestListUnquoted

func SuggestListUnquoted(prefix string, typed string, suggestions []string) ErrorOption

func Suggestf

func Suggestf(suggestion string, args ...interface{}) ErrorOption

type Events

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

func (*Events) OnDirective

func (o *Events) OnDirective(f func(walker *Walker, directive *ast.Directive))

func (*Events) OnDirectiveList

func (o *Events) OnDirectiveList(f func(walker *Walker, directives []*ast.Directive))

func (*Events) OnField

func (o *Events) OnField(f func(walker *Walker, field *ast.Field))

func (*Events) OnFragment

func (o *Events) OnFragment(f func(walker *Walker, fragment *ast.FragmentDefinition))

func (*Events) OnFragmentSpread

func (o *Events) OnFragmentSpread(f func(walker *Walker, fragmentSpread *ast.FragmentSpread))

func (*Events) OnInlineFragment

func (o *Events) OnInlineFragment(f func(walker *Walker, inlineFragment *ast.InlineFragment))

func (*Events) OnOperation

func (o *Events) OnOperation(f func(walker *Walker, operation *ast.OperationDefinition))

func (*Events) OnValue

func (o *Events) OnValue(f func(walker *Walker, value *ast.Value))

type Walker

type Walker struct {
	Context   context.Context
	Observers *Events
	Schema    *ast.Schema
	Document  *ast.QueryDocument

	CurrentOperation *ast.OperationDefinition
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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