astnormalization

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeDefinition added in v1.18.0

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 added in v1.22.0

func NormalizeSubgraphSDL(definition *ast.Document, report *operationreport.Report)

Types

type DefinitionNormalizer added in v1.18.0

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

DefinitionNormalizer walks a given AST and applies all registered rules

func NewDefinitionNormalizer added in v1.18.0

func NewDefinitionNormalizer() *DefinitionNormalizer

NewDefinitionNormalizer creates a new DefinitionNormalizer and sets up all default rules

func (*DefinitionNormalizer) NormalizeDefinition added in v1.18.0

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 Depths

type Depths []Depth

func (Depths) ByRef

func (d Depths) ByRef(ref int) (int, bool)

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 WithNormalizeDefinition added in v1.18.0

func WithNormalizeDefinition() Option

func WithRemoveFragmentDefinitions

func WithRemoveFragmentDefinitions() Option

func WithRemoveUnusedVariables

func WithRemoveUnusedVariables() Option

type SubgraphSDLNormalizer added in v1.22.0

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

func NewSubgraphSDLNormalizer added in v1.22.0

func NewSubgraphSDLNormalizer() *SubgraphSDLNormalizer

func (*SubgraphSDLNormalizer) NormalizeSubgraphSDL added in v1.22.0

func (s *SubgraphSDLNormalizer) NormalizeSubgraphSDL(definition *ast.Document, report *operationreport.Report)

Jump to

Keyboard shortcuts

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