graphql

package
v0.0.0-...-32f7d7b Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: ISC, MIT Imports: 20 Imported by: 0

Documentation

Overview

Package graphql provides an implementation of GraphQL. It provides foundation to build GraphQL type schema and to serve queries against that type schema.

TypeDefinition-NewType-Type Design

Each Type has corresponding TypeDefinition which provides a set of interfaces for NewType to get required data to initialize instance for the Type.

Instead of providing data (or definition) for creating Type via a concrete object (i.e., `struct`), TypeDefinition provides the data by requiring type creator to implement an object that fulfills a set of interfaces. NewType will read data through the interfaces. Because referencing data in function never causes "initialization loop" like global variables, types that depends on each other and even depends on itself can be achieved without additional work.

The added TypeDefinition abstraction and the ability to provide complete type dependency graph (through the way mentioned above) enables us to deal with circular type creation in the library.

Note that every instance of TypeDefinition creates at most one Type instance. NewType tracks the Type instantiation by mapping the Type instance to its TypeDefinition instance. This implies that once the Type instance corresponded to the TypeDefinition is created, changes that made to TypeDefinition won't reflect to the created Type. Type instance for a TypeDefinition is created when NewType is called with the TypeDefinition instance or any types that reference to the TypeDefinition instance.

Index

Constants

View Source
const (
	// Executable directive location
	DirectiveLocationQuery              DirectiveLocation = "QUERY"
	DirectiveLocationMutation                             = "MUTATION"
	DirectiveLocationSubscription                         = "SUBSCRIPTION"
	DirectiveLocationField                                = "FIELD"
	DirectiveLocationFragmentDefinition                   = "FRAGMENT_DEFINITION"
	DirectiveLocationFragmentSpread                       = "FRAGMENT_SPREAD"
	DirectiveLocationInlineFragment                       = "INLINE_FRAGMENT"
	DirectiveLocationVariableDefinition                   = "VARIABLE_DEFINITION"

	// Type system directive location
	DirectiveLocationSchema               = "SCHEMA"
	DirectiveLocationScalar               = "SCALAR"
	DirectiveLocationObject               = "OBJECT"
	DirectiveLocationFieldDefinition      = "FIELD_DEFINITION"
	DirectiveLocationArgumentDefinition   = "ARGUMENT_DEFINITION"
	DirectiveLocationInterface            = "INTERFACE"
	DirectiveLocationUnion                = "UNION"
	DirectiveLocationEnum                 = "ENUM"
	DirectiveLocationEnumValue            = "ENUM_VALUE"
	DirectiveLocationInputObject          = "INPUT_OBJECT"
	DirectiveLocationInputFieldDefinition = "INPUT_FIELD_DEFINITION"
)

Reference: https://graphql.github.io/graphql-spec/June2018/#DirectiveLocations

View Source
const (
	// Search with the enum value whose name matches the given value when performing coercion. This is
	// considered faster than by-value and consume less memory usage. This is also the default
	// strategy.
	DefaultEnumResultCoercerLookupByName = iota

	// Search with the enum value whose internal value matches the given value when performing
	// coercion.
	DefaultEnumResultCoercerLookupByValue

	// This is the same as DefaultEnumResultCoercerLookupByValue. Except when the given value is a
	// pointer, it will look up enum value whose internal value matches the value dereferenced from
	// the pointer. This implements graphql-go's strategy.
	DefaultEnumResultCoercerLookupByValueDeref
)

Enumeration of DefaultEnumResultCoercerLookupStrategy

View Source
const (
	SchemaMetaFieldName   = "__schema"
	TypeMetaFieldName     = "__type"
	TypenameMetaFieldName = "__typename"
)

List of meta-field names

View Source
const DefaultDeprecationReason = "No longer supported"

DefaultDeprecationReason is a constant string used for default reason for a deprecation.

View Source
const NilArgumentDefaultValue argumentNilValueType = 0

NilArgumentDefaultValue is a value that has a special meaning when it is given to the DefaultValue in ArgumentDefinition. It sets the argument with default value set to "null". While setting DefaultValue to "nil" or not giving it a value means there's no default value. We need this trick because using only "nil" cannot tells whether it's an "undefined" or a "null" DefaultValue. The constant has an internal type, therefore there's no way to create one outside the package.

View Source
const NilEnumInternalValue enumNilValueType = 0

