Automattic\WooCommerce\Vendor\GraphQL\Utils
BreakingChangesFinder::findTypesAddedToUnions
Given two schemas, returns an Array containing descriptions of any dangerous changes in the newSchema related to adding types to a union type.
Method of the class: BreakingChangesFinder{}
No Hooks.
Returns
Array
Usage
$result = BreakingChangesFinder::findTypesAddedToUnions( $oldSchema, $newSchema ): array;
BreakingChangesFinder::findTypesAddedToUnions() BreakingChangesFinder::findTypesAddedToUnions code WC 10.9.1
public static function findTypesAddedToUnions(
Schema $oldSchema,
Schema $newSchema
): array {
$oldTypeMap = $oldSchema->getTypeMap();
$newTypeMap = $newSchema->getTypeMap();
$typesAddedToUnion = [];
foreach ($newTypeMap as $typeName => $newType) {
$oldType = $oldTypeMap[$typeName] ?? null;
if (! ($oldType instanceof UnionType) || ! ($newType instanceof UnionType)) {
continue;
}
$typeNamesInOldUnion = [];
foreach ($oldType->getTypes() as $type) {
$typeNamesInOldUnion[$type->name] = true;
}
foreach ($newType->getTypes() as $type) {
if (! isset($typeNamesInOldUnion[$type->name])) {
$typesAddedToUnion[] = [
'type' => self::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION,
'description' => "{$type->name} was added to union type {$typeName}.",
];
}
}
}
return $typesAddedToUnion;
}