internal

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBasicType

func IsBasicType(typ Type) bool

func IsInputType

func IsInputType(typ Type) bool

func NewLexer

func NewLexer(source string, useStringDescriptions ...bool) *lexer

func ParseDocument

func ParseDocument(source string) (*ast.Document, *errors.GraphQLError)

func ParseType

func ParseType(l *lexer) ast.Type

*

  • Operation :
  • - NamedType
  • - ListType
  • - NonNullType

func ParseValueLiteral

func ParseValueLiteral(l *lexer, constOnly bool) ast.Value

*

  • Value[Const] :
  • - [~Const] Variable
  • - IntValue
  • - FloatValue
  • - StringValue
  • - BooleanValue
  • - EnumValue
  • - ListValue[?Const]
  • - ObjectValue[?Const] *
  • BooleanValue : one of `true` `false` *
  • EnumValue : Name but not `true`, `false` or `null`

func ValueToJson

func ValueToJson(value ast.Value, vars map[string]interface{}) (interface{}, *errors.GraphQLError)

Types

type Directive

type Directive struct {
	Name      string                 `json:"name"`
	Desc      string                 `json:"description"`
	Args      map[string]*InputField `json:"arguments"`
	ArgVals   map[string]interface{} `json:"-"`
	FnResolve DirectiveFn            `json:"-"`
	Locs      []string               `json:"locations"`
	Loc       errors.Location
}

type DirectiveFn

type DirectiveFn func(ctx context.Context, args interface{}, fieldFn FieldResolve, source interface{}, fieldArgs interface{}) (bool, interface{}, error)

type Document

type Document struct {
	Operations []*ast.OperationDefinition
	Fragments  []*ast.FragmentDefinition
}

func Parse

func Parse(source string) (*Document, error)

type Enum

type Enum struct {
	Name       string                 `json:"name"`
	Values     []string               `json:"values"`
	ValuesDesc map[string]string      `json:"-"`
	ReverseMap map[string]interface{} `json:"-"`
	Map        map[interface{}]string `json:"-"`
	Desc       string                 `json:"description"`
}

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.

func (*Enum) Description

func (t *Enum) Description() string

func (*Enum) IsType

func (t *Enum) IsType()

func (*Enum) String

func (t *Enum) String() string

func (*Enum) TypeName

func (t *Enum) TypeName() string

type Field

type Field struct {
	Name    string                 `json:"name"`
	Type    Type                   `json:"type"`
	Args    map[string]*InputField `json:"arguments"`
	Resolve FieldResolve           `json:"-"`
	Desc    string                 `json:"desc"`
}

type FieldResolve

type FieldResolve func(ctx context.Context, source, args interface{}) (interface{}, error)

type FragmentDefinition

type FragmentDefinition struct {
	Name         string
	On           string
	SelectionSet *SelectionSet
	Loc          errors.Location
}

A FragmentDefinition represents a reusable part of a GraphQL query

The On part of a FragmentDefinition represents the type of source object for which this FragmentDefinition should be used. That is not currently implemented in this package.

type FragmentSpread

type FragmentSpread struct {
	Loc        errors.Location
	Fragment   *FragmentDefinition
	Directives []*Directive
}

FragmentSpread represents a usage of a FragmentDefinition. Alongside the information about the fragment, it includes any directives used at that spread location.

type InputField

type InputField struct {
	Name         string      `json:"name"`
	Type         Type        `json:"type"`
	Desc         string      `json:"description"`
	DefaultValue interface{} `json:"defaultValue"`
}

type InputObject

type InputObject struct {
	Name   string                 `json:"name"`
	Fields map[string]*InputField `json:"fields"`
	Desc   string                 `json:"description"`
}

An input object defines a structured collection of fields which may be supplied to a field argument.

Using NonNull will ensure that a value must be provided by the query

func (*InputObject) Description

func (t *InputObject) Description() string

func (*InputObject) IsType

func (t *InputObject) IsType()

func (*InputObject) String

func (t *InputObject) String() string

func (*InputObject) TypeName

func (t *InputObject) TypeName() string

type Interface

