testDetectsRemovalOfFieldArgument

This commit is contained in:
Ben Roberts 2017-11-17 17:18:26 -05:00
parent cac011246e
commit fc9c5e85aa
2 changed files with 95 additions and 1 deletions

View File

@ -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());

View File

@ -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']);
}
}