diff --git a/src/Utils/FindBreakingChanges.php b/src/Utils/FindBreakingChanges.php index 452430d..a2cab12 100644 --- a/src/Utils/FindBreakingChanges.php +++ b/src/Utils/FindBreakingChanges.php @@ -164,9 +164,10 @@ class FindBreakingChanges } ); if (!$newArgDef) { + $argName = $oldArgDef->name; $breakingChanges[] = [ 'type' => self::BREAKING_CHANGE_ARG_REMOVED, - 'description' => "${$oldTypeName}->${$fieldName} arg ${oldArgName} was removed" + 'description' => "${oldTypeName}->${fieldName} arg ${argName} was removed" ]; } else { $isSafe = self::isChangeSafeForInputObjectFieldOrFieldArg($oldArgDef->getType(), $newArgDef->getType()); diff --git a/tests/Utils/FindBreakingChangesTest.php b/tests/Utils/FindBreakingChangesTest.php index 77ad74c..3af4c83 100644 --- a/tests/Utils/FindBreakingChangesTest.php +++ b/tests/Utils/FindBreakingChangesTest.php @@ -592,4 +592,97 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase FindBreakingChanges::findValuesRemovedFromEnums($oldSchema, $newSchema)[0] ); } + + public function testDetectsRemovalOfFieldArgument() + { + + $oldType = new ObjectType([ + 'name' => 'Type1', + 'fields' => [ + 'field1' => [ + 'type' => Type::string(), + 'args' => [ + 'name' => Type::string() + ] + ] + ] + ]); + + + $inputType = new InputObjectType([ + 'name' => 'InputType1', + 'fields' => [ + 'field1' => Type::string() + ] + ]); + + $oldInterfaceType = new InterfaceType([ + 'name' => 'Interface1', + 'fields' => [ + 'field1' => [ + 'type' => Type::string(), + 'args' => [ + 'arg1' => Type::boolean(), + 'objectArg' => $inputType + ] + ] + ] + ]); + + $newType = new ObjectType([ + 'name' => 'Type1', + 'fields' => [ + 'field1' => [ + 'type' => Type::string(), + 'args' => [] + ] + ] + ]); + + $newInterfaceType = new InterfaceType([ + 'name' => 'Interface1', + 'fields' => [ + 'field1' => Type::string() + ] + ]); + + $oldSchema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'root', + 'fields' => [ + 'type1' => $oldType, + 'type2' => $oldInterfaceType + ], + 'types' => [$oldType, $oldInterfaceType] + ]) + ]); + + $newSchema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'root', + 'fields' => [ + 'type1' => $newType, + 'type2' => $newInterfaceType + ], + 'types' => [$newType, $newInterfaceType] + ]) + ]); + + $expectedChanges = [ + [ + 'type' => FindBreakingChanges::BREAKING_CHANGE_ARG_REMOVED, + 'description' => 'Type1->field1 arg name was removed', + ], + [ + 'type' => FindBreakingChanges::BREAKING_CHANGE_ARG_REMOVED, + 'description' => 'Interface1->field1 arg arg1 was removed', + ], + [ + 'type' => FindBreakingChanges::BREAKING_CHANGE_ARG_REMOVED, + 'description' => 'Interface1->field1 arg objectArg was removed', + ] + ]; + + $this->assertEquals($expectedChanges, FindBreakingChanges::findArgChanges($oldSchema, $newSchema)['breakingChanges']); + } } \ No newline at end of file