diff --git a/src/Utils/FindBreakingChanges.php b/src/Utils/FindBreakingChanges.php index 7864508..51134c4 100644 --- a/src/Utils/FindBreakingChanges.php +++ b/src/Utils/FindBreakingChanges.php @@ -116,7 +116,7 @@ class FindBreakingChanges $newTypeKindName = self::typeKindName($newTypeDefinition); $breakingChanges[] = [ 'type' => self::BREAKING_CHANGE_TYPE_CHANGED, - 'description' => "${$typeName} changed from ${oldTypeKindName} to ${newTypeKindName}." + 'description' => "${typeName} changed from ${oldTypeKindName} to ${newTypeKindName}." ]; } } diff --git a/tests/Utils/FindBreakingChangesTest.php b/tests/Utils/FindBreakingChangesTest.php index cb0c220..e2cc9b2 100644 --- a/tests/Utils/FindBreakingChangesTest.php +++ b/tests/Utils/FindBreakingChangesTest.php @@ -5,8 +5,10 @@ namespace GraphQL\Tests\Utils; +use GraphQL\Type\Definition\InterfaceType; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; +use GraphQL\Type\Definition\UnionType; use GraphQL\Type\Schema; use GraphQL\Utils\FindBreakingChanges; @@ -64,4 +66,49 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase $this->assertEquals([], FindBreakingChanges::findRemovedTypes($oldSchema, $oldSchema)); } + public function testShouldDetectTypeChanges() + { + $objectType = new ObjectType([ + 'name' => 'ObjectType', + 'fields' => [ + 'field1' => ['type' => Type::string()], + ] + ]); + + $interfaceType = new InterfaceType([ + 'name' => 'Type1', + 'fields' => [ + 'field1' => ['type' => Type::string()] + ] + ]); + + $unionType = new UnionType([ + 'name' => 'Type1', + 'types' => [new ObjectType(['name' => 'blah'])], + ]); + + $oldSchema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'root', + 'fields' => [ + 'type1' => $interfaceType + ] + ]) + ]); + + $newSchema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'root', + 'fields' => [ + 'type1' => $unionType + ] + ]) + ]); + + $this->assertEquals( + ['type' => FindBreakingChanges::BREAKING_CHANGE_TYPE_CHANGED, 'description' => 'Type1 changed from an Interface type to a Union type.'], + FindBreakingChanges::findTypesThatChangedKind($oldSchema, $newSchema)[0] + ); + } + } \ No newline at end of file