ast

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArenaOptions

type ArenaOptions struct {
	Nodes               int
	Definitions         int
	IndexEntries        int
	Values              int
	Arguments           int
	Directives          int
	VariableDefinitions int
}

type Argument

type Argument struct {
	Name  string
	Value Value
}

type Builder

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

func (*Builder) Operation

func (b *Builder) Operation(op OperationType, name string) *SelectionBuilder

type Description

type Description struct {
	Value   string
	Span    Span
	IsBlock bool
	Defined bool
}

type Directive

type Directive struct {
	Name      string
	Arguments []Argument
}

type Document

type Document struct {
	Source []byte
	// contains filtered or unexported fields
}

func NewArenaDocument

func NewArenaDocument(a arena.Arena, opts ArenaOptions) *Document

func NewDocument

func NewDocument() *Document

func NewDocumentWithCapacity

func NewDocumentWithCapacity(nodes, definitions int, values ...int) *Document

func ResetArenaDocument

func ResetArenaDocument(doc *Document, a arena.Arena, opts ArenaOptions) *Document

ResetArenaDocument prepares a released arena document for another parse. The caller must ensure that no references to the document remain in use.

func (*Document) AddChild

func (d *Document) AddChild(parent NodeID, n Node) NodeID

func (*Document) AddDefinition

func (d *Document) AddDefinition(n Node) NodeID

func (*Document) AddFieldChild

func (d *Document) AddFieldChild(parent NodeID, name, alias string, span Span) NodeID

func (*Document) AddFieldOrInputValueDefinitionChild

func (d *Document) AddFieldOrInputValueDefinitionChild(parent NodeID, kind Kind, name, typ string, children []NodeID, directives []Directive, span Span) NodeID

func (*Document) AddIndexedDefinition

func (d *Document) AddIndexedDefinition(n Node) NodeID

func (*Document) AddIndexedFieldChild

func (d *Document) AddIndexedFieldChild(parent NodeID, name, alias string, span Span) NodeID

func (*Document) AdoptChild

func (d *Document) AdoptChild(parent, child NodeID)

func (*Document) Alias

func (d *Document) Alias(id NodeID) string

func (*Document) AppendArgument

func (d *Document) AppendArgument(dst []Argument, arg Argument) []Argument

func (*Document) AppendDirective

func (d *Document) AppendDirective(dst []Directive, directive Directive) []Directive

func (*Document) AppendNodeID

func (d *Document) AppendNodeID(dst []NodeID, id NodeID) []NodeID

func (*Document) AppendRootOperation

func (d *Document) AppendRootOperation(dst []RootOperation, root RootOperation) []RootOperation

func (*Document) AppendString

func (d *Document) AppendString(dst []string, value string) []string

func (*Document) AppendVariableDefinition

func (d *Document) AppendVariableDefinition(dst []VariableDefinition, variable VariableDefinition) []VariableDefinition

func (*Document) Builder

func (d *Document) Builder() *Builder

func (*Document) Children

func (d *Document) Children(id NodeID) []NodeID

func (*Document) DefinitionCount

func (d *Document) DefinitionCount() int

func (*Document) DefinitionIDs

func (d *Document) DefinitionIDs() []NodeID

func (*Document) Definitions

func (d *Document) Definitions() []NodeID

func (*Document) DirectiveDefinition

func (d *Document) DirectiveDefinition(name string) (NodeID, bool)

func (*Document) Editor

func (d *Document) Editor() *Editor

func (*Document) FirstField

func (d *Document) FirstField(parent NodeID, name string) (NodeID, bool)

func (*Document) FirstFieldByName

func (d *Document) FirstFieldByName(name string) (NodeID, bool)

func (*Document) Fragment

func (d *Document) Fragment(name string) (NodeID, bool)

func (*Document) Kind

func (d *Document) Kind(id NodeID) Kind

func (*Document) MetadataJSON

func (d *Document) MetadataJSON() *astjson.Value

func (*Document) MutableNode

func (d *Document) MutableNode(id NodeID) (*Node, error)

func (*Document) Name

func (d *Document) Name(id NodeID) string

func (*Document) Node

func (d *Document) Node(id NodeID) (Node, bool)

func (*Document) NodePtr

func (d *Document) NodePtr(id NodeID) (*Node, bool)

func (*Document) Operation

func (d *Document) Operation(name string) (NodeID, bool)

func (*Document) OperationType

func (d *Document) OperationType(id NodeID) OperationType

func (*Document) Parent

func (d *Document) Parent(id NodeID) NodeID

func (*Document) RebuildIndexes

func (d *Document) RebuildIndexes()

func (*Document) SetChildren

func (d *Document) SetChildren(parent NodeID, children []NodeID)

func (*Document) SetMetadataJSON

func (d *Document) SetMetadataJSON(a arena.Arena, raw []byte) error

func (*Document) SetMetadataJSONWithParser

func (d *Document) SetMetadataJSONWithParser(a arena.Arena, parser *astjson.Parser, raw []byte) error

