diff --git a/src/Utils/FindBreakingChanges.php b/src/Utils/FindBreakingChanges.php index c44d78d..aeb1f37 100644 --- a/src/Utils/FindBreakingChanges.php +++ b/src/Utils/FindBreakingChanges.php @@ -410,7 +410,7 @@ class FindBreakingChanges foreach ($oldType->getTypes() as $type) { if (!isset($typeNamesInNewUnion[$type->name])) { $missingTypeName = $type->name; - $typesRemovedFromUnion[] = ['type' => self::BREAKING_CHANGE_TYPE_REMOVED_FROM_UNION, 'description' => "${missingTypeName} was removed from union type ${typeName}"]; + $typesRemovedFromUnion[] = ['type' => self::BREAKING_CHANGE_TYPE_REMOVED_FROM_UNION, 'description' => "${missingTypeName} was removed from union type ${typeName}."]; } } } diff --git a/tests/Utils/FindBreakingChangesTest.php b/tests/Utils/FindBreakingChangesTest.php index ed87628..0600999 100644 --- a/tests/Utils/FindBreakingChangesTest.php +++ b/tests/Utils/FindBreakingChangesTest.php @@ -473,4 +473,76 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase FindBreakingChanges::findFieldsThatChangedType($oldSchema, $newSchema)[0] ); } + + public function testDetectsIfTypeWasRemovedFromUnion() + { + $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() + ] + ]); + + $type3 = new ObjectType([ + 'name' => 'Type3', + 'fields' => [ + 'field1' => Type::string() + ] + ]); + + $oldUnionType = new UnionType([ + 'name' => 'UnionType1', + 'types' => [$type1, $type2], + 'resolveType' => function () { + } + ]); + + + $newUnionType = new UnionType([ + 'name' => 'UnionType1', + 'types' => [$type1a, $type3], + 'resolveType' => function () { + } + ]); + + $oldSchema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'root', + 'fields' => [ + 'type1' => $oldUnionType + ] + ]) + ]); + + $newSchema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'root', + 'fields' => [ + 'type1' => $newUnionType + ] + ]) + ]); + + $this->assertEquals( + [ + 'type' => FindBreakingChanges::BREAKING_CHANGE_TYPE_REMOVED_FROM_UNION, + 'description' => 'Type2 was removed from union type UnionType1.' + ], + FindBreakingChanges::findTypesRemovedFromUnions($oldSchema, $newSchema)[0] + ); + } } \ No newline at end of file