Documentation
¶
Overview ¶
Package operation_complexity implements two common algorithms used by GitHub to calculate GraphQL query complexity:
- Node count, the maximum number of Nodes a query may return
- 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 RootFieldStats ¶
type RootFieldStats struct {
TypeName string
FieldName string
Alias string
Stats OperationStats
}