asttransform

package
v2.0.0-rc.112 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package asttransform contains a set of helper methods to make recursive ast transformations possible.

This is especially useful for ast normalization for nested fragment inlining.

This package is necessary to make AST transformations possible while walking an AST recusively. In order to resolve dependencies in a tree (inline fragments & fragment spreads) it's necessary to resolve them in a specific order. The right order to not mess things up is from the deepest level up to the root. Therefore, this package is used to register transformations while walking an AST in order to bring all transformations in the right order. Only then, when all transformations are in the right order according to depth, it's possible to safely apply them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeDefinitionWithBaseSchema

func MergeDefinitionWithBaseSchema(definition *ast.Document) error

Types

type Precedence

type Precedence struct {
	Depth int
	Order int
}

Precedence defines Depth and Order of each transformation

type Transformable

type Transformable interface {
	// DeleteRootNode marks a Node for deletion
	DeleteRootNode(node ast.Node)
	// EmptySelectionSet marks a selectionset for emptying
	EmptySelectionSet(ref int)
	// AppendSelectionSet marks to append a reference to a selectionset
	AppendSelectionSet(ref int, appendRef int)
}

Transformable defines the interface which needs to be implemented in order to apply Transformations This needs to be implemented by any AST in order to be transformable

type Transformer

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

Transformer takes transformation registrations and applies them

func (*Transformer) AppendSelectionSet

func (t *Transformer) AppendSelectionSet(precedence Precedence, ref int, appendRef int)

AppendSelectionSet registers an action to append a selection to a selectionset

func (*Transformer) ApplyTransformations

func (t *Transformer) ApplyTransformations(transformable Transformable)

ApplyTransformations applies all registered transformations to a transformable

func (*Transformer) DeleteRootNode

func (t *Transformer) DeleteRootNode(precedence Precedence, node ast.Node)

DeleteRootNode registers an action to delete a root node

func (*Transformer) EmptySelectionSet

func (t *Transformer) EmptySelectionSet(precedence Precedence, ref int)

EmptySelectionSet registers an actions to empty a selectionset

func (*Transformer) Reset

func (t *Transformer) Reset()

Reset empties all actions

type TypeNameVisitor

type TypeNameVisitor struct {
	*astvisitor.Walker
	// contains filtered or unexported fields
}

func NewTypeNameVisitor

func NewTypeNameVisitor() *TypeNameVisitor

func (*TypeNameVisitor) EnterDocument

func (v *TypeNameVisitor) EnterDocument(definition, _ *ast.Document)

func (*TypeNameVisitor) ExtendSchema

func (v *TypeNameVisitor) ExtendSchema(definition *ast.Document) error

func (*TypeNameVisitor) LeaveInterfaceTypeDefinition

func (v *TypeNameVisitor) LeaveInterfaceTypeDefinition(ref int)

func (*TypeNameVisitor) LeaveObjectTypeDefinition

func (v *TypeNameVisitor) LeaveObjectTypeDefinition(ref int)

func (*TypeNameVisitor) LeaveUnionTypeDefinition

func (v *TypeNameVisitor) LeaveUnionTypeDefinition(ref int)

Jump to

Keyboard shortcuts

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