func (*Document) Span

func (d *Document) Span(id NodeID) Span

func (*Document) TraversalChildren

func (d *Document) TraversalChildren(id NodeID) ([]NodeID, bool)

func (*Document) TraversalChildrenUnchecked

func (d *Document) TraversalChildrenUnchecked(id NodeID) []NodeID

func (*Document) TraversalData

func (d *Document) TraversalData(id NodeID) (Kind, string, []NodeID, bool)

func (*Document) TraversalDataUnchecked

func (d *Document) TraversalDataUnchecked(id NodeID) (Kind, string, []NodeID)

func (*Document) TraversalKindChildren

func (d *Document) TraversalKindChildren(id NodeID) (Kind, []NodeID, bool)

func (*Document) TraversalKindChildrenUnchecked

func (d *Document) TraversalKindChildrenUnchecked(id NodeID) (Kind, []NodeID)

func (*Document) TraversalNameUnchecked

func (d *Document) TraversalNameUnchecked(id NodeID) string

func (*Document) Type

func (d *Document) Type(name string) (NodeID, bool)

func (*Document) ValuePtr

func (d *Document) ValuePtr(value Value) *Value

type Editor

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

func (*Editor) AddArgument

func (e *Editor) AddArgument(id NodeID, arg Argument) error

func (*Editor) AddDirective

func (e *Editor) AddDirective(id NodeID, directive Directive) error

func (*Editor) AddField

func (e *Editor) AddField(parent NodeID, spec FieldSpec) (NodeID, error)

func (*Editor) CopySelectionsFrom

func (e *Editor) CopySelectionsFrom(dstParent NodeID, src *Document, srcRoot NodeID) ([]NodeID, error)

func (*Editor) MoveSelection

func (e *Editor) MoveSelection(parent, child NodeID, to int) error

func (*Editor) Remove

func (e *Editor) Remove(id NodeID) error

func (*Editor) RemoveArgument

func (e *Editor) RemoveArgument(id NodeID, name string) error

func (*Editor) RemoveDirective

func (e *Editor) RemoveDirective(id NodeID, name string) error

func (*Editor) ReplaceArgumentValue

func (e *Editor) ReplaceArgumentValue(id NodeID, name string, value Value) error

func (*Editor) ReplaceFragmentSpreadWithInlineFragment

func (e *Editor) ReplaceFragmentSpreadWithInlineFragment(id NodeID, typeCondition string) error

ReplaceFragmentSpreadWithInlineFragment converts a fragment spread in place while preserving its identity, position, span, parent, and directives.

func (*Editor) ReplaceName

func (e *Editor) ReplaceName(id NodeID, name string) error

type FieldSpec

type FieldSpec struct {
	Name       string
	Alias      string
	Arguments  []Argument
	Directives []Directive
}

type Kind

type Kind uint8
const (
	KindInvalid Kind = iota
	KindDocument
	KindOperationDefinition
	KindFragmentDefinition
	KindInlineFragment
	KindFragmentSpread
	KindField
	KindSchemaDefinition
	KindDirectiveDefinition
	KindObjectType
	KindInterfaceType
	KindInputObjectType
	KindEnumType
	KindUnionType
	KindScalarType
	KindFieldDefinition
	KindInputValue
	KindEnumValue
	KindDeleted
)

func (Kind) String

func (k Kind) String() string

type Node

type Node struct {
	ID            NodeID
	Kind          Kind
	Name          string
	Alias         string
	OperationType OperationType
	Type          string
	TypeCondition string
	Span          Span
	OriginSpan    Span
	Description   Description
	IsExtension   bool
	Parent        NodeID
	Children      []NodeID
	Arguments     []Argument
	Directives    []Directive
	Variables     []VariableDefinition
	RootOps       []RootOperation
	Interfaces    []string
	UnionMembers  []string
	Locations     []string
	Repeatable    bool
}

type NodeID

type NodeID = uint32
const InvalidNodeID NodeID = 0

type OperationType

type OperationType string
const (
	OperationQuery        OperationType = "query"
	OperationMutation     OperationType = "mutation"
	OperationSubscription OperationType = "subscription"
)

type RootOperation

type RootOperation struct {
	Operation OperationType
	Type      string
}

type SelectionBuilder

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

func (*SelectionBuilder) Field

func (b *SelectionBuilder) Field(name string) *SelectionBuilder

func (*SelectionBuilder) NodeID

func (b *SelectionBuilder) NodeID() NodeID

type Span

type Span struct {
	Start int
	End   int
}

type Value

type Value struct {
	Kind ValueKind
	Raw  string
}

func RawValue

func RawValue(raw string) Value

type ValueKind

type ValueKind string
const (
	ValueRaw ValueKind = "Raw"
)

type VariableDefinition

type VariableDefinition struct {
	Name         string
	Type         string
	DefaultValue *Value
	Directives   []Directive
}

Jump to

Keyboard shortcuts

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