Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules
OverlappingFieldsCanBeMerged::findConflict
Determines if there is a conflict between two particular fields, including comparing their sub-fields.
Method of the class: OverlappingFieldsCanBeMerged{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->findConflict( $context, $parentFieldsAreMutuallyExclusive, $responseName, $field1, $field2 ): ?array;
- $context(QueryValidationContext) (required)
- .
- $parentFieldsAreMutuallyExclusive(true|false) (required)
- .
- $responseName(string) (required)
- .
- $field1(array) (required)
- .
- $field2(array) (required)
- .
OverlappingFieldsCanBeMerged::findConflict() OverlappingFieldsCanBeMerged::findConflict code WC 10.9.1
protected function findConflict(
QueryValidationContext $context,
bool $parentFieldsAreMutuallyExclusive,
string $responseName,
array $field1,
array $field2
): ?array {
[$parentType1, $ast1, $def1] = $field1;
[$parentType2, $ast2, $def2] = $field2;
// If it is known that two fields could not possibly apply at the same
// time, due to the parent types, then it is safe to permit them to diverge
// in aliased field or arguments used as they will not present any ambiguity
// by differing.
// It is known that two parent types could never overlap if they are
// different Object types. Interface or Union types might overlap - if not
// in the current state of the schema, then perhaps in some future version,
// thus may not safely diverge.
$areMutuallyExclusive = $parentFieldsAreMutuallyExclusive
|| (
$parentType1 !== $parentType2
&& $parentType1 instanceof ObjectType
&& $parentType2 instanceof ObjectType
);
// The return type for each field.
$type1 = $def1 === null
? null
: $def1->getType();
$type2 = $def2 === null
? null
: $def2->getType();
if (! $areMutuallyExclusive) {
// Two aliases must refer to the same field.
$name1 = $ast1->name->value;
$name2 = $ast2->name->value;
if ($name1 !== $name2) {
return [
[$responseName, "{$name1} and {$name2} are different fields"],
[$ast1],
[$ast2],
];
}
if (! $this->sameArguments($ast1->arguments, $ast2->arguments)) {
return [
[$responseName, 'they have differing arguments'],
[$ast1],
[$ast2],
];
}
}
if (
$type1 !== null
&& $type2 !== null
&& $this->doTypesConflict($type1, $type2)
) {
return [
[$responseName, "they return conflicting types {$type1} and {$type2}"],
[$ast1],
[$ast2],
];
}
// Collect and compare sub-fields. Use the same "visited fragment names" list
// for both collections so fields in a fragment reference are never
// compared to themselves.
$selectionSet1 = $ast1->selectionSet;
$selectionSet2 = $ast2->selectionSet;
if ($selectionSet1 !== null && $selectionSet2 !== null) {
$conflicts = $this->findConflictsBetweenSubSelectionSets(
$context,
$areMutuallyExclusive,
Type::getNamedType($type1),
$selectionSet1,
Type::getNamedType($type2),
$selectionSet2
);
return $this->subfieldConflicts(
$conflicts,
$responseName,
$ast1,
$ast2
);
}
return null;
}