Documentation
¶
Overview ¶
Package language reads and writes GraphQL documents: a lexer and a parser for executable documents (operations and fragments) and type-system documents (schema definitions, the SDL), the syntax tree both produce, and a printer. It follows the GraphQL specification (October 2021): block strings, \u{…} escapes and descriptions included.
Every node records where it starts (Loc): a 1-based line and a 1-based column counted in characters.
Index ¶
- Constants
- func BlockStringValue(raw string) string
- func Print(n Node) string
- func PrintBlockString(s, indent string) string
- func PrintString(s string) string
- type Argument
- type BooleanValue
- type Definition
- type Directive
- type DirectiveDefinition
- type Document
- type EnumTypeDefinition
- type EnumValue
- type EnumValueDefinition
- type Field
- type FieldDefinition
- type FloatValue
- type FragmentDefinition
- type FragmentSpread
- type InlineFragment
- type InputObjectTypeDefinition
- type InputValueDefinition
- type IntValue
- type InterfaceTypeDefinition
- type ListType
- type ListValue
- type Loc
- type NamedType
- type Node
- type NonNullType
- type NullValue
- type ObjectField
- type ObjectTypeDefinition
- type ObjectValue
- type OperationDefinition
- type OperationTypeDefinition
- type ScalarTypeDefinition
- type SchemaDefinition
- type Selection
- type SelectionSet
- type StringValue
- type SyntaxError
- type TypeRef
- type UnionTypeDefinition
- type Value
- type Variable
- type VariableDefinition
Constants ¶
const ( OpQuery = "query" OpMutation = "mutation" OpSubscription = "subscription" )
Operation kinds, as OperationDefinition.Operation and OperationTypeDefinition.Operation spell them.
Variables ¶
This section is empty.
Functions ¶
func BlockStringValue ¶
BlockStringValue is a block string's value from its raw text (between the quotes, \""" already unescaped): its common indentation and its leading and trailing blank lines removed, lines joined with \n.
func Print ¶
Print writes a node as GraphQL: a document, a definition, a selection, a value or a type, two spaces an indentation level.
func PrintBlockString ¶
PrintBlockString writes s as a block string ("""…"""), its lines after the first indented with indent; a string a block string can't hold as it is (one with leading spaces on its first line, or ending in a quote) is written so it reads back the same.
func PrintString ¶
PrintString writes s as a GraphQL string literal, quoted and escaped.
Types ¶
type Definition ¶
type Definition interface {
Node
// contains filtered or unexported methods
}
Definition is a top-level definition of a document: an *OperationDefinition or *FragmentDefinition (executable), or a type-system definition.
type DirectiveDefinition ¶
type DirectiveDefinition struct {
Loc
Description string
Name string
Arguments []*InputValueDefinition
Repeatable bool
Locations []string
}
DirectiveDefinition is directive @name(args) repeatable on LOCATIONS.
type Document ¶
type Document struct {
Loc
Definitions []Definition
}
Document is a parsed GraphQL document.
func Parse ¶
Parse parses a GraphQL document: operations and fragments, and type-system definitions (the SDL) too — a document of either kind, or a mix, which validation then refuses where it runs operations.
func (*Document) Fragments ¶
func (d *Document) Fragments() map[string]*FragmentDefinition
Fragments are the document's fragment definitions by name; the first of a name when several share it.
func (*Document) Operations ¶
func (d *Document) Operations() []*OperationDefinition
Operations are the document's operation definitions, in order.
type EnumTypeDefinition ¶
type EnumTypeDefinition struct {
Loc
Extend bool
Description string
Name string
Directives []*Directive
Values []*EnumValueDefinition
}
EnumTypeDefinition is enum Name { VALUES }.
type EnumValueDefinition ¶
EnumValueDefinition is one value of an enum.
type Field ¶
type Field struct {
Loc
Alias string // "" when it has none
Name string
Arguments []*Argument
Directives []*Directive
SelectionSet *SelectionSet // nil for a leaf
}
Field selects a field: alias: name(args) @directives { … }.
func (*Field) ResponseKey ¶
ResponseKey is the key the field's value takes in the response: its alias, else its name.
type FieldDefinition ¶
type FieldDefinition struct {
Loc
Description string
Name string
Arguments []*InputValueDefinition
Type TypeRef
Directives []*Directive
}
FieldDefinition is a field of an object or interface type.
type FloatValue ¶
FloatValue is a float literal, as written.
type FragmentDefinition ¶
type FragmentDefinition struct {
Loc
Name string
NameLoc Loc
TypeCondition *NamedType
Directives []*Directive
SelectionSet *SelectionSet
}
FragmentDefinition is a named fragment: fragment Name on Type { … }.
type FragmentSpread ¶
FragmentSpread is ...Name @directives.
type InlineFragment ¶
type InlineFragment struct {
Loc
TypeCondition *NamedType
Directives []*Directive
SelectionSet *SelectionSet
}
InlineFragment is ... on Type @directives { … }; TypeCondition is nil when the fragment names no type.
type InputObjectTypeDefinition ¶
type InputObjectTypeDefinition struct {
Loc
Extend bool
Description string
Name string
Directives []*Directive
Fields []*InputValueDefinition
}
InputObjectTypeDefinition is input Name { fields }.
type InputValueDefinition ¶
type InputValueDefinition struct {
Loc
Description string
Name string
Type TypeRef
DefaultValue Value // nil when it has none
Directives []*Directive
}
InputValueDefinition is an argument or an input object's field.
type InterfaceTypeDefinition ¶
type InterfaceTypeDefinition struct {
Loc
Extend bool
Description string
Name string
Interfaces []*NamedType
Directives []*Directive
Fields []*FieldDefinition
}
InterfaceTypeDefinition is interface Name implements A { fields }.
type Loc ¶
type Loc struct{ Line, Column int }
Loc is where a node starts in its source: 1-based line and column, the column counted in characters (runes).
type NonNullType ¶
NonNullType is Type!.
func (*NonNullType) String ¶
func (t *NonNullType) String() string
type ObjectField ¶
ObjectField is one name: value of an ObjectValue.
type ObjectTypeDefinition ¶
type ObjectTypeDefinition struct {
Loc
Extend bool
Description string
Name string
Interfaces []*NamedType
Directives []*Directive
Fields []*FieldDefinition
}
ObjectTypeDefinition is type Name implements A & B { fields }.
type ObjectValue ¶
type ObjectValue struct {
Loc
Fields []*ObjectField
}
ObjectValue is { name: value … }.
type OperationDefinition ¶
type OperationDefinition struct {
Loc
Operation string // "query", "mutation" or "subscription"
Name string
NameLoc Loc
VariableDefinitions []*VariableDefinition
Directives []*Directive
SelectionSet *SelectionSet
Shorthand bool
}
OperationDefinition is a query, mutation or subscription. Shorthand is a query written as a bare selection set ("{ a }").
type OperationTypeDefinition ¶
OperationTypeDefinition is query: Query inside a schema definition.
type ScalarTypeDefinition ¶
type ScalarTypeDefinition struct {
Loc
Extend bool
Description string
Name string
Directives []*Directive
}
ScalarTypeDefinition is scalar Name.
type SchemaDefinition ¶
type SchemaDefinition struct {
Loc
Extend bool
Description string
Directives []*Directive
OperationTypes []*OperationTypeDefinition
}
SchemaDefinition is schema { query: Query … }.
type Selection ¶
type Selection interface {
Node
// contains filtered or unexported methods
}
Selection is a *Field, *FragmentSpread or *InlineFragment.
type SelectionSet ¶
SelectionSet is { … }: the fields and fragments selected.
type StringValue ¶
StringValue is a string literal, its escapes resolved (a block string's indentation removed); Block says it was written """…""".
type SyntaxError ¶
SyntaxError is a document that doesn't parse: what is wrong, and where.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type UnionTypeDefinition ¶
type UnionTypeDefinition struct {
Loc
Extend bool
Description string
Name string
Directives []*Directive
Types []*NamedType
}
UnionTypeDefinition is union Name = A | B.