operation_complexity

package
v2.0.0-rc.130 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

package operation_complexity implements two common algorithms used by GitHub to calculate GraphQL query complexity

1. Node count, the maximum number of Nodes a query may return 2. Complexity, the maximum number of Node requests that might be needed to execute the query

OperationComplexityEstimator takes a schema definition and a query and then walks recursively through the query to calculate both variables.

The calculation can be influenced by integer arguments on fields that indicate the amount of Nodes returned by a field.

To help the algorithm understand your schema you could make use of these two directives:

- directive @nodeCountMultiply on ARGUMENT_DEFINITION - directive @nodeCountSkip on FIELD

nodeCountMultiply: Indicates that the Int value the directive is applied on should be used as a Node multiplier

nodeCountSkip: Indicates that the algorithm should skip this Node. This is useful to whitelist certain query paths, e.g. for introspection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateOperationComplexity

func CalculateOperationComplexity(operation, definition *ast.Document, report *operationreport.Report) (OperationStats, []RootFieldStats)

Types

type OperationComplexityEstimator

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

func NewOperationComplexityEstimator

func NewOperationComplexityEstimator() *OperationComplexityEstimator

func (*OperationComplexityEstimator) Do

func (n *OperationComplexityEstimator) Do(operation, definition *ast.Document, report *operationreport.Report) (OperationStats, []RootFieldStats)

type OperationStats

type OperationStats struct {
	NodeCount  int
	Complexity int
	Depth      int
}

type RootFieldStats

type RootFieldStats struct {
	TypeName  string
	FieldName string
	Alias     string
	Stats     OperationStats
}

Jump to

Keyboard shortcuts

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