Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DepthCalculator.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use GraphQL\Language\AST\FieldNode;
11 
16 {
23  public function calculate(FieldNode $fieldNode) : int
24  {
25  $selections = $fieldNode->selectionSet->selections ?? [];
26  $depth = count($selections) ? 1 : 0;
27  $childrenDepth = [0];
28  foreach ($selections as $node) {
29  if ($node->kind === 'InlineFragment') {
30  continue;
31  }
32 
33  $childrenDepth[] = $this->calculate($node);
34  }
35 
36  return $depth + max($childrenDepth);
37  }
38 }