Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

OverlappingFieldsCanBeMerged::collectConflictsBetweenFieldsAndFragmentprotectedWC 1.0

Collect all conflicts found between a set of fields and a fragment reference including via spreading in any nested fragments.

Method of the class: OverlappingFieldsCanBeMerged{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->collectConflictsBetweenFieldsAndFragment( $context, $conflicts, $comparedFragments, $areMutuallyExclusive, $fieldMap, $fragmentName ): void;
$context(QueryValidationContext) (required)
.
$conflicts(array) (required)
.
$comparedFragments(array<string, true>) (required)
.
$areMutuallyExclusive(true|false) (required)
.
$fieldMap(array) (required)
.
$fragmentName(string) (required)
.

OverlappingFieldsCanBeMerged::collectConflictsBetweenFieldsAndFragment() code WC 11.0.1

protected function collectConflictsBetweenFieldsAndFragment(
    QueryValidationContext $context,
    array &$conflicts,
    array &$comparedFragments,
    bool $areMutuallyExclusive,
    array $fieldMap,
    string $fragmentName
): void {
    if (isset($comparedFragments[$fragmentName])) {
        return;
    }

    $comparedFragments[$fragmentName] = true;

    $fragment = $context->getFragment($fragmentName);
    if ($fragment === null) {
        return;
    }

    [$fieldMap2, $fragmentNames2] = $this->getReferencedFieldsAndFragmentNames(
        $context,
        $fragment
    );

    if ($fieldMap === $fieldMap2) {
        return;
    }

    // (D) First collect any conflicts between the provided collection of fields
    // and the collection of fields represented by the given fragment.
    $this->collectConflictsBetween(
        $context,
        $conflicts,
        $areMutuallyExclusive,
        $fieldMap,
        $fieldMap2
    );

    // (E) Then collect any conflicts between the provided collection of fields
    // and any fragment names found in the given fragment.
    $fragmentNames2Length = count($fragmentNames2);
    for ($i = 0; $i < $fragmentNames2Length; ++$i) {
        $this->collectConflictsBetweenFieldsAndFragment(
            $context,
            $conflicts,
            $comparedFragments,
            $areMutuallyExclusive,
            $fieldMap,
            $fragmentNames2[$i]
        );
    }
}