ast

package
v2.5.19 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 6 Imported by: 3,700

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(i interface{}) string

Dump turns ast into a stable string format for assertions in tests

Types

type Argument

type Argument struct {
	Name     string
	Value    *Value
	Position *Position `dump:"-"`
	Comment  *CommentGroup
}

type ArgumentDefinition

type ArgumentDefinition struct {
	Description  string
	Name         string
	DefaultValue *Value
	Type         *Type
	Directives   DirectiveList
	Position     *Position `dump:"-"`

	BeforeDescriptionComment *CommentGroup
	AfterDescriptionComment  *CommentGroup
}

type ArgumentDefinitionList

type ArgumentDefinitionList []*ArgumentDefinition

func (ArgumentDefinitionList) ForName

type ArgumentList

type ArgumentList []*Argument

func (ArgumentList) ForName

func (l ArgumentList) ForName(name string) *Argument

type ChildValue

type ChildValue struct {
	Name     string
	Value    *Value
	Position *Position `dump:"-"`
	Comment  *CommentGroup
}

type ChildValueList

type ChildValueList []*ChildValue

func (ChildValueList) ForName

func (v ChildValueList) ForName(name string) *Value

type Comment added in v2.5.5

type Comment struct {
	Value    string
	Position *Position
}

func (*Comment) Text added in v2.5.5

func (c *Comment) Text() string

type CommentGroup added in v2.5.5

type CommentGroup struct {
	List []*Comment
}

func (*CommentGroup) Dump added in v2.5.5

func (c *CommentGroup) Dump() string

type Definition

type Definition struct {
	Kind        DefinitionKind
	Description string
	Name        string
	Directives  DirectiveList
	Interfaces  []string      // object and input object
	Fields      FieldList     // object and input object
	Types       []string      // union
	EnumValues  EnumValueList // enum

	Position *Position `dump:"-"`
	BuiltIn  bool      `dump:"-"`

	BeforeDescriptionComment *CommentGroup
	AfterDescriptionComment  *CommentGroup
	EndOfDefinitionComment   *CommentGroup
}

Definition is the core type definition object, it includes all of the definable types but does *not* cover schema or directives.

@vektah: Javascript implementation has different types for all of these, but they are more similar than different and don't define any behaviour. I think this style of "some hot" struct works better, at least for go.

Type extensions are also represented by this same struct.

func (*Definition) IsAbstractType

func (d *Definition) IsAbstractType() bool

func (*Definition) IsCompositeType

func (d *Definition) IsCompositeType() bool

func (*Definition) IsInputType

func (d *Definition) IsInputType() bool

func (*Definition) IsLeafType

func (d *Definition) IsLeafType() bool

func (*Definition) OneOf

func (d *Definition) OneOf(types ...string) bool

type DefinitionKind

type DefinitionKind string
const (
	Scalar      DefinitionKind = "SCALAR"
	Object      DefinitionKind = "OBJECT"
	Interface   DefinitionKind = "INTERFACE"
	Union       DefinitionKind = "UNION"
	Enum        DefinitionKind = "ENUM"
	InputObject DefinitionKind = "INPUT_OBJECT"
)

type DefinitionList

type DefinitionList []*Definition

func (DefinitionList) ForName

func (l DefinitionList) ForName(name string) *Definition

type Directive

type Directive struct {
	Name      string
	Arguments ArgumentList
	Position  *Position `dump:"-"`

	// Requires validation
	ParentDefinition *Definition
	Definition       *DirectiveDefinition
	Location         DirectiveLocation
}

func (*Directive) ArgumentMap

func (d *Directive) ArgumentMap(vars map[string]interface{}) map[string]interface{}

type DirectiveDefinition

type DirectiveDefinition struct {
	Description  string
	Name         string
	Arguments    ArgumentDefinitionList
	Locations    []DirectiveLocation
	IsRepeatable bool
	Position     *Position `dump:"-"`

	BeforeDescriptionComment *CommentGroup
	AfterDescriptionComment  *CommentGroup
}

type DirectiveDefinitionList

type DirectiveDefinitionList []*DirectiveDefinition

func (DirectiveDefinitionList) ForName

type DirectiveList

type DirectiveList []*Directive

func (DirectiveList) ForName

func (l DirectiveList) ForName(name string) *Directive

func (DirectiveList) ForNames

func (l DirectiveList) ForNames(name string) []*Directive

type DirectiveLocation

