gqlang

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package gqlang provides a parser for the GraphQL language.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name  *Name
	Colon Pos
	Value *InputValue
}

Argument is a single element in Arguments. https://graphql.github.io/graphql-spec/June2018/#sec-Language.Arguments

type Arguments

type Arguments struct {
	LParen Pos
	Args   []*Argument
	RParen Pos
}

Arguments is a set of named arguments on a field. https://graphql.github.io/graphql-spec/June2018/#sec-Language.Arguments

func (*Arguments) ByName

func (args *Arguments) ByName(name string) *Argument

ByName returns the first argument with the given name or nil if not found.

func (*Arguments) IdenticalTo added in v0.2.0

func (args *Arguments) IdenticalTo(args2 *Arguments) bool

IdenticalTo reports whether args is structurally identical to args2, ignoring token positions and argument order. The result is undefined if either set of arguments contain multiple values for the same argument name.

type ArgumentsDefinition

type ArgumentsDefinition struct {
	LParen Pos
	Args   []*InputValueDefinition
	RParen Pos
}

ArgumentsDefinition specifies the arguments for a FieldDefinition. https://graphql.github.io/graphql-spec/June2018/#ArgumentsDefinition

type DefaultValue

type DefaultValue struct {
	Eq    Pos
	Value *InputValue
}

DefaultValue specifies the default value of an input. https://graphql.github.io/graphql-spec/June2018/#DefaultValue

type Definition

type Definition struct {
	Operation *Operation
	Fragment  *FragmentDefinition
	Type      *TypeDefinition
}

Definition is a top-level GraphQL construct like an operation, a fragment, or a type. Only one of its fields will be set. https://graphql.github.io/graphql-spec/June2018/#sec-Language.Document

func (*Definition) Start

func (defn *Definition) Start() Pos

Start returns the position of the definition's first token.

type Description

type Description struct {
	Start Pos
	Raw   string
}

A Description is a string that documents a type system definition. https://graphql.github.io/graphql-spec/June2018/#Description

func (*Description) Value

func (d *Description) Value() string

Value returns the string value of the description.

type Directive added in v0.2.0

type Directive struct {
	At        Pos
	Name      *Name
	Arguments *Arguments // may be nil
}

A Directive is a single annotation.

type Directives added in v0.2.0

type Directives []*Directive

Directives annotate parts of a GraphQL document.

type Document

type Document struct {
	Definitions []*Definition
}

Document is a parsed GraphQL source. https://graphql.github.io/graphql-spec/June2018/#sec-Language.Document

func Parse

func Parse(input string) (*Document, []error)

Parse parses a GraphQL document into an abstract syntax tree.

func (*Document) FindFragment added in v0.2.0

func (doc *Document) FindFragment(name string) *FragmentDefinition

FindFragment returns the fragment with the name or nil if not found.

func (*Document) FindOperation added in v0.2.0

func (doc *Document) FindOperation(name string) *Operation

FindOperation returns the operation with the name or nil if not found. If the name is the empty string, it returns the first operation.

type EnumTypeDefinition

type EnumTypeDefinition struct {
	Description *Description
	Keyword     Pos
	Name        *Name
	Values      *EnumValuesDefinition
}

EnumTypeDefinition defines an enumeration type and its possible values. https://graphql.github.io/graphql-spec/June2018/#EnumTypeDefinition

type EnumValueDefinition

type EnumValueDefinition struct {
	Description *Description
	Value       *Name
	Directives  Directives
}

EnumValueDefinition is a possible value of an enumeration. https://graphql.github.io/graphql-spec/June2018/#EnumValueDefinition

type EnumValuesDefinition

type EnumValuesDefinition struct {
	LBrace Pos
	Values []*EnumValueDefinition
	RBrace Pos
}

EnumValuesDefinition is a brace-delimited list of enumeration values. https://graphql.github.io/graphql-spec/June2018/#EnumValuesDefinition

type Field

type Field struct {
	Alias        *Name
	Name         *Name
	Arguments    *Arguments
	SelectionSet *SelectionSet
}

A Field is a discrete piece of information available to request within a selection set. https://graphql.github.io/graphql-spec/June2018/#sec-Language.Fields

