Automattic\WooCommerce\Vendor\GraphQL\Type
SchemaValidationContext::validateUnionMembers
Method of the class: SchemaValidationContext{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->validateUnionMembers( $union ): void;
- $union(UnionType) (required)
- .
SchemaValidationContext::validateUnionMembers() SchemaValidationContext::validateUnionMembers code WC 10.9.1
private function validateUnionMembers(UnionType $union): void
{
$memberTypes = $union->getTypes();
if ($memberTypes === []) {
$this->reportError(
"Union type {$union->name} must define one or more member types.",
$this->getAllNodes($union)
);
}
$includedTypeNames = [];
foreach ($memberTypes as $memberType) {
// @phpstan-ignore-next-line The generic type says this should not happen, but a user may use it wrong nonetheless
if (! $memberType instanceof ObjectType) {
$notObjectType = Utils::printSafe($memberType);
$this->reportError(
"Union type {$union->name} can only include Object types, it cannot include {$notObjectType}.",
$this->getUnionMemberTypeNodes($union, $notObjectType)
);
continue;
}
if (isset($includedTypeNames[$memberType->name])) {
$this->reportError(
"Union type {$union->name} can only include type {$memberType->name} once.",
$this->getUnionMemberTypeNodes($union, $memberType->name)
);
continue;
}
$includedTypeNames[$memberType->name] = true;
}
}