Automattic\WooCommerce\Api\Infrastructure
GraphQLControllerBase::walk_depth_in_depth
Walk a selection set counting every field in the deepest chain, leaves included. Produces the "shape" metric surfaced alongside the enforcement metric in debug output.
Method of the class: GraphQLControllerBase{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->walk_depth_in_depth( ?SelectionSetNode $selection_set, $depth ): int;
- ?SelectionSetNode $selection_set(required)
- .
- $depth(int) (required)
- The depth of the selection set's parent.
GraphQLControllerBase::walk_depth_in_depth() GraphQLControllerBase::walk depth in depth code WC 10.9.1
private function walk_depth_in_depth( ?SelectionSetNode $selection_set, int $depth ): int {
if ( null === $selection_set ) {
return $depth;
}
$max = $depth;
foreach ( $selection_set->selections as $selection ) {
if ( $selection instanceof FieldNode ) {
$max = max( $max, $this->walk_depth_in_depth( $selection->selectionSet, $depth + 1 ) );
} elseif ( $selection instanceof InlineFragmentNode ) {
$max = max( $max, $this->walk_depth_in_depth( $selection->selectionSet, $depth ) );
}
}
return $max;
}