func (*Field) End

func (f *Field) End() Pos

End returns the byte offset after the end of the field.

func (*Field) Key

func (f *Field) Key() *Name

Key returns the field's response key. Typically, this is the field's name, but if an alias is set then that will be used.

func (*Field) Start

func (f *Field) Start() Pos

Start returns the byte offset of the beginning of the field.

type FieldDefinition

type FieldDefinition struct {
	Description *Description
	Name        *Name
	Args        *ArgumentsDefinition
	Colon       Pos
	Type        *TypeRef
	Directives  Directives
}

FieldDefinition specifies a single field in an ObjectTypeDefinition. https://graphql.github.io/graphql-spec/June2018/#FieldsDefinition

type FieldsDefinition

type FieldsDefinition struct {
	LBrace Pos
	Defs   []*FieldDefinition
	RBrace Pos
}

FieldsDefinition is the list of fields in an ObjectTypeDefinition. https://graphql.github.io/graphql-spec/June2018/#FieldsDefinition

type FragmentDefinition added in v0.2.0

type FragmentDefinition struct {
	Keyword      Pos
	Name         *Name
	Type         *TypeCondition
	SelectionSet *SelectionSet
}

A FragmentDefinition is a selection of fields. https://graphql.github.io/graphql-spec/June2018/#FragmentDefinition

type FragmentSpread added in v0.2.0

type FragmentSpread struct {
	Ellipsis Pos
	Name     *Name
}

A FragmentSpread is a reference to a fragment inside a selection set. https://graphql.github.io/graphql-spec/June2018/#FragmentSpread

func (*FragmentSpread) String added in v0.2.0

func (spread *FragmentSpread) String() string

String returns the spread as "...name".

type InlineFragment added in v0.2.0

type InlineFragment struct {
	Ellipsis     Pos
	Type         *TypeCondition // may be nil
	SelectionSet *SelectionSet
}

An InlineFragment is an anonymous fragment inside a selection set. https://graphql.github.io/graphql-spec/June2018/#InlineFragment

type InputFieldsDefinition

type InputFieldsDefinition struct {
	LBrace Pos
	Defs   []*InputValueDefinition
	RBrace Pos
}

InputFieldsDefinition is the list of fields in an InputObjectTypeDefinition. https://graphql.github.io/graphql-spec/June2018/#InputFieldsDefinition

type InputObjectField

type InputObjectField struct {
	Name  *Name
	Colon Pos
	Value *InputValue
}

An InputObjectField is a keyed input value.

type InputObjectTypeDefinition

type InputObjectTypeDefinition struct {
	Description *Description
	Keyword     Pos
	Name        *Name
	Fields      *InputFieldsDefinition
}

InputObjectTypeDefinition names an input object type. https://graphql.github.io/graphql-spec/June2018/#InputObjectTypeDefinition

type InputObjectValue

type InputObjectValue struct {
	LBrace Pos
	Fields []*InputObjectField
	RBrace Pos
}

An InputObjectValue is an unordered list of keyed input values.

func (*InputObjectValue) IdenticalTo added in v0.2.0

func (ioval *InputObjectValue) IdenticalTo(ioval2 *InputObjectValue) bool

IdenticalTo reports whether ioval is structurally identical to ioval2, ignoring token positions and input object field order. The result is undefined if either value is or contains an input object which contain multiple values for the same field name.

func (*InputObjectValue) String

func (ioval *InputObjectValue) String() string

String formats the value in GraphQL syntax.

type InputValue

type InputValue struct {
	Null        *Name
	Scalar      *ScalarValue
	VariableRef *Variable
	List        *ListValue
	InputObject *InputObjectValue
}

An InputValue is a scalar or a variable reference. https://graphql.github.io/graphql-spec/June2018/#sec-Input-Values

func (*InputValue) IdenticalTo added in v0.2.0

func (ival *InputValue) IdenticalTo(ival2 *InputValue) bool

IdenticalTo reports whether ival is structurally identical to ival2, ignoring token positions and input object field order. The result is undefined if either value contains an input object which contain multiple values for the same field name.

