Automattic\WooCommerce\Internal\Api

QueryComplexityRule::getVisitor │ public │ WC 1.0

Reset the per-document state, then replace the stock SELECTION_SET callback, which re-collects field definitions through every fragment reachable from each selection set, with recording the definition that TypeInfo already resolves as the visitor enters each field.

Method of the class: QueryComplexityRule{}

No Hooks.

Returns

array. The visitor definition.

Usage

$QueryComplexityRule = new QueryComplexityRule();
$QueryComplexityRule->getVisitor( $context ): array;
$context(QueryValidationContext) (required)
The validation context.

QueryComplexityRule::getVisitor() code WC 11.1.2

public function getVisitor( QueryValidationContext $context ): array {
	$this->fragment_complexities   = array();
	$this->fragments_in_progress   = array();
	$this->coerced_variable_values = null;
	$this->field_definitions       = array();

	$visitor = parent::getVisitor( $context );
	if ( array() === $visitor ) {
		// The rule is disabled.
		return $visitor;
	}

	unset( $visitor[ NodeKind::SELECTION_SET ] );
	$visitor[ NodeKind::FIELD ] = function ( FieldNode $node ) use ( $context ): void {
		$this->field_definitions[ spl_object_id( $node ) ] = $context->getFieldDef();
	};

	return $visitor;
}