Automattic\WooCommerce\Internal\Api

QueryComplexityRule::directiveExcludesField │ protected │ WC 1.0

Whether @include / @skip directives exclude the field from execution.

Same semantics as the stock rule, but variable values are coerced once per document (see {@see self::get_coerced_variable_values()}).

Method of the class: QueryComplexityRule{}

No Hooks.

Returns

bool. True when the field will not be executed.

Usage

// protected - for code of main (parent) or child class
$result = $this->directiveExcludesField( $node ): bool;
$node(FieldNode) (required)
The field node.

QueryComplexityRule::directiveExcludesField() code WC 11.1.2

protected function directiveExcludesField( FieldNode $node ): bool {
	foreach ( $node->directives as $directive_node ) {
		$directive_name = $directive_node->name->value;

		if ( Directive::INCLUDE_NAME === $directive_name ) {
			$include_arguments = Values::getArgumentValues(
				Directive::includeDirective(),
				$directive_node,
				$this->get_coerced_variable_values()
			);
			if ( false === $include_arguments['if'] ) {
				return true;
			}
		} elseif ( Directive::SKIP_NAME === $directive_name ) {
			$skip_arguments = Values::getArgumentValues(
				Directive::skipDirective(),
				$directive_node,
				$this->get_coerced_variable_values()
			);
			if ( true === $skip_arguments['if'] ) {
				return true;
			}
		}
	}

	return false;
}