type DirectiveLocation string
const (
	// Executable
	LocationQuery              DirectiveLocation = `QUERY`
	LocationMutation           DirectiveLocation = `MUTATION`
	LocationSubscription       DirectiveLocation = `SUBSCRIPTION`
	LocationField              DirectiveLocation = `FIELD`
	LocationFragmentDefinition DirectiveLocation = `FRAGMENT_DEFINITION`
	LocationFragmentSpread     DirectiveLocation = `FRAGMENT_SPREAD`
	LocationInlineFragment     DirectiveLocation = `INLINE_FRAGMENT`

	// Type System
	LocationSchema               DirectiveLocation = `SCHEMA`
	LocationScalar               DirectiveLocation = `SCALAR`
	LocationObject               DirectiveLocation = `OBJECT`
	LocationFieldDefinition      DirectiveLocation = `FIELD_DEFINITION`
	LocationArgumentDefinition   DirectiveLocation = `ARGUMENT_DEFINITION`
	LocationInterface            DirectiveLocation = `INTERFACE`
	LocationUnion                DirectiveLocation = `UNION`
	LocationEnum                 DirectiveLocation = `ENUM`
	LocationEnumValue            DirectiveLocation = `ENUM_VALUE`
	LocationInputObject          DirectiveLocation = `INPUT_OBJECT`
	LocationInputFieldDefinition DirectiveLocation = `INPUT_FIELD_DEFINITION`
	LocationVariableDefinition   DirectiveLocation = `VARIABLE_DEFINITION`
)

type Dumpable

type Dumpable interface {
	Dump() string
}

type EnumValueDefinition

type EnumValueDefinition struct {
	Description string
	Name        string
	Directives  DirectiveList
	Position    *Position `dump:"-"`

	BeforeDescriptionComment *CommentGroup
	AfterDescriptionComment  *CommentGroup
}

type EnumValueList

type EnumValueList []*EnumValueDefinition

func (EnumValueList) ForName

func (l EnumValueList) ForName(name string) *EnumValueDefinition

type Field

type Field struct {
	Alias        string
	Name         string
	Arguments    ArgumentList
	Directives   DirectiveList
	SelectionSet SelectionSet
	Position     *Position `dump:"-"`
	Comment      *CommentGroup

	// Require validation
	Definition       *FieldDefinition
	ObjectDefinition *Definition
}

func (*Field) ArgumentMap

func (f *Field) ArgumentMap(vars map[string]interface{}) map[string]interface{}

func (*Field) GetPosition

func (f *Field) GetPosition() *Position

func (*Field) UnmarshalJSON added in v2.4.8

func (f *Field) UnmarshalJSON(b []byte) error

type FieldDefinition

type FieldDefinition struct {
	Description  string
	Name         string
	Arguments    ArgumentDefinitionList // only for objects
	DefaultValue *Value                 // only for input objects
	Type         *Type
	Directives   DirectiveList
	Position     *Position `dump:"-"`

	BeforeDescriptionComment *CommentGroup
	AfterDescriptionComment  *CommentGroup
}

type FieldList

type FieldList []*FieldDefinition

func (FieldList) ForName

func (l FieldList) ForName(name string) *FieldDefinition

type FragmentDefinition

type FragmentDefinition struct {
	Name string
	// Note: fragment variable definitions are experimental and may be changed
	// or removed in the future.
	VariableDefinition VariableDefinitionList
	TypeCondition      string
	Directives         DirectiveList
	SelectionSet       SelectionSet

	// Require validation
	Definition *Definition

	Position *Position `dump:"-"`
	Comment  *CommentGroup
}

func (*FragmentDefinition) UnmarshalJSON added in v2.4.8

func (f *FragmentDefinition) UnmarshalJSON(b []byte) error

type FragmentDefinitionList

type FragmentDefinitionList []*FragmentDefinition

func (FragmentDefinitionList) ForName

type FragmentSpread

type FragmentSpread struct {
	Name       string
	Directives DirectiveList

	// Require validation
	ObjectDefinition *Definition
	Definition       *FragmentDefinition

	Position *Position `dump:"-"`
	Comment  *CommentGroup
}

func (*FragmentSpread) GetPosition

func (s *FragmentSpread) GetPosition() *Position

type InlineFragment

type InlineFragment struct {
	TypeCondition string
	Directives    DirectiveList
	SelectionSet  SelectionSet

	// Require validation
	ObjectDefinition *Definition

	Position *Position `dump:"-"`
	Comment  *CommentGroup
}

func (*InlineFragment) GetPosition

func (f *InlineFragment) GetPosition() *Position

func (*InlineFragment) UnmarshalJSON added in v2.4.8

func (f *InlineFragment) UnmarshalJSON(b []byte) error

type Operation

type Operation string
const (
	Query        Operation = "query"
	Mutation     Operation = "mutation"
	Subscription Operation = "subscription"
)

type OperationDefinition

type OperationDefinition struct {
	Operation           Operation
	Name                string
	VariableDefinitions VariableDefinitionList
	Directives          DirectiveList
	SelectionSet        SelectionSet
	Position            *Position `dump:"-"`
	Comment             *CommentGroup
}

func (*OperationDefinition) UnmarshalJSON added in v2.4.8

func (f *OperationDefinition) UnmarshalJSON(b []byte) error

type OperationList

type OperationList []*OperationDefinition

func (OperationList) ForName

func (l OperationList) ForName(name string) *OperationDefinition

type OperationTypeDefinition

type OperationTypeDefinition struct {
	Operation Operation
	Type      string
	Position  *Position `dump:"-"`
	Comment   *CommentGroup
}

type OperationTypeDefinitionList

type OperationTypeDefinitionList []*OperationTypeDefinition

func (OperationTypeDefinitionList) ForType

