Automattic\WooCommerce\Internal\Api
QueryComplexityRule::nodeComplexity
Score a single selection. Named fragments are scored once and the result reused for every spread; everything else is delegated to the stock rule.
Method of the class: QueryComplexityRule{}
No Hooks.
Returns
int. The complexity of the selection.
Usage
// protected - for code of main (parent) or child class $result = $this->nodeComplexity( $node ): int;
- $node(SelectionNode) (required)
- The selection to score.
QueryComplexityRule::nodeComplexity() QueryComplexityRule::nodeComplexity code WC 11.1.2
protected function nodeComplexity( SelectionNode $node ): int {
if ( ! $node instanceof FragmentSpreadNode ) {
return parent::nodeComplexity( $node );
}
$fragment = $this->getFragment( $node );
if ( is_null( $fragment ) ) {
return 0;
}
$name = $fragment->name->value;
if ( array_key_exists( $name, $this->fragment_complexities ) ) {
return $this->fragment_complexities[ $name ];
}
// A fragment that (transitively) spreads itself has unbounded
// complexity. NoFragmentCycles reports the actual error.
if ( isset( $this->fragments_in_progress[ $name ] ) ) {
return self::COMPLEXITY_CEILING;
}
$this->fragments_in_progress[ $name ] = true;
try {
$complexity = $this->fieldComplexity( $fragment->selectionSet );
} finally {
unset( $this->fragments_in_progress[ $name ] );
}
$this->fragment_complexities[ $name ] = $complexity;
return $complexity;
}