Documentation
¶
Overview ¶
Package astnormalization helps to transform parsed GraphQL AST's into a easier to use structure.
Example ¶
This example shows how the normalization package helps "simplify" 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 InlineArgument
- type InlineArgumentsValidationOptions
- type ListInputCoercion
- type NormalizationResult
- type OperationNormalizer
- func (o *OperationNormalizer) NormalizeNamedOperation(operation, definition *ast.Document, operationName []byte, ...)
- func (o *OperationNormalizer) NormalizeNamedOperationWithResult(operation, definition *ast.Document, operationName []byte, ...) *NormalizationResult
- func (o *OperationNormalizer) NormalizeOperation(operation, definition *ast.Document, report *operationreport.Report)
- type Option
- func WithEnableDefer() Option
- func WithExtractVariables() Option
- func WithIgnoreSkipInclude() Option
- func WithInlineArgumentsValidation(opts InlineArgumentsValidationOptions) Option
- func WithInlineFragmentSpreads() Option
- func WithNormalizeDefinition() Option
- func WithPrevalidationRules(rules ...func(walker *astvisitor.Walker)) Option
- func WithRemoveFragmentDefinitions() Option
- func WithRemoveNotMatchingOperationDefinitions() Option
- func WithRemoveUnusedVariables() Option
- type RunOptions
- type SubgraphSDLNormalizer
- type VariablesMapper
- type VariablesNormalizer
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 any, 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 InlineArgument ¶ added in v2.12.0
type InlineArgument struct {
ArgumentName string
AncestorName string
AncestorKind ast.NodeKind
Path string
ValueKind ast.ValueKind
Position position.Position
}
InlineArgument describes a single argument in an operation whose value was supplied inline (a literal) instead of as a variable.
func (InlineArgument) QualifiedName ¶ added in v2.12.0
func (a InlineArgument) QualifiedName() string
type InlineArgumentsValidationOptions ¶ added in v2.12.0
type ListInputCoercion ¶
type ListInputCoercion struct {
// contains filtered or unexported fields
}
func NewListInputCoercion ¶
func NewListInputCoercion() *ListInputCoercion
func (*ListInputCoercion) CoerceInput ¶
type NormalizationResult ¶ added in v2.12.0
type NormalizationResult struct {
InlineArguments []InlineArgument
}
NormalizationResult carries per-run outputs of normalization beyond report errors.
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)
func (*OperationNormalizer) NormalizeNamedOperationWithResult ¶ added in v2.12.0
func (o *OperationNormalizer) NormalizeNamedOperationWithResult( operation, definition *ast.Document, operationName []byte, report *operationreport.Report, runOpts RunOptions, ) *NormalizationResult
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 WithEnableDefer ¶ added in v2.8.0
func WithEnableDefer() Option
func WithExtractVariables ¶
func WithExtractVariables() Option
func WithIgnoreSkipInclude ¶
func WithIgnoreSkipInclude() Option
func WithInlineArgumentsValidation ¶ added in v2.12.0
func WithInlineArgumentsValidation(opts InlineArgumentsValidationOptions) Option
WithInlineArgumentsValidation enables detection of arguments whose values are supplied inline (as literals) instead of as variables. Findings are returned from NormalizeNamedOperationWithResult as a NormalizationResult. When opts.Enforce is set, normalization aborts on the first inline argument and surfaces the error via the report instead of collecting findings.
func WithInlineFragmentSpreads ¶
func WithInlineFragmentSpreads() Option
func WithNormalizeDefinition ¶
func WithNormalizeDefinition() Option
func WithPrevalidationRules ¶ added in v2.8.0
func WithPrevalidationRules(rules ...func(walker *astvisitor.Walker)) Option
func WithRemoveFragmentDefinitions ¶
func WithRemoveFragmentDefinitions() Option
func WithRemoveNotMatchingOperationDefinitions ¶
func WithRemoveNotMatchingOperationDefinitions() Option
func WithRemoveUnusedVariables ¶
func WithRemoveUnusedVariables() Option
type RunOptions ¶ added in v2.12.0
type RunOptions struct {
SkipInlineArguments bool
}
RunOptions are per-call inputs to a normalization run.
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)
type VariablesMapper ¶
type VariablesMapper struct {
// contains filtered or unexported fields
}
func NewVariablesMapper ¶
func NewVariablesMapper() *VariablesMapper
func (*VariablesMapper) NormalizeOperation ¶
func (v *VariablesMapper) NormalizeOperation(operation, definition *ast.Document, report *operationreport.Report) map[string]string
type VariablesNormalizer ¶
type VariablesNormalizer struct {
// contains filtered or unexported fields
}
func NewVariablesNormalizer ¶
func NewVariablesNormalizer() *VariablesNormalizer
func (*VariablesNormalizer) NormalizeOperation ¶
func (v *VariablesNormalizer) NormalizeOperation(operation, definition *ast.Document, report *operationreport.Report) []uploads.UploadPathMapping
Source Files
¶
- abstract_field_normalizer.go
- astnormalization.go
- defer_align_typename_scope.go
- defer_ensure_typename.go
- defer_expand_into_internal.go
- defer_populate_parent_ids.go
- definition_normalization.go
- directive_include_skip.go
- enum_type_extending.go
- extends_directive.go
- field_deduplication.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_arguments.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_mapper.go
- variables_mapping.go
- variables_unused_deletion.go