Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

OverlappingFieldsCanBeMerged::collectConflictsBetweenFragmentsprotectedWC 1.0

Collect all conflicts found between two fragments, 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->collectConflictsBetweenFragments( $context, $conflicts, $areMutuallyExclusive, $fragmentName1, $fragmentName2 ): void;
$context(QueryValidationContext) (required)
.
$conflicts(array) (required)
.
$areMutuallyExclusive(true|false) (required)
.
$fragmentName1(string) (required)
.
$fragmentName2(string) (required)
.

OverlappingFieldsCanBeMerged::collectConflictsBetweenFragments() code WC 10.9.1

protected function collectConflictsBetweenFragments(
    QueryValidationContext $context,
    array &$conflicts,
    bool $areMutuallyExclusive,
    string $fragmentName1,
    string $fragmentName2
): void {
    // No need to compare a fragment to itself.
    if ($fragmentName1 === $fragmentName2) {
        return;
    }

    // Memoize so two fragments are not compared for conflicts more than once.
    if (
        $this->comparedFragmentPairs->has(
            $fragmentName1,
            $fragmentName2,
            $areMutuallyExclusive
        )
    ) {
        return;
    }

    $this->comparedFragmentPairs->add(
        $fragmentName1,
        $fragmentName2,
        $areMutuallyExclusive
    );

    $fragment1 = $context->getFragment($fragmentName1);
    $fragment2 = $context->getFragment($fragmentName2);
    if ($fragment1 === null || $fragment2 === null) {
        return;
    }

    [$fieldMap1, $fragmentNames1] = $this->getReferencedFieldsAndFragmentNames(
        $context,
        $fragment1
    );
    [$fieldMap2, $fragmentNames2] = $this->getReferencedFieldsAndFragmentNames(
        $context,
        $fragment2
    );

    // (F) First, collect all conflicts between these two collections of fields
    // (not including any nested fragments).
    $this->collectConflictsBetween(
        $context,
        $conflicts,
        $areMutuallyExclusive,
        $fieldMap1,
        $fieldMap2
    );

    // (G) Then collect conflicts between the first fragment and any nested
    // fragments spread in the second fragment.
    $fragmentNames2Length = count($fragmentNames2);
    for ($j = 0; $j < $fragmentNames2Length; ++$j) {
        $this->collectConflictsBetweenFragments(
            $context,
            $conflicts,
            $areMutuallyExclusive,
            $fragmentName1,
            $fragmentNames2[$j]
        );
    }

    // (G) Then collect conflicts between the second fragment and any nested
    // fragments spread in the first fragment.
    $fragmentNames1Length = count($fragmentNames1);
    for ($i = 0; $i < $fragmentNames1Length; ++$i) {
        $this->collectConflictsBetweenFragments(
            $context,
            $conflicts,
            $areMutuallyExclusive,
            $fragmentNames1[$i],
            $fragmentName2
        );
    }
}