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