Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

QueryDepth::nodeDepthprotectedWC 1.0

Method of the class: QueryDepth{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->nodeDepth( $node, $depth, $maxDepth ): int;
$node(Node) (required)
.
$depth(int)
.
$maxDepth(int)
.

QueryDepth::nodeDepth() code WC 10.9.1

protected function nodeDepth(Node $node, int $depth = 0, int $maxDepth = 0): int
{
    switch (true) {
        case $node instanceof FieldNode:
            // node has children?
            if ($node->selectionSet !== null) {
                // update maxDepth if needed
                if ($depth > $maxDepth) {
                    $maxDepth = $depth;
                }

                $maxDepth = $this->fieldDepth($node, $depth + 1, $maxDepth);
            }

            break;

        case $node instanceof InlineFragmentNode:
            $maxDepth = $this->fieldDepth($node, $depth, $maxDepth);

            break;

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

            if ($fragment !== null) {
                $name = $fragment->name->value;
                if (isset($this->calculatedFragments[$name])) {
                    return $this->maxQueryDepth + 1;
                }

                $this->calculatedFragments[$name] = true;
                $maxDepth = $this->fieldDepth($fragment, $depth, $maxDepth);
                unset($this->calculatedFragments[$name]);
            }

            break;
    }

    return $maxDepth;
}