NilEnumInternalValue is a value that has a special meaning when it is given to the Value field in EnumValueDefinition. By default, when the nil is given in Value field (this can also be happened when user doesn't specify value for the field), the internal value for created enum value will be initialized to its enum name. When this special value is used, the internal value will set to nil.

View Source
const NilInputFieldDefaultValue inputFieldNilValueType = 0

NilInputFieldDefaultValue is a value that has a special meaning when it is given to the DefaultValue in InputFieldDefinition. It sets the argument with default value set to "null". This is not the same with setting DefaultValue to "nil" or not giving it a value which means there's no default value. We need this trick to distiguish from whether the input field has a default value "nil" or it doesn't have one at all. The constant has an internal type, therefore there's no way to create one outside the package.

Variables

View Source
var IntrospectionTypes = introspectionTypes{}

IntrospectionTypes provides accessors to the types used specifically for introspection.

Functions

func Inspect

func Inspect(v interface{}) string

Inspect calls InspectOrErr but panics on error.

func InspectTo

func InspectTo(out io.Writer, v interface{}) error

InspectTo prints Go values v to the given buf in the same format as graphql-js's inspect function. The implementation matches https://github.com/graphql/graphql-js/blob/1375776/src/jsutils/inspect.js.

Note that errors returned from out.Write are ignored.

func IsAbstractType

func IsAbstractType(t Type) bool

IsAbstractType returns true if the given type is a abstract.

func IsCompositeType

func IsCompositeType(t Type) bool

IsCompositeType true if the given type is one of object, interface or union.

func IsEnumType

func IsEnumType(t Type) bool

IsEnumType returns true if the given type is an Enum type.

func IsInputObjectType

func IsInputObjectType(t Type) bool

IsInputObjectType returns true if the given type is an Input Object type.

func IsInputType

func IsInputType(t Type) bool

IsInputType returns true if the given type is valid for values in input arguments and variables.

Reference: https://graphql.github.io/graphql-spec/June2018/#IsInputType()

func IsInterfaceType

func IsInterfaceType(t Type) bool

IsInterfaceType returns true if the given type is an Interface type.

func IsLeafType

func IsLeafType(t Type) bool

IsLeafType returns true if the given type is a leaf.

func IsListType

func IsListType(t Type) bool

IsListType returns true if the given type is a List type.

func IsNamedType

func IsNamedType(t Type) bool

IsNamedType returns true if the type is a non-wrapping type.

Reference: https://graphql.github.io/graphql-spec/draft/#sec-Wrapping-Types

func IsNonNullType

func IsNonNullType(t Type) bool

IsNonNullType returns true if the given type is a NonNull type.

func IsNullableType

func IsNullableType(t Type) bool

IsNullableType returns true if the type accepts null value.

func IsObjectType

func IsObjectType(t Type) bool

IsObjectType returns true if the given type is an Object type.

func IsOutputType

func IsOutputType(t Type) bool

IsOutputType returns true if the given type is valid for values in field output.

Reference: https://graphql.github.io/graphql-spec/draft/#IsOutputType()

func IsRequiredArgument

func IsRequiredArgument(arg *Argument) bool

IsRequiredArgument returns true if value must be provided to the argument for execution.

func IsRequiredInputField

func IsRequiredInputField(field InputField) bool

IsRequiredInputField returns true if value must be provided to the input field for execution.

func IsScalarType

func IsScalarType(t Type) bool

IsScalarType returns true if the given type is a Scalar type.

func IsTypeSubTypeOf

func IsTypeSubTypeOf(schema Schema, maybeSubType Type, superType Type) bool

IsTypeSubTypeOf returns true if Provided a type and a super type, return true if the first type is either equal or a subset of the second super type (covariant).

func IsUnionType

func IsUnionType(t Type) bool

IsUnionType returns true if the given type is an Union type.

func IsWrappingType

func IsWrappingType(t Type) bool

IsWrappingType returns true if the given type is a wrapping type.

func NewCoercionError

func NewCoercionError(format string, a ...interface{}) error

NewCoercionError raises an error to indicate an error due to coercion failure (for either input coercion or result coercion defined in 0). The error is tagged with ErrKindCoercion and several functions will take special care of it which described as follows:

1. For coercion errors returning from Enum and Scalar's CoerceResultValue:

  • When execution engine sees these error (in `CompleteValue` 1, and look our implementation of `executor.Common.completeLeafValue`, more specifically), it will bypass the errors directly to the caller, resulting a field/query error containing the message as the one carried by the errors. Otherwise, execution engine will wrap the error with NewDefaultResultCoercionError.

2. For coercion errors returning from Enum and Scalar's CoerceVariableValue:

  • When CoerceValue sees these errors, it will present a query error with the message specified in the error to the user.

3. For coercion errors returning from Enum and Scalar's CoerceLiteralValue:

  • Currently it makes no difference than other errors.

func NewDefaultResultCoercionError

func NewDefaultResultCoercionError(typeName string, value interface{}, err error) error

NewDefaultResultCoercionError creates a CoercionError for result coercion with a default message.

func NewError

func NewError(message string, args ...interface{}) error

NewError builds an error value from arguments. Inspired by the design of upspin.io/errors 0.

func NewErrorMarshaler

func NewErrorMarshaler(err *Error) jsonwriter.ValueMarshaler

NewErrorMarshaler creates marshaler to write JSON encoding for given Error with jsonwriter.

func NewErrorsMarshaler

func NewErrorsMarshaler(errs Errors) jsonwriter.ValueMarshaler

NewErrorsMarshaler creates marshaler to write JSON encoding for given errs with jsonwriter.

func NewResponsePathMarshaler

func NewResponsePathMarshaler(path *ResponsePath) jsonwriter.ValueMarshaler

NewResponsePathMarshaler creates marshaler to write JSON encoding for given ResponsePath with jsonwriter.

func NewSyntaxError

func NewSyntaxError(source *token.Source, location token.SourceLocation, description string) error

NewSyntaxError produces an error representing a syntax error, containing useful descriptive information about the syntax error's position in the source.

func WrapError

func WrapError(err error, message string) error

WrapError is a convenient wrapper to build an Error value from an underlying error with a message.

func WrapErrorf

func WrapErrorf(err error, format string, args ...interface{}) error

WrapErrorf is similar to WrapError but with the format specifier.

Types

type AbstractType

type AbstractType interface {
	Type
	TypeWithName
	TypeWithDescription

	// TypeResolver returns resolver that could determine the concrete Object type for the abstract
	// type from resolved value.
	//
	// Reference: https://graphql.github.io/graphql-spec/June2018/#ResolveAbstractType()
	TypeResolver() TypeResolver
	// contains filtered or unexported methods
}

AbstractType indicates a GraphQL abstract type. Namely, interfaces and unions.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Types

type Argument

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

Argument is accepted in querying a field to further specify the return value.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Field-Arguments

func MockArgument

func MockArgument(name string, description string, t Type, defaultValue interface{}) Argument

MockArgument creates an Argument object. This is only used in the tests to create an Argument for comparing with one in Type instances. We never use this to create an Argument.

func (*Argument) DefaultValue

func (arg *Argument) DefaultValue() interface{}

DefaultValue specifies the value to be assigned to the argument when no value is provided.

func (*Argument) Description

func (arg *Argument) Description() string

Description of the argument

func (*Argument) HasDefaultValue

func (arg *Argument) HasDefaultValue() bool

HasDefaultValue returns true if the argument has a default value.

func (*Argument) Name

func (arg *Argument) Name() string

Name of the argument

func (*Argument) Type

func (arg *Argument) Type() Type

Type of the value that can be given to the argument

type ArgumentConfig

type ArgumentConfig struct {
	// Description fo the argument
	Description string

	// Type of the value that can be given to the argument
	Type TypeDefinition

	// DefaultValue specified the value to be assigned to the argument when no value is provided.
	DefaultValue interface{}
}

ArgumentConfig provides definition for defining an argument in a field.

type ArgumentConfigMap

type ArgumentConfigMap map[string]ArgumentConfig

ArgumentConfigMap maps argument name to its definition.

type ArgumentValues

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

An ArgumentValues contains argument values given to a field. It is immutable after it is created.

func NewArgumentValues

func NewArgumentValues(values map[string]interface{}) ArgumentValues

NewArgumentValues creates an ArgumentValues from given values.

func NoArgumentValues

func NoArgumentValues() ArgumentValues

NoArgumentValues represents an empty argument value set.

func (ArgumentValues) Get

func (args ArgumentValues) Get(name string) interface{}

Get returns argument value for the given name. It returns nil if no such argument was found.

func (ArgumentValues) Lookup

func (args ArgumentValues) Lookup(name string) (value interface{}, ok bool)

Lookup returns argument value for the given name. If argument with the given name doesn't exist, returns nil. The second value (ok) is a bool that is true if the argument exists, and false if not.

func (ArgumentValues) MarshalJSON

func (args ArgumentValues) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler to serialize the internal map in ArgumentValues into JSON. This is primarily used by tests for verifying argument values.

type CoerceEnumResultFunc

type CoerceEnumResultFunc func(value interface{}) (EnumValue, error)

CoerceEnumResultFunc is an adapter to allow the use of ordinary functions as EnumResultCoercer.

func (CoerceEnumResultFunc) Coerce

func (f CoerceEnumResultFunc) Coerce(value interface{}) (EnumValue, error)

Coerce calls f(enum, value).

type CreateEnumResultCoercerFunc

type CreateEnumResultCoercerFunc func(enum Enum) (EnumResultCoercer, error)

CreateEnumResultCoercerFunc is an adapter to allow the use of ordinary functions as EnumResultCoercerFactory.

func (CreateEnumResultCoercerFunc) Create

Create calls f(enum).

type DataLoaderManager

type DataLoaderManager interface {
	// HasPendingDataLoaders returns true if there's any data loaders waiting for dispatch.
	HasPendingDataLoaders() bool

	// GetAndResetPendingDataLoaders reports DataLoader's that are waiting for dispatching and resets
	// current list.
	GetAndResetPendingDataLoaders() map[*dataloader.DataLoader]bool
}

DataLoaderManager provides a way to,

  1. Let user manage DataLoader instances being used during execution and access the loaders via ResolveInfo;
  2. Let executor know which DataLoader's are pending for batch data fetching and schedule for their dispatch.

type DataLoaderManagerBase

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

DataLoaderManagerBase is useful to embed in a DataLoaderManager class to track the use of data loaders as required by DataLoaderManager.

func (*DataLoaderManagerBase) GetAndResetPendingDataLoaders

func (manager *DataLoaderManagerBase) GetAndResetPendingDataLoaders() map[*dataloader.DataLoader]bool

GetAndResetPendingDataLoaders implements DataLoaderManager.HasPendingDataLoaders.

func (*DataLoaderManagerBase) HasPendingDataLoaders

func (manager *DataLoaderManagerBase) HasPendingDataLoaders() bool

HasPendingDataLoaders implements DataLoaderManager.HasPendingDataLoaders.

func (*DataLoaderManagerBase) LoadManyWith

func (manager *DataLoaderManagerBase) LoadManyWith(loader *dataloader.DataLoader, keys dataloader.Keys) (future.Future, error)

LoadManyWith requests given loader for data at given keys. It also updates pendingLoaders as appropriated. It is very similar to LoadWith with just `loader.Load` replaced with `loader.LoadMany`.

func (*DataLoaderManagerBase) LoadWith

func (manager *DataLoaderManagerBase) LoadWith(loader *dataloader.DataLoader, key dataloader.Key) (future.Future, error)

LoadWith requests given loader for data at given key. It also updates pendingLoaders as appropriated.

type DefaultEnumResultCoercerLookupStrategy

type DefaultEnumResultCoercerLookupStrategy uint

DefaultEnumResultCoercerLookupStrategy specifies how to search the enum value.

type Deprecation

type Deprecation struct {
	// Reason provides a description of why the subject is deprecated.
	Reason string
}

Deprecation contains information about deprecation for a field or an enum value.

See https://graphql.github.io/graphql-spec/June2018/#sec-Deprecation.

func (*Deprecation) Defined

func (d *Deprecation) Defined() bool

Defined returns true if the deprecation is active.

type Directive

type Directive interface {
	// Name of the directive
	Name() string

	// Description provides documentation for the directive.
	Description() string

	// Locations specifies the places where the directive must only be used.
	Locations() []DirectiveLocation

	// Args indicates the arguments taken by the directive.
	Args() []Argument
}

Directive are used by the GraphQL runtime as a way of modifying a validator, execution or client tool behavior.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Type-System.Directives

func DeprecatedDirective

func DeprecatedDirective() Directive

DeprecatedDirective returns directive definition for @deprecated.

func IncludeDirective

func IncludeDirective() Directive

IncludeDirective returns directive definition for @include.

func MustNewDirective

func MustNewDirective(config *DirectiveConfig) Directive

MustNewDirective is a convenience function equivalent to NewDirective but panics on failure instead of returning an error.

func NewDirective

func NewDirective(config *DirectiveConfig) (Directive, error)

NewDirective creates a Directive from a DirectiveConfig.

func SkipDirective

func SkipDirective() Directive

SkipDirective returns directive definition for @skip.

func StandardDirectives

func StandardDirectives() []Directive

StandardDirectives returns list of directives that should be included in a standard GraphQL as per specification.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Type-System.Directives

type DirectiveConfig

type DirectiveConfig struct {
	// Name of the defining Directive
	Name string

	// Description for the Directive type
	Description string

	// Locations in the schema where the defining directive can appear
	Locations []DirectiveLocation

	// Arguments to be provided when using the directive
	Args ArgumentConfigMap
}

DirectiveConfig provides definition for creating a Directive.

func (*DirectiveConfig) DeepCopy

func (config *DirectiveConfig) DeepCopy() *DirectiveConfig

DeepCopy makes a copy of receiver.

type DirectiveList

type DirectiveList []Directive

DirectiveList is a list of Directive.

func (DirectiveList) Lookup

func (directiveList DirectiveList) Lookup(name string) Directive

Lookup finds a directive with given name in the list.

type DirectiveLocation

type DirectiveLocation string

DirectiveLocation specifies a valid location for a directive to be used.

type Enum

type Enum interface {
	LeafType

	// Values return all enum values defined in this Enum type.
	Values() EnumValueMap
	// contains filtered or unexported methods
}

Enum Type Definition

Some leaf values of requests and input values are Enums. GraphQL serializes Enum values as strings, however internally Enums can be represented by any kind of type, often integers.

Note: If a value is not provided in a definition, the name of the enum value will be used as its

internal value.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Enums

func MustNewEnum

func MustNewEnum(typeDef EnumTypeDefinition) Enum

MustNewEnum is a convenience function equivalent to NewEnum but panics on failure instead of returning an error.

func NewEnum

func NewEnum(typeDef EnumTypeDefinition) (Enum, error)

NewEnum defines a Enum type from a EnumTypeDefinition.

type EnumConfig

type EnumConfig struct {
	ThisIsTypeDefinition

	// Name of the enum type
	Name string

	// Description for the enum type
	Description string

	// Values to be defined in the enum
	Values EnumValueDefinitionMap

	// ResultCoercerFactory creates an EnumResultCoercer to coerce an internal value into enum value
	// into. If not provided, DefaultEnumResultCoercerFactory(DefaultEnumResultCoercerLookupByName)
	// will be used.
	ResultCoercerFactory EnumResultCoercerFactory
}

EnumConfig provides specification to define an Enum type. It is served as a convenient way to create an EnumTypeDefinition for creating an enum type.

func (*EnumConfig) NewResultCoercer

func (config *EnumConfig) NewResultCoercer(enum Enum) (EnumResultCoercer, error)

NewResultCoercer implments EnumTypeDefinition.

func (*EnumConfig) TypeData

func (config *EnumConfig) TypeData() EnumTypeData

TypeData implements EnumTypeDefinition.

type EnumResultCoercer

type EnumResultCoercer interface {
	// Given a result value of execution, it finds corresponding enum value from the given enum that
	// represents it.
	Coerce(value interface{}) (EnumValue, error)
}

EnumResultCoercer implements serialization for an Enum type. See comments for Coerce function.

type EnumResultCoercerFactory

type EnumResultCoercerFactory interface {
	// Create is called at the end of NewEnum when Enum is "almost" initialized to obtains an
	// EnumResultCoercer for serializing result value.
	Create(enum Enum) (EnumResultCoercer, error)
}

EnumResultCoercerFactory creates EnumResultCoercer for an initialized Enum.

func DefaultEnumResultCoercerFactory

func DefaultEnumResultCoercerFactory(lookupStrategy DefaultEnumResultCoercerLookupStrategy) EnumResultCoercerFactory

DefaultEnumResultCoercerFactory exposes factory to create a defaultEnumResultCoercer.

type EnumTypeData

type EnumTypeData struct {
	// The name of the Enum type
	Name string

	// Description of the Enum type
	Description string

	// Values to be defined in the Enum type
	Values EnumValueDefinitionMap
}

EnumTypeData contains type data for Enum.

type EnumTypeDefinition

type EnumTypeDefinition interface {
	TypeDefinition

	// TypeData reads data from the definition for the defining enum.
	TypeData() EnumTypeData

	// NewResultCoercer creates a EnumResultCoercer instance for the defining Enum type object during
	// its initialization.
	NewResultCoercer(enum Enum) (EnumResultCoercer, error)
}

EnumTypeDefinition provides data accessors that are required for defining a Enum.

type EnumValue

type EnumValue interface {
	// Name of enum value.
	Name() string

	// Description of the enum value
	Description() string

	// Value returns the internal value to be used when the enum value is read from input.
	Value() interface{}

	// Deprecation is non-nil when the value is tagged as deprecated.
	Deprecation() *Deprecation
}

EnumValue provides definition for a value in enum.

Reference: https://graphql.github.io/graphql-spec/June2018/#EnumValue

type EnumValueDefinition

type EnumValueDefinition struct {
	// Description of the enum value
	Description string

	// Value contains an internal value to represent the enum value. If omitted, the value will be set
	// to the name of enum value.
	Value interface{}

	// Deprecation is non-nil when the value is tagged as deprecated.
	Deprecation *Deprecation
}

EnumValueDefinition provides definition to an enum value.

type EnumValueDefinitionMap

type EnumValueDefinitionMap map[string]EnumValueDefinition

EnumValueDefinitionMap maps enum name to its value definition.

type EnumValueMap

type EnumValueMap map[string]EnumValue

EnumValueMap maps enum value names to their corresponding value definitions in an enum type.

func (EnumValueMap) Lookup

func (m EnumValueMap) Lookup(name string) EnumValue

Lookup finds the enum value with given name or return nil if there's no such one.

type ErrKind

type ErrKind uint8

ErrKind defines the kind of error this is.

const (
	ErrKindOther      ErrKind = iota // Unclassified error. This value is not printed in the error message.
	ErrKindCoercion                  // Failed to cerce input or result values for desired GraphQL type.
	ErrKindSyntax                    // Represent a syntax error in the GraphQL source.
	ErrKindValidation                // Represent an error occurred when validating schema.
	ErrKindExecution                 // Represent an error occurred when executing a query.
	ErrKindInternal                  // Internal error
)

Enumeration of Kind

func (ErrKind) String

func (k ErrKind) String() string

type Error

type Error struct {
	// Message describes the error for debugging purposes. It is required by a GraphQL Error as per
	// spec..
	Message string

	// Locations is an array of { line, column } locations within the source GraphQL document which
	// correspond to this error. It should be included if an error can be associated to a particular
	// point in the requested GraphQL document as per spec..
	//
	// Errors during validation often contain multiple locations, for example to point out two things
	// with the same name. Errors during execution include a single location, the field which produced
	// the error.
	Locations []ErrorLocation

	// Path describes the path of the response field which experienced the error. It should be
	// presented when an error can be associated to a particular field in the GraphQL result as per
	// spec.. Currently, it is only included for errors during execution. See example in [0].
	//
	// [0]: https://graphql.github.io/graphql-spec/June2018/#example-90475
	Path ResponsePath

	// Extensions contains data to be added to in the error response
	Extensions ErrorExtensions

	// The underlying error that triggered this one
	Err error

	// Op is the operation being performed, usually the name of the method being invoked.
	Op Op

	// Kind is the class of error
	Kind ErrKind
}

An Error describes an error found during parse, validate or execute phases of performing a GraphQL operation. It can be serialized to JSON for including in the response.

The Error is designed to contain the fields defined in the specification [0]. Furthermore, you can build an Error by wrapping an error value. Information (if unspecified in the arguments to NewError) in the error value will be propagated to the newly created Error. During the execution, the Error value is returned alone the execution path to the top, each intermediate function will either pass through the error to its caller or could wrap the error with further information, or even rewrite the error.

It also includes Op and ErrKind which will show when printing the error value. This makes it helpful for programmers.

[0] https://graphql.github.io/graphql-spec/June2018/#sec-Errors

func (*Error) Error

func (e *Error) Error() string

Error implements Go's error interface.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type ErrorExtensions

type ErrorExtensions map[string]interface{}

ErrorExtensions provides an additional entry to a GraphQL error with key "extensions". It is useful for attaching vendor-specific error data (such as error code).

Reference: https://github.com/facebook/graphql/pull/407

type ErrorLocation

type ErrorLocation struct {
	// Both line and column are positive numbers starting from 1
	Line   uint
	Column uint
}

ErrorLocation contains a line number and a column number to point out the beginning of an associated syntax element.

func ErrorLocationOfASTNode

func ErrorLocationOfASTNode(node ast.Node) ErrorLocation

ErrorLocationOfASTNode formats location of an AST node into an ErrorLocation.

type ErrorWithASTNodes

type ErrorWithASTNodes struct {
	Nodes []ast.Node
}

ErrorWithASTNodes is a utility base which implements ErrorWithLocations by querying location information from ast.Node's.

func (ErrorWithASTNodes) Locations

func (err ErrorWithASTNodes) Locations() []ErrorLocation

Locations implements ErrorWithLocations.

type ErrorWithExtensions

type ErrorWithExtensions interface {
	Extensions() ErrorExtensions
}

ErrorWithExtensions indicates an error that contains extensions data. If "extensions" is not given in the arguments to NewError, NewError will retrieve the one from the underlying error (if provided) that implements this interface.

type ErrorWithLocations

type ErrorWithLocations interface {
	Locations() []ErrorLocation
}

ErrorWithLocations indicates an error that contains locations. If "locations" is not given in the arguments to NewError, NewError will retrieve one from the underlying error (if provided) that implements this interface.

type ErrorWithPath

type ErrorWithPath interface {
	Path() ResponsePath
}

ErrorWithPath indicates an error that contains a path for reporting. If "path" is not given in the arguments to NewError, NewError will retrieve the one from the underlying error (if provided) that implements this interface.

type Errors

type Errors struct {
	Errors []*Error
}

Errors wraps a list of Error. Intentionally wrapped in a struct instead of a simple alias to []*Error (i.e., "type Errors []*Error") to enforce error checks to use errs.HaveOccurred() instead of (errs != nil) (errs may be an empty array which should be treat as no error).

func ErrorsOf

func ErrorsOf(args ...interface{}) Errors

ErrorsOf is an utility function to constructs an Errors value. It takes arguments in one of the form otherwise it panics:

  1. An array of *graphql.Error's; or
  2. Arguments that can be taken by NewError to construct an Error value; That is, a string specified the error message followed by other error context (e.g., locations).
  3. An array of *graphql.Error's followed by arguments that can be taken by NewError.

This is useful for use in construct-and-return. For example,

func SomethingMightFail() graphql.Errors {
	...

	// Something wrong; Construct an error and return it.
	return nil, graphql.ErrorsOf("something wrong")
}

func NoErrors

func NoErrors() Errors

NoErrors constructs an empty Errors.

func (*Errors) Append

func (errs *Errors) Append(e ...error)

Append appends list of Error's to the end of the Errors. Note that the given error must be an graphql.Error otherwise it panics. The update is occurred in-place to the given Errors.

func (*Errors) AppendErrors

func (errs *Errors) AppendErrors(e ...Errors)

AppendErrors takes a list of Errors's and pulls every Error in each Errors to append to "errs". The update is occurred in-place to the given Errors.

func (*Errors) Emplace

func (errs *Errors) Emplace(message string, args ...interface{})

Emplace constructs an Error from arguments and append to the errs. (We borrowed the name from C++'s std::list::emaplce.) It updates the list in the receiving Errors object (note about the pointer receiver). Note that it would panic if unsupported argument is supplied in args.

func (Errors) HaveOccurred

func (errs Errors) HaveOccurred() bool

HaveOccurred returns true if some errors exist. Use this instead of relying on "errs != nil" for checking existence of error because errs may be an empty array.

func (Errors) MarshalJSON

func (errs Errors) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type Field

type Field interface {
	// Name of the field
	Name() string

	// Description of the field
	Description() string

	// Type of value yielded by the field
	Type() Type

	// Args specifies the definitions of arguments being taken when querying this field.
	Args() []Argument

	// Resolver determines the result value for the field from the value resolved by parent Object.
	//
	// Reference: https://graphql.github.io/graphql-spec/June2018/#ResolveFieldValue()
	Resolver() FieldResolver

	// Deprecation is non-nil when the field is tagged as deprecated.
	Deprecation() *Deprecation
}

Field representing a field in an object or an interface. It yields a value of a specific type.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Objects

func SchemaMetaFieldDef

func SchemaMetaFieldDef() Field

SchemaMetaFieldDef returns the field that is used to introspect schema.

func TypeMetaFieldDef

func TypeMetaFieldDef() Field

TypeMetaFieldDef returns the field that is used to introspect type definition.

func TypenameMetaFieldDef

func TypenameMetaFieldDef() Field

TypenameMetaFieldDef returns the field that is used to introspect type name.

type FieldConfig

type FieldConfig struct {
	// Description of the defining field
	Description string

	// TypeDefinition instance of the defining field; It will be resolved during type initialization.
	Type TypeDefinition

	// Argument configuration of the field
	Args ArgumentConfigMap

	// Resolver for resolving field value during execution
	Resolver FieldResolver

	// Deprecation is non-nil when the value is tagged as deprecated.
	Deprecation *Deprecation
}

FieldConfig provides definition of a field when defining an object.

type FieldMap

type FieldMap map[string]Field

FieldMap maps field name to the Field.

func BuildFieldMap

func BuildFieldMap(fieldConfigMap Fields, typeDefResolver typeDefinitionResolver) (FieldMap, error)

BuildFieldMap builds a FieldMap from given Fields.

type FieldResolver

type FieldResolver interface {
	// Context carries deadlines and cancelation signals.
	//
	// Source is the "source" value. It contains the value that has been resolved by field's enclosing
	// object.
	//
	// Info contains a collection of information about the current execution state.
	Resolve(ctx context.Context, source interface{}, info ResolveInfo) (interface{}, error)
}

FieldResolver resolves field value during execution.

Reference: https://graphql.github.io/graphql-spec/June2018/#ResolveFieldValue()

type FieldResolverFunc

type FieldResolverFunc func(ctx context.Context, source interface{}, info ResolveInfo) (interface{}, error)

FieldResolverFunc is an adapter to allow the use of ordinary functions as FieldResolver.

func (FieldResolverFunc) Resolve

func (f FieldResolverFunc) Resolve(
	ctx context.Context,
	source interface{},
	info ResolveInfo) (interface{}, error)

Resolve calls f(ctx, source, info).

type FieldSelectionInfo

type FieldSelectionInfo interface {
	// A link to the parent field whose selection set contains this field selection
	Parent() FieldSelectionInfo

	// AST definition of the field; See comments in ResolveInfo.FieldDefinitions for more details.
	FieldDefinitions() []*ast.Field

	// The corresponding Field definition in Schema
	Field() Field

	// Argument values that are given to the field
	Args() ArgumentValues
}

FieldSelectionInfo is provided as part of ResolveInfo which contains the Selection [0] for the resolving field and its parent fields.

Reference: https://graphql.github.io/graphql-spec/June2018/#Field

type Fields

type Fields map[string]FieldConfig

Fields maps field name to its definition. In general, this should be named as "FieldConfigMap". However, this type is used frequently so we try to make it shorter to save some typing efforts. Unfortunately we cannot offer FieldConfig as Field because the name is used for representing fields within Object and Interface types.

type InputField

type InputField interface {
	// Name of the field
	Name() string

	// Description of the field
	Description() string

	// Type of value yielded by the field
	Type() Type

	// HasDefaultValue returns true if the input field has a default value. Calling DefaultValue when
	// this returns false results an undefined behavior.
	HasDefaultValue() bool

	// DefaultValue specified the value to be assigned to the field when no input is provided.
	DefaultValue() interface{}
}

InputField defines a field in an InputObject. It is much simpler than Field because it doesn't resolve value nor can have arguments.

type InputFieldDefinition

type InputFieldDefinition struct {
	// Description of the field
	Description string

	// Type of value given to this field
	Type TypeDefinition

	// DefaultValue specified the value to be assigned to the field when no input is provided.
	DefaultValue interface{}
}

InputFieldDefinition contains definition for defining a field in an Input Object type.

type InputFieldMap

type InputFieldMap map[string]InputField

InputFieldMap maps field name to the field definition in an Input Object type.

func BuildInputFieldMap

func BuildInputFieldMap(inputFieldDefMap InputFields, typeDefResolver typeDefinitionResolver) (InputFieldMap, error)

BuildInputFieldMap builds an InputFieldMap from given InputFields.

type InputFields

type InputFields map[string]InputFieldDefinition

InputFields maps field name to its definition for defining an InputField. It should be "InputFieldDefinitionMap" but is shorten to save some typing efforts.

type InputObject

type InputObject interface {
	Type
	TypeWithName
	TypeWithDescription

	Fields() InputFieldMap
	// contains filtered or unexported methods
}

InputObject Type Definition

An input object defines a structured collection of fields which may be supplied to a field argument. It is essentially an Object type but with some contraints on the fields so it can be used as an input argument. More specifically, fields in an Input Object type cannot define arguments or contain references to interfaces and unions.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Input-Objects

func MustNewInputObject

func MustNewInputObject(typeDef InputObjectTypeDefinition) InputObject

MustNewInputObject is a convenience function equivalent to NewInputObject but panics on failure instead of returning an error.

func NewInputObject

func NewInputObject(typeDef InputObjectTypeDefinition) (InputObject, error)

NewInputObject defines a InputObject type from a InputObjectTypeDefinition.

type InputObjectConfig

type InputObjectConfig struct {
	ThisIsTypeDefinition

	// Name of the defining InputObject
	Name string

	// Description for the InputObject type
	Description string

	// Fields to be defined in the InputObject Type
	Fields InputFields
}

InputObjectConfig provides specification to define a InputObject type. It is served as a convenient way to create a InputObjectTypeDefinition for creating an input object type.

func (*InputObjectConfig) TypeData

func (config *InputObjectConfig) TypeData() InputObjectTypeData

TypeData implements InputObjectTypeDefinition.

type InputObjectTypeData

type InputObjectTypeData struct {
	// The name of the Input Object type
	Name string

	// Description of the Input Object type
	Description string

	// Fields in the InputObject Type
	Fields InputFields
}

InputObjectTypeData contains type data for InputObject.

type InputObjectTypeDefinition

type InputObjectTypeDefinition interface {
	TypeDefinition

	// TypeData reads data from the definition for the defining enum.
	TypeData() InputObjectTypeData
}

InputObjectTypeDefinition provides data accessors that are required for defining a InputObject.

type Interface

type Interface interface {
	AbstractType

	// Fields returns set of fields that needs to be provided when implementing this interface.
	Fields() FieldMap
	// contains filtered or unexported methods
}

Interface Type Definition

When a field can return one of a heterogeneous set of types, a Interface type is used to describe what types are possible, what fields are in common across all types, as well as a function to determine which type is actually used when the field is resolved.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Interfaces

func MustNewInterface

func MustNewInterface(typeDef InterfaceTypeDefinition) Interface

MustNewInterface is a convenience function equivalent to NewInterface but panics on failure instead of returning an error.

func NewInterface

func NewInterface(typeDef InterfaceTypeDefinition) (Interface, error)

NewInterface initializes an instance of "iface".

type InterfaceConfig

type InterfaceConfig struct {
	ThisIsTypeDefinition

	// Name of the defining Interface
	Name string

	// Description for the Interface type
	Description string

	// TypeResolver resolves the concrete Object type implementing the defining interface from given
	// value.
	TypeResolver TypeResolver

	// Fields in the Interface Type
	Fields Fields
}

InterfaceConfig provides specification to define a Interface type. It is served as a convenient way to create a InterfaceTypeDefinition for creating an interface type.

func (*InterfaceConfig) NewTypeResolver

func (config *InterfaceConfig) NewTypeResolver(iface Interface) (TypeResolver, error)

NewTypeResolver implments InterfaceTypeDefinition.

func (*InterfaceConfig) TypeData

func (config *InterfaceConfig) TypeData() InterfaceTypeData

TypeData implements InterfaceTypeDefinition.

type InterfaceTypeData

type InterfaceTypeData struct {
	// The name of the Interface type
	Name string

	// Description of the Interface type
	Description string

	// Fields in the Interface Type
	Fields Fields
}

InterfaceTypeData contains type data for Interface.

type InterfaceTypeDefinition

type InterfaceTypeDefinition interface {
	TypeDefinition

	// TypeData reads data from the definition for the defining enum.
	TypeData() InterfaceTypeData

	// NewTypeResolver creates a TypeResolver instance for the defining Interface during its
	// initialization.
	NewTypeResolver(iface Interface) (TypeResolver, error)
}

InterfaceTypeDefinition provides data accessors that are required for defining a Interface.

func I

I is similar to T but convert an InterfaceType into InterfaceTypeDefinition.

type Iterable

type Iterable interface {
	// Iterator returns iterator to loop over its values.
	Iterator() Iterator
}

An Iterable defines iteration behavior. It is recognized by executor specially when it is presented to a field of a List type.

type Iterator

type Iterator interface {
	// Next returns the next value in iteration. It follows the semantics defined by iterator package
	// [0] which returns:
	//
	//  - (value, nil): return the next value in sequence.
	//  - (<ignored>, iterator.Done): the iterator is past the end of the iterated sequence.
	//  - (<ignored>, <error>): there's an error occurred when fetching the next value in sequence.
	//
	// [0]: github.com/botobag/artemis/iterator
	Next() (interface{}, error)
}

Iterator defines a way to access values in an Iterable.

type LeafType

type LeafType interface {
	Type
	TypeWithName
	TypeWithDescription

	// CoerceResultValue coerces the given value to be returned as result of field with the type.
	CoerceResultValue(value interface{}) (interface{}, error)
	// contains filtered or unexported methods
}

LeafType can represent a leaf value where execution of the GraphQL hierarchical queries terminates. Currently only Scalar and Enum are valid types for leaf nodes in GraphQL. See 0 and 1.

type List

type List interface {
	WrappingType

	// ElementType indicates the the type of the elements in the list.
	ElementType() Type
	// contains filtered or unexported methods
}

List Type Modifier

A list is a wrapping type which points to another type. Lists are often created within the context of defining the fields of an object type.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Type-System.List

func MustNewList

func MustNewList(typeDef ListTypeDefinition) List

MustNewList is a convenience function equivalent to NewList but panics on failure instead of returning an error.

func MustNewListOf

func MustNewListOf(elementTypeDef TypeDefinition) List

MustNewListOf is a panic-on-fail version of NewListOf.

func MustNewListOfType

func MustNewListOfType(elementType Type) List

MustNewListOfType is a panic-on-fail version of NewListOfType.

func NewList

func NewList(typeDef ListTypeDefinition) (List, error)

NewList defines a List type from a ListTypeDefinition.

func NewListOf

func NewListOf(elementTypeDef TypeDefinition) (List, error)

NewListOf defines a List type from a given TypeDefinition of element type.

func NewListOfType

func NewListOfType(elementType Type) (List, error)

NewListOfType defines a List type from a given Type of element type.

type ListTypeDefinition

type ListTypeDefinition interface {
	TypeDefinition

	// ElementType specifies the type being wrapped in the List type.
	ElementType() TypeDefinition
}

ListTypeDefinition provides data accessors that are required for defining a List.

func ListOf

func ListOf(elementTypeDef TypeDefinition) ListTypeDefinition

ListOf returns a ListTypeDefinition with the given TypeDefinition of element type.

func ListOfType

func ListOfType(elementType Type) ListTypeDefinition

ListOfType returns a ListTypeDefinition with the given Type of element type.

type MapKeysIterable

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

MapKeysIterable wraps a Go map into an Iterable and provides an iterator to loop over keys in the map. Note that the given map should not be modified during iteration.

func NewMapKeysIterable

func NewMapKeysIterable(m interface{}) *MapKeysIterable

NewMapKeysIterable creates a MapKeysIterable. m must be a Go map.

func (*MapKeysIterable) Iterator

func (iterable *MapKeysIterable) Iterator() Iterator

Iterator implements Iterable. It returns iterator for iterating map keys.

func (*MapKeysIterable) Size

func (iterable *MapKeysIterable) Size() int

Size implements SizedIterable. It returns the number of entries in the map.

type MapKeysIterator

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

MapKeysIterator implements Iterator to loop over the keys in a map.

func NewMapKeysIterator

func NewMapKeysIterator(m interface{}) MapKeysIterator

NewMapKeysIterator creates a MapKeysIterator for given map.

func (MapKeysIterator) Next

func (iter MapKeysIterator) Next() (interface{}, error)

Next implements Iterator.

type MapValuesIterable

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

MapValuesIterable wraps a Go map into an Iterable and provides an iterator to loop over the values in the map. Note that the given map should not be modified during iteration.

func NewMapValuesIterable

func NewMapValuesIterable(m interface{}) *MapValuesIterable

NewMapValuesIterable creates a MapValuesIterable. m must be a Go map.

func (*MapValuesIterable) Iterator

func (iterable *MapValuesIterable) Iterator() Iterator

Iterator implements Iterable. It returns iterator for iterating map values.

func (*MapValuesIterable) Size

func (iterable *MapValuesIterable) Size() int

Size implements SizedIterable. It returns the number of entries in the map.

type MapValuesIterator

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

MapValuesIterator implements Iterator to loop over the values in a map.

func NewMapValuesIterator

func NewMapValuesIterator(m interface{}) MapValuesIterator

NewMapValuesIterator creates a MapValuesIterator for given map.

func (MapValuesIterator) Next

func (iter MapValuesIterator) Next() (interface{}, error)

Next implements Iterator.

type NonNull

type NonNull interface {
	WrappingType

	// InnerType indicates the type of the element wrapped in this non-null type.
	InnerType() Type
	// contains filtered or unexported methods
}

NonNull Type Modifier

A non-null is a wrapping type which points to another type. Non-null types enforce that their values are never null and can ensure an error is raised if this ever occurs during a request. It is useful for fields which you can make a strong guarantee on non-nullability, for example usually the id field of a database row will never be null.

Note: the enforcement of non-nullability occurs within the executor.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Type-System.Non-Null

func MustNewNonNull

func MustNewNonNull(typeDef NonNullTypeDefinition) NonNull

MustNewNonNull is a convenience function equivalent to NewNonNull but panics on failure instead of returning an error.

func MustNewNonNullOf

func MustNewNonNullOf(elementTypeDef TypeDefinition) NonNull

MustNewNonNullOf is a panic-on-fail version of NewNonNullOf.

func MustNewNonNullOfType

func MustNewNonNullOfType(elementType Type) NonNull

MustNewNonNullOfType is a panic-on-fail version of NewNonNullOfType.

func NewNonNull

func NewNonNull(typeDef NonNullTypeDefinition) (NonNull, error)

NewNonNull defines a NonNull type from a NonNullTypeDefinition.

func NewNonNullOf

func NewNonNullOf(elementTypeDef TypeDefinition) (NonNull, error)

NewNonNullOf defines a NonNull type from a given TypeDefinition of element type.

func NewNonNullOfType

func NewNonNullOfType(elementType Type) (NonNull, error)

NewNonNullOfType defines a NonNull type from a given Type of element type.

type NonNullTypeDefinition

type NonNullTypeDefinition interface {
	TypeDefinition

	// InnerType specifies the type being wrapped in the NonNull type.
	InnerType() TypeDefinition
}

NonNullTypeDefinition provides data accessors that are required for defining a NonNull.

func NonNullOf

func NonNullOf(elementTypeDef TypeDefinition) NonNullTypeDefinition

NonNullOf returns a NonNullTypeDefinition with the given TypeDefinition of element type.

func NonNullOfType

func NonNullOfType(elementType Type) NonNullTypeDefinition

NonNullOfType returns a NonNullTypeDefinition with the given Type of element type.

type Object

type Object interface {
	Type
	TypeWithName
	TypeWithDescription

	// Fields in the object
	Fields() FieldMap

	// Interfaces includes interfaces that implemented by the Object type.
	Interfaces() []Interface
	// contains filtered or unexported methods
}

Object Type Definition

GraphQL queries are hierarchical and composed, describing a tree of information. While Scalar types describe the leaf values of these hierarchical queries, Objects describe the intermediate levels.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Objects

func MustNewObject

func MustNewObject(typeDef ObjectTypeDefinition) Object

MustNewObject is a convenience function equivalent to NewObject but panics on failure instead of returning an error.

func NewObject

func NewObject(typeDef ObjectTypeDefinition) (Object, error)

NewObject defines an Object type from a ObjectTypeDefinition.

type ObjectConfig

type ObjectConfig struct {
	ThisIsTypeDefinition

	// Name of the defining Object
	Name string

	// Description for the Object type
	Description string

	// Interfaces that implemented by the defining Object
	Interfaces []InterfaceTypeDefinition

	// Fields in the object
	Fields Fields
}

ObjectConfig provides specification to define a Object type. It is served as a convenient way to create a ObjectTypeDefinition for creating an object type.

func (*ObjectConfig) TypeData

func (config *ObjectConfig) TypeData() ObjectTypeData

TypeData implements ObjectTypeDefinition.

type ObjectTypeData

type ObjectTypeData struct {
	// The name of the Object type
	Name string

	// Description of the Object type
	Description string

	// Interfaces that implemented by the defining Object
	Interfaces []InterfaceTypeDefinition

	// Fields in the Object Type
	Fields Fields
}

ObjectTypeData contains type data for Object.

type ObjectTypeDefinition

type ObjectTypeDefinition interface {
	TypeDefinition

	// TypeData reads data from the definition for the defining enum.
	TypeData() ObjectTypeData
}

ObjectTypeDefinition provides data accessors that are required for defining a Object.

type Op

type Op string

Op describes an operation, usually as the package and method, such as "language/parser.Parse".

type PossibleTypeSet

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

PossibleTypeSet stores possible types for an abstract type (could be either an Interface or an Union) in a schema.

func NewPossibleTypeSet

func NewPossibleTypeSet() PossibleTypeSet

NewPossibleTypeSet creates an empty PossibleTypeSet.

func (PossibleTypeSet) Add

func (set PossibleTypeSet) Add(o Object)

Add adds a type to the set.

func (PossibleTypeSet) Contains

func (set PossibleTypeSet) Contains(o Object) bool

Contains returns true if the given Object type is the possible types of the abstract type associated with the set.

func (PossibleTypeSet) DoesIntersect

func (set PossibleTypeSet) DoesIntersect(other PossibleTypeSet) bool

DoesIntersect returns true if there is any intersect between set and the given one.

func (PossibleTypeSet) Empty

func (set PossibleTypeSet) Empty() bool

Empty returns true if there's no any possible types in the set.

func (PossibleTypeSet) Iterator

func (set PossibleTypeSet) Iterator() Iterator

Iterator returns iterator to loop over all types in the set.

type ResolveInfo

type ResolveInfo interface {

	// Schema of the type system that is currently executing.
	Schema() Schema

	// Document that contains definitions for the operation.
	Document() ast.Document

	// Definition of this operation
	Operation() *ast.OperationDefinition

	// DataLoaderManager that manages usage and dispatch of data loaders during execution.
	DataLoaderManager() DataLoaderManager

	// RootValue is an initial value corresponding to the root type being executed.
	RootValue() interface{}

	// AppContext contains an application-specific data. It is what you passed to
	// PreparedOperation.Execute via AppContext. It is commonly used to represent an authenticated
	// user, or request-specific caches.
	AppContext() interface{}

	// VariableValues contains values to the parameters in current query. The values has passed
	// through the input coercion.
	VariableValues() VariableValues

	// Link to the Selection that requests this field.
	ParentFieldSelection() FieldSelectionInfo

	// The Oject in which the Field belongs to
	Object() Object

	// AST definitions of the field that is being requested; Note that it is an array of ast.Field
	// because a field could e requested in a Selection Set multiple times (with the same
	// name/response key) with different or the same sub-selection set. For example:
	//
	//	{
	//	  foo {
	//	    bar
	//	  }
	//
	//	  foo {
	//	    bar
	//	    baz
	//	  }
	//	}
	//
	// The above operation specifies "foo" two times which is valid. FieldDefinitions will returns two
	// ast.Field each of which corresponding to one of "foo" in the query. The query result would
	// contain only one "foo" with all three fields merged in the field data.
	FieldDefinitions() []*ast.Field

	// The corresponding Field definition in Schema
	Field() Field

	// Path in the response to this field. This can be serialized to the "path" when there're errors
	// occurred on field. Note that this is created on request by traversing ResultNode and could be
	// expensive. Cache it if you want to it to be reusable.
	Path() ResponsePath

	// Argument values that are given to the field
	Args() ArgumentValues
}

ResolveInfo exposes a collection of information about execution state for resolvers.

type ResponsePath

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

ResponsePath is an array of "key" where each key is either a string (indicating the field name) or an integer (indicating an index to list.) It should be presented when an error can be assoc

func (*ResponsePath) AppendFieldName

func (path *ResponsePath) AppendFieldName(name string)

AppendFieldName adds a field name to the end of current path.

func (*ResponsePath) AppendIndex

func (path *ResponsePath) AppendIndex(index int)

AppendIndex adds a list index to the end of current path.

func (ResponsePath) Clone

func (path ResponsePath) Clone() ResponsePath

Clone makes a deep copy of the path.

func (ResponsePath) Empty

func (path ResponsePath) Empty() bool

Empty returns true if the path doesn't contain any path keys.

func (*ResponsePath) MarshalJSON

func (path *ResponsePath) MarshalJSON() ([]byte, error)

MarshalJSON serializes path keys to JSON.

func (ResponsePath) String

func (path ResponsePath) String() string

String serializes a ResponsePath to more readable format.

type Scalar

type Scalar interface {
	LeafType

	// CoerceVariableValue coerces values in input variables into eligible Go values for the scalar.
	CoerceVariableValue(value interface{}) (interface{}, error)

	// CoerceLiteralValue coerces values in field or directive argument into eligible Go values for
	// the scalar.
	CoerceLiteralValue(value ast.Value) (interface{}, error)
	// contains filtered or unexported methods
}

Scalar Type Definition

The leaf values of any request and input values to arguments are Scalars (or Enums) and are defined with a name and a series of functions used to parse input from ast or variables and to ensure validity.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Scalars

func Boolean

func Boolean() Scalar

Boolean returns the GraphQL builtin Boolean type definition.

func Float

func Float() Scalar

Float returns the GraphQL builtin Float type definition.

func ID

func ID() Scalar

ID returns the GraphQL builtin ID type definition.

func Int

func Int() Scalar

Int returns the GraphQL builtin Int type definition.

func MustNewScalar

func MustNewScalar(typeDef ScalarTypeDefinition) Scalar

MustNewScalar is a convenience function equivalent to NewScalar but panics on failure instead of returning an error.

func NewScalar

func NewScalar(typeDef ScalarTypeDefinition) (Scalar, error)

NewScalar defines a scalar type from a ScalarTypeDefinition.

func String

func String() Scalar

String returns the GraphQL builtin String type definition.

type ScalarAlias

type ScalarAlias interface {
	// A ScalarAlias behaves like the Scalar being aliased to.
	Scalar

	// AliasFor describes the Scalar that is aliased by this type.
	AliasFor() Scalar
}

ScalarAlias builds a custom coercion on top of a Scalar type. It looks and works like an ordinary Scalar type. In schema, the type is still represented by the aliasing Scalar but behind the scenes values to these types are coerced in the ways defined by the ScalarAlias types. Typical use cases for ScalarAlias include:

  1. Add a validation on top of a Scalar, such as constrain an Int to be positive;

  2. Transform into different type of internal value, for example, to use a custom UUID type in Go for values represented by the built-in ID.

The brilliant idea is borrowed from Scalar Type Alias 0 in Sangria 1.

func MustNewScalarAlias

func MustNewScalarAlias(typeDef ScalarAliasTypeDefinition) ScalarAlias

MustNewScalarAlias is a convenience function equivalent to NewScalarAlias but panics on failure instead of returning an error.

func NewScalarAlias

func NewScalarAlias(typeDef ScalarAliasTypeDefinition) (ScalarAlias, error)

NewScalarAlias defines a scalar type from a ScalarAliasTypeDefinition.

type ScalarAliasConfig

type ScalarAliasConfig struct {
	ThisIsTypeDefinition

	AliasFor Scalar

	// ResultCoercer serializes value for return in execution result. If omitted, the newly created
	// ScalarAlias will apply result coercion as its aliasing Scalar.
	ResultCoercer ScalarResultCoercer

	// InputCoercer parses input value given to the scalar field. If omitted, the newly created
	// ScalarAlias will apply input coercion as its aliasing Scalar.
	InputCoercer ScalarInputCoercer
}

ScalarAliasConfig provides specification to define a scalar type. It is served as a convenient way to create a ScalarAliasTypeDefinition for creating a scalar type.

func (*ScalarAliasConfig) NewInputCoercer

func (config *ScalarAliasConfig) NewInputCoercer(alias ScalarAlias) (ScalarInputCoercer, error)

NewInputCoercer implments ScalarAliasTypeDefinition.

func (*ScalarAliasConfig) NewResultCoercer

func (config *ScalarAliasConfig) NewResultCoercer(alias ScalarAlias) (ScalarResultCoercer, error)

NewResultCoercer implments ScalarAliasTypeDefinition.

func (*ScalarAliasConfig) TypeData

func (config *ScalarAliasConfig) TypeData() ScalarAliasTypeData

TypeData implements ScalarAliasTypeDefinition.

type ScalarAliasTypeData

type ScalarAliasTypeData struct {
	// The Scalar type being aliased to. Note that we take Scalar instead of ScalarTypeDefinition here
	// for convenience.
	AliasFor Scalar
}

ScalarAliasTypeData contains type data for ScalarAlias.

type ScalarAliasTypeDefinition

type ScalarAliasTypeDefinition interface {
	TypeDefinition

	// TypeData reads data from the definition for the defining scalar type alias.
	TypeData() ScalarAliasTypeData

	// NewResultCoercer creates a ScalarAliasResultCoercer instance for the defining ScalarAlias type
	// object during its initialization.
	NewResultCoercer(scalar ScalarAlias) (ScalarResultCoercer, error)

	// NewInputCoercer creates an ScalarAliasInputCoercer instance for the defining ScalarAlias type
	// object during its initialization.
	NewInputCoercer(scalar ScalarAlias) (ScalarInputCoercer, error)
}

ScalarAliasTypeDefinition provides data accessors that are required for defining a ScalarAlias.

type ScalarConfig

type ScalarConfig struct {
	ThisIsTypeDefinition

	// Name of the scalar type
	Name string

	// Description of the scalar type
	Description string

	// ResultCoercer serializes value for return in execution result
	ResultCoercer ScalarResultCoercer

	// InputCoercer parses input value given to the scalar field (optional)
	InputCoercer ScalarInputCoercer
}

ScalarConfig provides specification to define a scalar type. It is served as a convenient way to create a ScalarTypeDefinition for creating a scalar type.

func (*ScalarConfig) NewInputCoercer

func (config *ScalarConfig) NewInputCoercer(scalar Scalar) (ScalarInputCoercer, error)

NewInputCoercer implments ScalarTypeDefinition.

func (*ScalarConfig) NewResultCoercer

func (config *ScalarConfig) NewResultCoercer(scalar Scalar) (ScalarResultCoercer, error)

NewResultCoercer implments ScalarTypeDefinition.

func (*ScalarConfig) TypeData

func (config *ScalarConfig) TypeData() ScalarTypeData

TypeData implements ScalarTypeDefinition.

type ScalarInputCoercer

type ScalarInputCoercer interface {
	// CoerceVariableValue coerces a scalar value in input query variables [0].
	//
	// [0]: https://graphql.github.io/graphql-spec/June2018/#CoerceVariableValues()
	CoerceVariableValue(value interface{}) (interface{}, error)

	// CoerceLiteralValue coerces a scalar value in input field arguments [0].
	//
	// [0]: https://graphql.github.io/graphql-spec/June2018/#CoerceLiteralValues()
	CoerceLiteralValue(value ast.Value) (interface{}, error)
}

ScalarInputCoercer coerces input values in the GraphQL requests into a value represented the Scalar type. Please read "Input Coercion" in 0 to provide appropriate implementation.

type ScalarInputCoercerFuncs

type ScalarInputCoercerFuncs struct {
	CoerceVariableValueFunc func(value interface{}) (interface{}, error)
	CoerceLiteralValueFunc  func(value ast.Value) (interface{}, error)
}

ScalarInputCoercerFuncs is an adapter to create a ScalarInputCoercer from function values.

func (ScalarInputCoercerFuncs) CoerceLiteralValue

func (f ScalarInputCoercerFuncs) CoerceLiteralValue(value ast.Value) (interface{}, error)

CoerceLiteralValue calls f.CoerceLiteralValueFunc(value).

func (ScalarInputCoercerFuncs) CoerceVariableValue

func (f ScalarInputCoercerFuncs) CoerceVariableValue(value interface{}) (interface{}, error)

CoerceVariableValue calls f.CoerceVariableValueFunc(value).

type ScalarResultCoercer

type ScalarResultCoercer interface {
	// CoerceResultValue coerces the given value for the field to return. It is called in
	// CompleteValue() [0] as per spec.
	//
	// [0]: https://graphql.github.io/graphql-spec/June2018/#CompleteValue()
	CoerceResultValue(value interface{}) (interface{}, error)
}

ScalarResultCoercer coerces result value into a value represented in the Scalar type. Please read "Result Coercion" in 0 to provide appropriate implementation.

type ScalarResultCoercerFunc

type ScalarResultCoercerFunc func(value interface{}) (interface{}, error)

ScalarResultCoercerFunc is an adapter to allow the use of ordinary functions as ScalarResultCoercer.

func (ScalarResultCoercerFunc) CoerceResultValue

func (f ScalarResultCoercerFunc) CoerceResultValue(value interface{}) (interface{}, error)

CoerceResultValue calls f(value).

type ScalarTypeData

type ScalarTypeData struct {
	// The name of the Scalar type
	Name string

	// Description of the Scalar type
	Description string
}

ScalarTypeData contains type data for Scalar.

type ScalarTypeDefinition

type ScalarTypeDefinition interface {
	TypeDefinition

	// TypeData reads data from the definition for the defining scalar.
	TypeData() ScalarTypeData

	// NewResultCoercer creates a ScalarResultCoercer instance for the defining Scalar type object
	// during its initialization.
	NewResultCoercer(scalar Scalar) (ScalarResultCoercer, error)

	// NewInputCoercer creates an ScalarInputCoercer instance for the defining Scalar type object
	// during its initialization.
	NewInputCoercer(scalar Scalar) (ScalarInputCoercer, error)
}

ScalarTypeDefinition provides data accessors that are required for defining a Scalar.

type Schema

type Schema interface {
	// TypeMap keeps track of all named types referenced within the schema.
	TypeMap() TypeMap

	// Directives keeps track of all valid directives within the schema.
	Directives() DirectiveList

	// The following provides root operation types defined in a GraphQL schema.
	//
	// Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Root-Operation-Types
	Query() Object
	Mutation() Object
	Subscription() Object

	// PossibleTypes returns set of possible concrete types for the given abstract type in the schema.
	// For Interface, this contains the list of Object types that implement it. For Union, this
	// contains the list of its member types.
	PossibleTypes(t AbstractType) PossibleTypeSet

	// TypeFromAST returns a graphql.Type that applies to the ast.Type in the given schema For
	// example, if provided the parsed AST node for `[User]`, a graphql.List instance will be
	// returned, containing the type called "User" found in the schema. If a type called "User" is not
	// found in the schema, then nil will be returned.
	TypeFromAST(t ast.Type) Type
}

Schema states the requirements of a schema object that other components such as execution engine depends on.

A GraphQL service’s collective type system capabilities are referred to as that service’s “schema”. A schema is defined in terms of the types and directives it supports as well as the root operation types for each kind of operation: query, mutation, and subscription; this determines the place in the type system where those operations begin.

Definitions including types and directives in schema are assumed to be immutable after creation. This allows us to cache the results for some operations such as PossibleTypes.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Schema

func MustNewSchema

func MustNewSchema(config *SchemaConfig) Schema

MustNewSchema is a convenience function equivalent to NewSchema but panics on failure instead of returning an error.

func NewSchema

func NewSchema(config *SchemaConfig) (Schema, error)

NewSchema initializes a Schema from the given config.

type SchemaConfig

type SchemaConfig struct {
	// Query, Mutation and Subscription returns GraphQL Root Operation defined by the schema.
	Query        Object
	Mutation     Object
	Subscription Object

	// List of types that are declared in the schema.
	Types []Type

	// List of directives to be added to the schema.
	Directives DirectiveList

	// If true, the standard directives such as @skip will not be incldued in the defining schema. The
	// directives provided in Directives will be the exact list of directives represented and allowed.
	ExcludeStandardDirectives bool
}

SchemaConfig contains configuration to define a GraphQL schema.

type SizedIterable

type SizedIterable interface {
	Iterable

	// Size provides hint about number of values in the sequence.
	Size() int
}

SizedIterable provides hint about size of iterable.

type ThisIsEnumType

type ThisIsEnumType struct{}

ThisIsEnumType is required to be embedded in struct that intends to be a Enum.

type ThisIsInputObjectType

type ThisIsInputObjectType struct{}

ThisIsInputObjectType is required to be embedded in struct that intends to be a InputObject.

type ThisIsInterfaceType

type ThisIsInterfaceType struct{}

ThisIsInterfaceType is required to be embedded in struct that intends to be an Interface.

type ThisIsListType

type ThisIsListType struct{}

ThisIsListType is required to be embedded in struct that intends to be a List.

type ThisIsNonNullType

type ThisIsNonNullType struct{}

ThisIsNonNullType is required to be embedded in struct that intends to be a NonNull.

type ThisIsObjectType

type ThisIsObjectType struct{}

ThisIsObjectType is required to be embedded in struct that intends to be an Object.

type ThisIsScalarType

type ThisIsScalarType struct{}

ThisIsScalarType is required to be embedded in struct that intends to be a Scalar.

type ThisIsTypeDefinition

type ThisIsTypeDefinition struct{}

ThisIsTypeDefinition is a marker struct intended to be embedded in every TypeDefinition implementation

func (ThisIsTypeDefinition) ThisIsGraphQLTypeDefinition

func (ThisIsTypeDefinition) ThisIsGraphQLTypeDefinition()

ThisIsGraphQLTypeDefinition implements ThisIsGraphQLTypeDefinition.

type ThisIsUnionType

type ThisIsUnionType struct{}

ThisIsUnionType is required to be embedded in struct that intends to be an Union.

type Type

type Type interface {
	// contains filtered or unexported methods
}

Type interfaces provided by a GraphQL type.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Types

func NamedTypeOf

func NamedTypeOf(t Type) Type

NamedTypeOf returns the given type if it is a non-wrapping type. Otherwise, return the underlying type of a wrapping type.

Reference: https://graphql.github.io/graphql-spec/draft/#sec-Wrapping-Types

func NewType

func NewType(typeDef TypeDefinition) (Type, error)

NewType creates a Type instance given a TypeDefinition. When type is known, calling a more specific version is prefer. For example, if you know you're creating a Scalar, call NewScalar with ScalarTypeDefinition.

func NullableTypeOf

func NullableTypeOf(t Type) Type

NullableTypeOf return the given type if it is not a non-null type. Otherwise, return the inner type of the non-null type.

type TypeDefinition

type TypeDefinition interface {
	// ThisIsGraphQLTypeDefinition puts a special mark for a TypeDefinition objects.
	ThisIsGraphQLTypeDefinition()
}

TypeDefinition defines interfaces that are provided by all TypeDefinition variants. See the package documentation for more information.

func T

func T(t Type) TypeDefinition

T converts a Type into TypeDefinition. When a TypeDefinition depends on some types (e.g., Object depends on the types of its fields), it specifies corresponding TypeDefinition instances to reference dependent types. To accept Type, we create an internal pseudo-TypeDefinition that represent a Type instance and expose a function "T" to make create such TypeDefinition. The pseudo TypeDefinition is handled specially in NewType implementation.

type TypeMap

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

TypeMap keeps track of all named types referenced within the schema.

func (TypeMap) Iterator

func (typeMap TypeMap) Iterator() Iterator

Iterator returns iterator to loop over all types in type map.

func (TypeMap) KeyIterator

func (typeMap TypeMap) KeyIterator() Iterator

KeyIterator returns iterator to loop over all type names in type map.

func (TypeMap) Lookup

func (typeMap TypeMap) Lookup(name string) Type

Lookup finds a type with given name.

func (TypeMap) Size

func (typeMap TypeMap) Size() int

Size returns number of types in the map.

type TypeResolver

type TypeResolver interface {
	// Context carries deadlines and cancelation signals.
	//
	// Value is the value returning from the field resolver of the field with abstract type that is
	// being resolved. Usually you determine the concrete Object type based on the value.
	//
	// Info contains a collection of information about the current execution state.
	//
	// Reference: https://graphql.github.io/graphql-spec/June2018/#ResolveAbstractType()
	Resolve(ctx context.Context, value interface{}, info ResolveInfo) (Object, error)
}

TypeResolver resolves concrete type of an Interface from given value.

type TypeResolverFunc

type TypeResolverFunc func(ctx context.Context, value interface{}, info ResolveInfo) (Object, error)

TypeResolverFunc is an adapter to allow the use of ordinary functions as TypeResolver.

func (TypeResolverFunc) Resolve

func (f TypeResolverFunc) Resolve(ctx context.Context, value interface{}, info ResolveInfo) (Object, error)

Resolve calls f(ctx, value, info).

type TypeWithDescription

type TypeWithDescription interface {
	// Description provides documentation for the type.
	Description() string
}

TypeWithDescription is implemented by the types that provides description.

type TypeWithName

type TypeWithName interface {
	// Name of the defining type
	Name() string
}

TypeWithName is implemented by the type definition for named type.

type Union

type Union interface {
	AbstractType

	// Types returns member of the union type.
	PossibleTypes() PossibleTypeSet
	// contains filtered or unexported methods
}

Union Type Definition

When a field can return one of a heterogeneous set of types, a Union type is used to describe what types are possible as well as providing a function to determine which type is actually used when the field is resolved.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Unions

func MustNewUnion

func MustNewUnion(typeDef UnionTypeDefinition) Union

MustNewUnion is a convenience function equivalent to NewUnion but panics on failure instead of returning an error.

func NewUnion

func NewUnion(typeDef UnionTypeDefinition) (Union, error)

NewUnion initializes an instance of "union".

type UnionConfig

type UnionConfig struct {
	ThisIsTypeDefinition

	// Name of the defining Union
	Name string

	// Description for the Union type
	Description string

	// PossibleTypes describes which Object types can be represented by the defining union.
	PossibleTypes []ObjectTypeDefinition

	// TypeResolver resolves the concrete Object type implementing the defining interface from given
	// value.
	TypeResolver TypeResolver
}

UnionConfig provides specification to define a Union type. It is served as a convenient way to create a UnionTypeDefinition for creating a union type.

func (*UnionConfig) NewTypeResolver

func (config *UnionConfig) NewTypeResolver(union Union) (TypeResolver, error)

NewTypeResolver implments UnionTypeDefinition.

func (*UnionConfig) TypeData

func (config *UnionConfig) TypeData() UnionTypeData

TypeData implements UnionTypeDefinition.

type UnionTypeData

type UnionTypeData struct {
	// The name of the Union type
	Name string

	// Description of the Union type
	Description string

	// PossibleTypes describes which Object types can be represented by the defining union.
	PossibleTypes []ObjectTypeDefinition
}

UnionTypeData contains type data for Union.

type UnionTypeDefinition

type UnionTypeDefinition interface {
	TypeDefinition

	// TypeData reads data from the definition for the defining enum.
	TypeData() UnionTypeData

	// NewTypeResolver creates a TypeResolver instance for the defining Union during its
	// initialization.
	NewTypeResolver(union Union) (TypeResolver, error)
}

UnionTypeDefinition provides data accessors that are required for defining a Union.

type ValueWithCustomInspect

type ValueWithCustomInspect interface {
	Inspect(out io.Writer) error
}

ValueWithCustomInspect provides custom inspect function to serialize value in Inspect.

type VariableValues

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

VariableValues contains values for variables defined by the query. It is immutable after it is created.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Language.Variables

func NewVariableValues

func NewVariableValues(values map[string]interface{}) VariableValues

NewVariableValues creates an VariableValues from given values.

func NoVariableValues

func NoVariableValues() VariableValues

NoVariableValues represents an empty variable value set.

func (VariableValues) Get

func (vars VariableValues) Get(name string) interface{}

Get returns variable value for the given name. It returns nil if no such variable was found.

func (VariableValues) Lookup

func (vars VariableValues) Lookup(name string) (value interface{}, ok bool)

Lookup returns variable value for the given name. If variable with the given name doesn't exist, returns nil. The second value (ok) is a bool that is true if the variable exists, and false if not.

func (VariableValues) MarshalJSON

func (vars VariableValues) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler to serialize the internal map in VariableValues into JSON. This is primarily used by tests for verifying argument values.

type WrappingType

type WrappingType interface {
	Type

	// UnwrappedType returns the type that is wrapped by this type.
	UnwrappedType() Type
	// contains filtered or unexported methods
}

WrappingType is a type that wraps another type. There are two wrapping type in GraphQL: List and NonNull.

Reference: https://graphql.github.io/graphql-spec/draft/#sec-Wrapping-Types

Directories

Path Synopsis
ast
Package ast defines the types used to represent syntax trees for a GraphQL source.
Package ast defines the types used to represent syntax trees for a GraphQL source.
visitor
Package visitor implements AST traversal.
Package visitor implements AST traversal.
Package handler helps build GraphQL services.
Package handler helps build GraphQL services.
internal
Package lexer implements a lexer for tokenizing GraphQL source.
Package lexer implements a lexer for tokenizing GraphQL source.
Package parser implements a parser for GraphQL source.
Package parser implements a parser for GraphQL source.
Package token defines lexical tokens in GraphQL language.
Package token defines lexical tokens in GraphQL language.
util
ast

Jump to

Keyboard shortcuts

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