Documentation ¶
Overview ¶
Package astnormalization helps to transform parsed GraphQL AST's into a easier to use structure.
Example ¶
This examples shows how the normalization package helps "simplifying" a GraphQL AST.
Input:
subscription sub { ... multipleSubscriptions ... on Subscription { newMessage { body sender } } } fragment newMessageFields on Message { body: body sender ... on Body { body } } fragment multipleSubscriptions on Subscription { newMessage { body sender } newMessage { ... newMessageFields } newMessage { body body sender } ... on Subscription { newMessage { body sender } } disallowedSecondRootField }
Output:
subscription sub { newMessage { body sender } disallowedSecondRootField } fragment newMessageFields on Message { body sender } fragment multipleSubscriptions on Subscription { newMessage { body sender } disallowedSecondRootField }
Index ¶
- func InlineFragmentAddOnType(walker *astvisitor.Walker)
- func NormalizeDefinition(definition *ast.Document, report *operationreport.Report)
- func NormalizeNamedOperation(operation, definition *ast.Document, operationName []byte, ...)
- func NormalizeOperation(operation, definition *ast.Document, report *operationreport.Report)
- func NormalizeSubgraphSDL(definition *ast.Document, report *operationreport.Report)
- type AbstractFieldNormalizer
- type DefinitionNormalizer
- type Depth
- type Depths
- type FragmentDefinitionRemoval
- type FragmentSpreadDepth
- type OperationNormalizer
- type Option
- type SubgraphSDLNormalizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InlineFragmentAddOnType ¶
func InlineFragmentAddOnType(walker *astvisitor.Walker)
InlineFragmentAddOnType adds on type condition to inline fragments of the same type this is needed for the planner to work correctly Such typename will not be printed by astprinter
func NormalizeDefinition ¶
func NormalizeDefinition(definition *ast.Document, report *operationreport.Report)
NormalizeDefinition creates a default DefinitionNormalizer and applies all rules to a given AST In case you're using DefinitionNormalizer in a hot path you shouldn't be using this function. Create a new DefinitionNormalizer using NewDefinitionNormalizer() instead and re-use it.
func NormalizeNamedOperation ¶
func NormalizeNamedOperation(operation, definition *ast.Document, operationName []byte, report *operationreport.Report)
func NormalizeOperation ¶
func NormalizeOperation(operation, definition *ast.Document, report *operationreport.Report)
NormalizeOperation creates a default Normalizer and applies all rules to a given AST In case you're using OperationNormalizer in a hot path you shouldn't be using this function. Create a new OperationNormalizer using NewNormalizer() instead and re-use it.
func NormalizeSubgraphSDL ¶
func NormalizeSubgraphSDL(definition *ast.Document, report *operationreport.Report)
Types ¶
type AbstractFieldNormalizer ¶
type AbstractFieldNormalizer struct { *astvisitor.Walker // contains filtered or unexported fields }
func (*AbstractFieldNormalizer) AllowVisitor ¶
func (v *AbstractFieldNormalizer) AllowVisitor(kind astvisitor.VisitorKind, ref int, visitor interface{}, skipFor astvisitor.SkipVisitors) bool
func (*AbstractFieldNormalizer) EnterField ¶
func (v *AbstractFieldNormalizer) EnterField(ref int)
func (*AbstractFieldNormalizer) LeaveField ¶
func (v *AbstractFieldNormalizer) LeaveField(ref int)
func (*AbstractFieldNormalizer) Normalize ¶
func (v *AbstractFieldNormalizer) Normalize() error
type DefinitionNormalizer ¶
type DefinitionNormalizer struct {
// contains filtered or unexported fields
}
DefinitionNormalizer walks a given AST and applies all registered rules
func NewDefinitionNormalizer ¶
func NewDefinitionNormalizer() *DefinitionNormalizer
NewDefinitionNormalizer creates a new DefinitionNormalizer and sets up all default rules
func NewSubgraphDefinitionNormalizer ¶
func NewSubgraphDefinitionNormalizer() *DefinitionNormalizer
func (*DefinitionNormalizer) NormalizeDefinition ¶
func (o *DefinitionNormalizer) NormalizeDefinition(definition *ast.Document, report *operationreport.Report)
NormalizeDefinition applies all registered rules to the AST
type Depth ¶
type Depth struct { SpreadRef int Depth int SpreadName ast.ByteSlice // contains filtered or unexported fields }
Depth holds all necessary information to understand the Depth of a Fragment Node
type FragmentDefinitionRemoval ¶
type FragmentDefinitionRemoval struct { }
type FragmentSpreadDepth ¶
type FragmentSpreadDepth struct {
// contains filtered or unexported fields
}
FragmentSpreadDepth is a helper for nested Fragments to calculate the actual depth of a Fragment Node
func (*FragmentSpreadDepth) Get ¶
func (r *FragmentSpreadDepth) Get(operation, definition *ast.Document, report *operationreport.Report, depths *Depths)
Get returns all FragmentSpread Depths for a given AST
type OperationNormalizer ¶
type OperationNormalizer struct {
// contains filtered or unexported fields
}
OperationNormalizer walks a given AST and applies all registered rules
func NewNormalizer ¶
func NewNormalizer(removeFragmentDefinitions, extractVariables bool) *OperationNormalizer
NewNormalizer creates a new OperationNormalizer and sets up all default rules
func NewWithOpts ¶
func NewWithOpts(opts ...Option) *OperationNormalizer
NewWithOpts creates a new OperationNormalizer with Options
func (*OperationNormalizer) NormalizeNamedOperation ¶
func (o *OperationNormalizer) NormalizeNamedOperation(operation, definition *ast.Document, operationName []byte, report *operationreport.Report)
NormalizeNamedOperation applies all registered rules to one specific named operation in the AST
func (*OperationNormalizer) NormalizeOperation ¶
func (o *OperationNormalizer) NormalizeOperation(operation, definition *ast.Document, report *operationreport.Report)
NormalizeOperation applies all registered rules to the AST
type Option ¶
type Option func(options *options)
func WithExtractVariables ¶
func WithExtractVariables() Option
func WithInlineFragmentSpreads ¶
func WithInlineFragmentSpreads() Option
func WithNormalizeDefinition ¶
func WithNormalizeDefinition() Option
func WithRemoveFragmentDefinitions ¶
func WithRemoveFragmentDefinitions() Option
func WithRemoveNotMatchingOperationDefinitions ¶
func WithRemoveNotMatchingOperationDefinitions() Option
func WithRemoveUnusedVariables ¶
func WithRemoveUnusedVariables() Option
type SubgraphSDLNormalizer ¶
type SubgraphSDLNormalizer struct {
// contains filtered or unexported fields
}
func NewSubgraphSDLNormalizer ¶
func NewSubgraphSDLNormalizer() *SubgraphSDLNormalizer
func (*SubgraphSDLNormalizer) NormalizeSubgraphSDL ¶
func (s *SubgraphSDLNormalizer) NormalizeSubgraphSDL(definition *ast.Document, report *operationreport.Report)
Source Files ¶
- abstract_field_normalizer.go
- astnormalization.go
- definition_normalization.go
- directive_include_skip.go
- enum_type_extending.go
- extends_directive.go
- field_deduplication.go
- field_selection_merging.go
- fragment_definition_removal.go
- fragment_spread_inlining.go
- fragmentspread_depth.go
- implicit_extend_root_operation.go
- implicit_schema_definition.go
- inject_input_default_values.go
- inline_fragment_add_on_type.go
- inline_fragment_selection_merging.go
- inline_selections_from_inline_fragments.go
- input_coercion_for_list.go
- input_object_type_extending.go
- interface_type_extending.go
- object_type_extending.go
- operation_definition_removal.go
- remove_self_aliasing.go
- remove_type_extensions.go
- scalar_type_extending.go
- subgraph_sdl_normalization.go
- union_type_extending.go
- variables_default_value_extraction.go
- variables_extraction.go
- variables_unused_deletion.go