func (*InputValue) Start

func (ival *InputValue) Start() Pos

Start returns the byte offset of the beginning of the expression.

func (*InputValue) String

func (ival *InputValue) String() string

String formats the expression as GraphQL syntax.

type InputValueDefinition

type InputValueDefinition struct {
	Description *Description
	Name        *Name
	Colon       Pos
	Type        *TypeRef
	Default     *DefaultValue
}

InputValueDefinition specifies an argument in a FieldDefinition or a field in an InputObjectTypeDefinition. https://graphql.github.io/graphql-spec/June2018/#InputValueDefinition

type ListType

type ListType struct {
	LBracket Pos
	Type     *TypeRef
	RBracket Pos
}

ListType declares a homogenous sequence of another type. https://graphql.github.io/graphql-spec/June2018/#ListType

func (*ListType) String

func (ltype *ListType) String() string

String formats the type in GraphQL syntax.

type ListValue

type ListValue struct {
	LBracket Pos
	Values   []*InputValue
	RBracket Pos
}

A ListValue is an ordered list literal.

func (*ListValue) IdenticalTo added in v0.2.0

func (lval *ListValue) IdenticalTo(lval2 *ListValue) bool

IdenticalTo reports whether lval is structurally identical to lval2, ignoring token positions and input object field order. The result is undefined if either value contains an input object which contain multiple values for the same field name.

func (*ListValue) String

func (lval *ListValue) String() string

String formats the list in GraphQL syntax.

type Name

type Name struct {
	Value string
	Start Pos
}

A Name is an identifier. https://graphql.github.io/graphql-spec/June2018/#sec-Names

func (*Name) End

func (n *Name) End() Pos

End returns the position of the byte after the last character of the name.

func (*Name) String

func (n *Name) String() string

String returns the name or the empty string if the name is nil.

type NonNullType

type NonNullType struct {
	Named *Name
	List  *ListType
	Pos   Pos
}

NonNullType declares a named or list type that cannot be null. https://graphql.github.io/graphql-spec/June2018/#Type

func (*NonNullType) Start

func (nn *NonNullType) Start() Pos

Start returns the byte offset of the start of the type.

func (*NonNullType) String

func (nn *NonNullType) String() string

String formats the type in GraphQL syntax.

type ObjectTypeDefinition

type ObjectTypeDefinition struct {
	Description *Description
	Keyword     Pos
	Name        *Name
	Fields      *FieldsDefinition
}

ObjectTypeDefinition names an output object type. https://graphql.github.io/graphql-spec/June2018/#ObjectTypeDefinition

type Operation

type Operation struct {
	Start               Pos
	Type                OperationType
	Name                *Name
	VariableDefinitions *VariableDefinitions
	SelectionSet        *SelectionSet
}

Operation is a query, a mutation, or a subscription. https://graphql.github.io/graphql-spec/June2018/#sec-Language.Operations

type OperationType

type OperationType int

OperationType is one of query, mutation, or subscription.

const (
	Query OperationType = iota
	Mutation
	Subscription
)

Types of operation.

func (OperationType) String

func (typ OperationType) String() string

String returns the keyword that corresponds to the operation type.

type Pos

type Pos int

A Pos is a 0-based byte offset in a GraphQL document.

func ErrorPos

func ErrorPos(e error) (pos Pos, ok bool)

ErrorPos attempts to extract an error's Pos.

func (Pos) ToPosition

func (pos Pos) ToPosition(input string) Position

ToPosition converts a byte position into a line and column number.

type Position

type Position struct {
	Line   int
	Column int
}

A Position is a line/column pair. Both are 1-based. The column is byte-based.

func ErrorPosition

func ErrorPosition(e error) (p Position, ok bool)

ErrorPosition attempts to extract an error's Position.

func (Position) String

func (p Position) String() string

String returns p in the form "line:col".

type ScalarType

type ScalarType int

ScalarType indicates the type of a ScalarValue.

const (
	StringScalar ScalarType = iota
	BooleanScalar
	EnumScalar
	IntScalar
	FloatScalar
)

Scalar types.

type ScalarTypeDefinition

