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 ¶
- func MergeDefinitionWithBaseSchema(definition *ast.Document) error
- func MergeDefinitionWithBaseSchemaWithInternal(definition *ast.Document, includeInternal bool) error
- func MergeOperationDocuments(operationName string, members []OperationMergeMember) (*ast.Document, error)
- type OperationMergeMember
- type Precedence
- type Transformable
- type Transformer
- func (t *Transformer) AppendSelectionSet(precedence Precedence, ref int, appendRef int)
- func (t *Transformer) ApplyTransformations(transformable Transformable)
- func (t *Transformer) DeleteRootNode(precedence Precedence, node ast.Node)
- func (t *Transformer) EmptySelectionSet(precedence Precedence, ref int)
- func (t *Transformer) Reset()
- type TypeNameVisitor
- func (v *TypeNameVisitor) EnterDocument(definition, _ *ast.Document)
- func (v *TypeNameVisitor) ExtendSchema(definition *ast.Document) error
- func (v *TypeNameVisitor) LeaveInterfaceTypeDefinition(ref int)
- func (v *TypeNameVisitor) LeaveObjectTypeDefinition(ref int)
- func (v *TypeNameVisitor) LeaveUnionTypeDefinition(ref int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeDefinitionWithBaseSchemaWithInternal ¶ added in v2.8.0
func MergeOperationDocuments ¶ added in v2.16.0
func MergeOperationDocuments(operationName string, members []OperationMergeMember) (*ast.Document, error)
MergeOperationDocuments builds a new document with a single query operation containing every member's root selection aliased and guarded by @include(if: $IncludeVariable). Variable definitions are emitted per member in document order followed by that member's synthetic include definition. Each member's root selection must be a single field; fragment spreads in member documents are rejected. TODO: Directives on operations are not handled (merged).
Types ¶
type OperationMergeMember ¶ added in v2.16.0
type OperationMergeMember struct {
// Document holds a single query operation definition to merge. Ownership is
// not transferred; the document is read, never mutated.
Document *ast.Document
// Alias is applied to the member's root field ("f1").
Alias string
// IncludeVariable is the synthetic Boolean! variable name guarding the
// member's root field ("includeF1").
IncludeVariable string
// VariableRename maps every original variable name (definitions and
// references) to its merged name. Callers must supply a total mapping over
// the member's variable definitions.
VariableRename map[string]string
}
OperationMergeMember describes one operation document to fold into a merged operation. Its single root selection is imported under Alias, guarded by @include(if: $IncludeVariable), with every variable reference and definition renamed through VariableRename.
type Precedence ¶
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
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)