operation_complexity

package
v2.0.0-rc.238 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 3 Imported by: 3

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 number of Nodes returned by a field.

To help the algorithm understand the schema 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. It can be used to allowlist certain query paths.

Note: Introspection fields (__schema and __type) are automatically skipped from complexity calculations by default.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateOperationComplexity deprecated

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

Deprecated: use NewOperationComplexityEstimator.

Types

type OperationComplexityEstimator

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

func NewOperationComplexityEstimator

func NewOperationComplexityEstimator(skipIntrospection bool) *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