type ScalarTypeDefinition struct {
	Description *Description
	Keyword     Pos
	Name        *Name
}

ScalarTypeDefinition names a scalar type. https://graphql.github.io/graphql-spec/June2018/#ScalarTypeDefinition

type ScalarValue

type ScalarValue struct {
	Start Pos
	Type  ScalarType
	Raw   string
}

ScalarValue is a primitive literal like a string or integer.

func (*ScalarValue) IdenticalTo added in v0.2.0

func (sval *ScalarValue) IdenticalTo(sval2 *ScalarValue) bool

IdenticalTo reports whether sval has the same type and value as sval2.

func (*ScalarValue) String

func (sval *ScalarValue) String() string

String returns sval.Raw.

func (*ScalarValue) Value

func (sval *ScalarValue) Value() string

Value converts the raw scalar into a string.

type Selection

type Selection struct {
	Field          *Field
	FragmentSpread *FragmentSpread
	InlineFragment *InlineFragment
}

A Selection is either a field or a fragment. https://graphql.github.io/graphql-spec/June2018/#sec-Selection-Sets

type SelectionSet

type SelectionSet struct {
	LBrace Pos
	Sel    []*Selection
	RBrace Pos
}

SelectionSet is the set of information an operation requests. https://graphql.github.io/graphql-spec/June2018/#SelectionSet

type TypeCondition added in v0.2.0

type TypeCondition struct {
	On   Pos
	Name *Name
}

TypeCondition specifies the type a fragment applies to. https://graphql.github.io/graphql-spec/June2018/#TypeCondition

func (*TypeCondition) String added in v0.2.0

func (cond *TypeCondition) String() string

String returns the condition in the form "on TypeName".

type TypeDefinition

type TypeDefinition struct {
	Scalar      *ScalarTypeDefinition
	Object      *ObjectTypeDefinition
	Union       *UnionTypeDefinition
	Enum        *EnumTypeDefinition
	InputObject *InputObjectTypeDefinition
}

TypeDefinition holds a type definition. https://graphql.github.io/graphql-spec/June2018/#TypeDefinition

func (*TypeDefinition) Description

func (defn *TypeDefinition) Description() *Description

Description returns the type definition's description or nil if it does not have one.

func (*TypeDefinition) Name

func (defn *TypeDefinition) Name() *Name

Name returns the type definition's name.

func (*TypeDefinition) Start

func (defn *TypeDefinition) Start() Pos

Start returns the position of the type definition's first token.

type TypeRef

type TypeRef struct {
	Named   *Name
	List    *ListType
	NonNull *NonNullType
}

A TypeRef is a named type, a list type, or a non-null type. https://graphql.github.io/graphql-spec/June2018/#Type

func (*TypeRef) Start

func (ref *TypeRef) Start() Pos

Start returns the byte offset of the start of the type reference.

func (*TypeRef) String

func (ref *TypeRef) String() string

String formats the type in GraphQL syntax.

type UnionTypeDefinition added in v0.7.0

type UnionTypeDefinition struct {
	Description *Description
	Keyword     Pos
	Name        *Name
	MemberTypes []*Name
}

UnionTypeDefinition defines an type that permits any one of a list of types. https://graphql.github.io/graphql-spec/June2018/#UnionTypeDefinition

type Variable

type Variable struct {
	Dollar Pos
	Name   *Name
}

A Variable is an input to a GraphQL operation. https://graphql.github.io/graphql-spec/June2018/#Variable

func (*Variable) String

func (v *Variable) String() string

String returns the variable in the form "$foo".

type VariableDefinition

type VariableDefinition struct {
	Var     *Variable
	Colon   Pos
	Type    *TypeRef
	Default *DefaultValue
}

VariableDefinition is an element of VariableDefinitions. https://graphql.github.io/graphql-spec/June2018/#Variable

type VariableDefinitions

type VariableDefinitions struct {
	LParen Pos
	Defs   []*VariableDefinition
	RParen Pos
}

VariableDefinitions is the set of variables an operation defines. https://graphql.github.io/graphql-spec/June2018/#Variable

Jump to

Keyboard shortcuts

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