mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 04:46:04 +03:00
testDetectsAdditionsToUnionType
This commit is contained in:
parent
e0a63ec792
commit
533b8b8b5f
@ -433,12 +433,13 @@ class FindBreakingChanges
|
||||
Schema $oldSchema, Schema $newSchema
|
||||
)
|
||||
{
|
||||
$oldTypeMap = $oldSchema->getTypeMap();
|
||||
$newTypeMap = $newSchema->getTypeMap();
|
||||
|
||||
$typesAddedToUnion = [];
|
||||
|
||||
foreach ($newTypeMap as $typeName => $oldType) {
|
||||
$newType = isset($newTypeMap[$typeName]) ? $newTypeMap[$typeName] : null;
|
||||
foreach ($newTypeMap as $typeName => $newType) {
|
||||
$oldType = isset($oldTypeMap[$typeName]) ? $oldTypeMap[$typeName] : null;
|
||||
if (!($oldType instanceof UnionType) || !($newType instanceof UnionType)) {
|
||||
continue;
|
||||
}
|
||||
@ -450,7 +451,7 @@ class FindBreakingChanges
|
||||
foreach ($newType->getTypes() as $type) {
|
||||
if (!isset($typeNamesInOldUnion[$type->name])) {
|
||||
$addedTypeName = $type->name;
|
||||
$typesRemovedFromUnion[] = ['type' => self::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION, 'description' => "${addedTypeName} was removed to union type ${typeName}"];
|
||||
$typesAddedToUnion[] = ['type' => self::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION, 'description' => "${addedTypeName} was added to union type ${typeName}"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1326,4 +1326,63 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
|
||||
FindBreakingChanges::findValuesAddedToEnums($oldSchema, $newSchema)[0]
|
||||
);
|
||||
}
|
||||
|
||||
public function testDetectsAdditionsToUnionType() {
|
||||
$type1 = new ObjectType([
|
||||
'name' => 'Type1',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$type1a = new ObjectType([
|
||||
'name' => 'Type1',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$type2 = new ObjectType([
|
||||
'name' => 'Type2',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$oldUnionType = new UnionType([
|
||||
'name' => 'UnionType1',
|
||||
'types' => [$type1],
|
||||
'resolveType' => function () {
|
||||
}
|
||||
]);
|
||||
|
||||
$newUnionType = new UnionType([
|
||||
'name' => 'UnionType1',
|
||||
'types' => [$type1a, $type2],
|
||||
'resolveType' => function () {
|
||||
}
|
||||
]);
|
||||
|
||||
$oldSchema = new Schema([
|
||||
'query' => $this->queryType,
|
||||
'types' => [
|
||||
$oldUnionType
|
||||
]
|
||||
]);
|
||||
|
||||
$newSchema = new Schema([
|
||||
'query' => $this->queryType,
|
||||
'types' => [
|
||||
$newUnionType
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'type' => FindBreakingChanges::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION,
|
||||
'description' => 'Type2 was added to union type UnionType1'
|
||||
],
|
||||
FindBreakingChanges::findTypesAddedToUnions($oldSchema, $newSchema)[0]
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user