Automattic\WooCommerce\Api\Infrastructure

GraphQLControllerBase::walk_depth_tree_onlyprivateWC 1.0

Walk a selection set counting only fields with child selections, matching webonyx's QueryDepth rule so the returned number is directly comparable to the configured "Maximum query depth" limit.

Method of the class: GraphQLControllerBase{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->walk_depth_tree_only( ?SelectionSetNode $selection_set, $depth ): int;
?SelectionSetNode $selection_set(required)
.
$depth(int) (required)
The depth at which fields in this selection set sit.

GraphQLControllerBase::walk_depth_tree_only() code WC 10.9.4

private function walk_depth_tree_only( ?SelectionSetNode $selection_set, int $depth ): int {
	if ( null === $selection_set ) {
		return 0;
	}

	$max = 0;
	foreach ( $selection_set->selections as $selection ) {
		if ( $selection instanceof FieldNode ) {
			if ( null !== $selection->selectionSet ) {
				$max = max( $max, $depth, $this->walk_depth_tree_only( $selection->selectionSet, $depth + 1 ) );
			}
		} elseif ( $selection instanceof InlineFragmentNode ) {
			$max = max( $max, $this->walk_depth_tree_only( $selection->selectionSet, $depth ) );
		}
	}

	return $max;
}