Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

QueryComplexity::nodeComplexityprotectedWC 1.0

Method of the class: QueryComplexity{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->nodeComplexity( $node ): int;
$node(SelectionNode) (required)
.

QueryComplexity::nodeComplexity() code WC 11.0.0

protected function nodeComplexity(SelectionNode $node): int
{
    switch (true) {
        case $node instanceof FieldNode:
            // Exclude __schema field and all nested content from complexity calculation
            if ($node->name->value === Introspection::SCHEMA_FIELD_NAME) {
                return 0;
            }

            if ($this->directiveExcludesField($node)) {
                return 0;
            }

            $childrenComplexity = isset($node->selectionSet)
                ? $this->fieldComplexity($node->selectionSet)
                : 0;

            $fieldDef = $this->fieldDefinition($node);
            if ($fieldDef instanceof FieldDefinition && $fieldDef->complexityFn !== null) {
                $fieldArguments = $this->buildFieldArguments($node);

                return ($fieldDef->complexityFn)($childrenComplexity, $fieldArguments);
            }

            return $childrenComplexity + 1;

        case $node instanceof InlineFragmentNode:
            return $this->fieldComplexity($node->selectionSet);

        case $node instanceof FragmentSpreadNode:
            $fragment = $this->getFragment($node);

            if ($fragment !== null) {
                return $this->fieldComplexity($fragment->selectionSet);
            }
    }

    return 0;
}