type Path

type Path []PathElement

func (Path) String

func (path Path) String() string

func (*Path) UnmarshalJSON

func (path *Path) UnmarshalJSON(b []byte) error

type PathElement

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

type PathIndex

type PathIndex int

type PathName

type PathName string

type Position

type Position struct {
	Start  int     // The starting position, in runes, of this token in the input.
	End    int     // The end position, in runes, of this token in the input.
	Line   int     // The line number at the start of this item.
	Column int     // The column number at the start of this item.
	Src    *Source // The source document this token belongs to
}

type QueryDocument

type QueryDocument struct {
	Operations OperationList
	Fragments  FragmentDefinitionList
	Position   *Position `dump:"-"`
	Comment    *CommentGroup
}

type Schema

type Schema struct {
	Query            *Definition
	Mutation         *Definition
	Subscription     *Definition
	SchemaDirectives DirectiveList

	Types      map[string]*Definition
	Directives map[string]*DirectiveDefinition

	PossibleTypes map[string][]*Definition
	Implements    map[string][]*Definition

	Description string

	Comment *CommentGroup
}

func (*Schema) AddImplements

func (s *Schema) AddImplements(name string, iface *Definition)

func (*Schema) AddPossibleType

func (s *Schema) AddPossibleType(name string, def *Definition)

func (*Schema) AddTypes added in v2.4.2

func (s *Schema) AddTypes(defs ...*Definition)

AddTypes is the helper to add types definition to the schema

func (*Schema) GetImplements

func (s *Schema) GetImplements(def *Definition) []*Definition

GetImplements returns all the interface and union definitions that the given definition satisfies

func (*Schema) GetPossibleTypes

func (s *Schema) GetPossibleTypes(def *Definition) []*Definition

GetPossibleTypes will enumerate all the definitions for a given interface or union

type SchemaDefinition

type SchemaDefinition struct {
	Description    string
	Directives     DirectiveList
	OperationTypes OperationTypeDefinitionList
	Position       *Position `dump:"-"`

	BeforeDescriptionComment *CommentGroup
	AfterDescriptionComment  *CommentGroup
	EndOfDefinitionComment   *CommentGroup
}

type SchemaDefinitionList

type SchemaDefinitionList []*SchemaDefinition

type SchemaDocument

type SchemaDocument struct {
	Schema          SchemaDefinitionList
	SchemaExtension SchemaDefinitionList
	Directives      DirectiveDefinitionList
	Definitions     DefinitionList
	Extensions      DefinitionList
	Position        *Position `dump:"-"`
	Comment         *CommentGroup
}

func (*SchemaDocument) Merge

func (d *SchemaDocument) Merge(other *SchemaDocument)

type Selection

type Selection interface {
	GetPosition() *Position
	// contains filtered or unexported methods
}

type SelectionSet

type SelectionSet []Selection

func UnmarshalSelectionSet added in v2.4.8

func UnmarshalSelectionSet(b []byte) (SelectionSet, error)

type Source

type Source struct {
	// Name is the filename of the source
	Name string
	// Input is the actual contents of the source file
	Input string
	// BuiltIn indicate whether the source is a part of the specification
	BuiltIn bool
}

Source covers a single *.graphql file

type Type

type Type struct {
	NamedType string
	Elem      *Type
	NonNull   bool
	Position  *Position `dump:"-"`
}

func ListType

func ListType(elem *Type, pos *Position) *Type

func NamedType

func NamedType(named string, pos *Position) *Type

func NonNullListType

func NonNullListType(elem *Type, pos *Position) *Type

func NonNullNamedType

func NonNullNamedType(named string, pos *Position) *Type

func (*Type) Dump

func (t *Type) Dump() string

func (*Type) IsCompatible

func (t *Type) IsCompatible(other *Type) bool

func (*Type) Name

func (t *Type) Name() string

func (*Type) String

func (t *Type) String() string

type Value

type Value struct {
	Raw      string
	Children ChildValueList
	Kind     ValueKind
	Position *Position `dump:"-"`
	Comment  *CommentGroup

	// Require validation
	Definition         *Definition
	VariableDefinition *VariableDefinition
	ExpectedType       *Type
}

func (*Value) Dump

func (v *Value) Dump() string

func (*Value) String

func (v *Value) String() string

func (*Value) Value

func (v *Value) Value(vars map[string]interface{}) (interface{}, error)

type ValueKind

type ValueKind int
const (
	Variable ValueKind = iota
	IntValue
	FloatValue
	StringValue
	BlockValue
	BooleanValue
	NullValue
	EnumValue
	ListValue
	ObjectValue
)

type VariableDefinition

type VariableDefinition struct {
	Variable     string
	Type         *Type
	DefaultValue *Value
	Directives   DirectiveList
	Position     *Position `dump:"-"`
	Comment      *CommentGroup

	// Requires validation
	Definition *Definition
	Used       bool `dump:"-"`
}

type VariableDefinitionList

type VariableDefinitionList []*VariableDefinition

func (VariableDefinitionList) ForName

Jump to

Keyboard shortcuts

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