type Interface struct {
	Name          string                `json:"name"`
	Desc          string                `json:"description"`
	Fields        map[string]*Field     `json:"fields"`
	Interfaces    map[string]*Interface `json:"interfaces"`
	PossibleTypes map[string]*Object    `json:"-"`
	TypeResolve   TypeResolve           `json:"-"`
}

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.

func (*Interface) Description

func (t *Interface) Description() string

func (*Interface) IsType

func (t *Interface) IsType()

func (*Interface) String

func (t *Interface) String() string

func (*Interface) TypeName

func (t *Interface) TypeName() string

type List

type List struct {
	Type Type
}

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

func (*List) IsType

func (t *List) IsType()

func (*List) String

func (t *List) String() string

type NamedType

type NamedType interface {
	Type
	TypeName() string
	Description() string
}

type NonNull

type NonNull struct {
	Type Type
}

A non-null is a kind of type marker, 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.

func (*NonNull) IsType

func (t *NonNull) IsType()

func (*NonNull) String

func (t *NonNull) String() string

type Object

type Object struct {
	Name       string                `json:"name"`
	Desc       string                `json:"description"`
	Interfaces map[string]*Interface `json:"interfaces"`
	Fields     map[string]*Field     `json:"fields"`
	IsTypeOf   interface{}           `json:"-"`
}

Almost all of the GraphQL types you define will be object types. Object types have a name, but most importantly describe their fields.

func (*Object) Description

func (t *Object) Description() string

func (*Object) IsType

func (t *Object) IsType()

func (*Object) String

func (t *Object) String() string

func (*Object) TypeName

func (t *Object) TypeName() string

type Scalar

type Scalar struct {
	Name         string                                 `json:"name"`
	Desc         string                                 `json:"description"`
	Serialize    func(interface{}) (interface{}, error) `json:"-"`
	ParseValue   func(interface{}) (interface{}, error) `json:"-"`
	ParseLiteral func(value ast.Value) error            `json:"-"`
}

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 serialization functions used to ensure validity.

func (*Scalar) Description

func (t *Scalar) Description() string

func (*Scalar) IsType

func (t *Scalar) IsType()

func (*Scalar) String

func (t *Scalar) String() string

func (*Scalar) TypeName

func (t *Scalar) TypeName() string

type Schema

type Schema struct {
	TypeMap      map[string]NamedType  `json:"-"`
	Directives   map[string]*Directive `json:"-"`
	Query        Type                  `json:"query"`
	Mutation     Type                  `json:"mutation"`
	Subscription Type                  `json:"subscription"`
}

Schema used to validate and resolve the queries

type Selection

type Selection struct {
	Name         string
	Alias        string
	Args         interface{}
	SelectionSet *SelectionSet
	Directives   []*Directive
	Loc          errors.Location
}

Selection : A selection represents a part of a GraphQL query

The selection

me: user(id: 166) { name }

has name "user" (representing the source field to be queried), alias "me" (representing the name to be used in the output), args id: 166 (representing arguments passed to the source field to be queried), and subselection name representing the information to be queried from the resulting object.

type SelectionSet

type SelectionSet struct {
	Loc        errors.Location
	Selections []*Selection
	Fragments  []*FragmentSpread
}

SelectionSet represents a core GraphQL query

A SelectionSet can contain multiple fields and multiple fragments. For example, the query

{
  name
  ... UserFragment
  memberships {
    organization { name }
  }
}

results in a root SelectionSet with two selections (name and memberships), and one fragment (UserFragment). The subselection `organization { name }` is stored in the memberships selection.

Because GraphQL allows multiple fragments with the same name or alias, selections are stored in an array instead of a map.

type Type

type Type interface {
	String() string
	// IsType() is used to identify the interface that implements IsType,
	// preventing any interface from implementing IsType
	IsType()
}

Operation corresponds to GraphQLType

type TypeResolve

type TypeResolve func(ctx context.Context, value interface{}) *Object

type Union

type Union struct {
	Name  string             `json:"name"`
	Types map[string]*Object `json:"types"`
	Desc  string             `json:"description"`
}

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.

func (*Union) Description

func (t *Union) Description() string

func (*Union) IsType

func (t *Union) IsType()

func (*Union) String

func (t *Union) String() string

func (*Union) TypeName

func (t *Union) TypeName() string

Jump to

Keyboard shortcuts

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