testDetectsAdditionOfFieldArg

This commit is contained in:
Ben Roberts 2017-11-20 13:48:21 -05:00
parent 42d8ac07f9
commit 0fd5abc833
2 changed files with 51 additions and 1 deletions

View File

@ -184,7 +184,7 @@ class FindBreakingChanges
}
}
// Check if a non-null arg was added to the field
foreach ($newTypeFields[$fieldName]->args as $newArgName => $newArgDef) {
foreach ($newTypeFields[$fieldName]->args as $newArgDef) {
$oldArgs = $oldTypeFields[$fieldName]->args;
$oldArgDef = Utils::find(
$oldArgs, function ($arg) use ($newArgDef) {
@ -194,6 +194,7 @@ class FindBreakingChanges
if (!$oldArgDef && $newArgDef->getType() instanceof NonNull) {
$newTypeName = $newTypeDefinition->name;
$newArgName = $newArgDef->name;
$breakingChanges[] = [
'type' => self::BREAKING_CHANGE_NON_NULL_ARG_ADDED,
'description' => "A non-null arg ${newArgName} on ${newTypeName}->${fieldName} was added."

View File

@ -812,4 +812,53 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedChanges, FindBreakingChanges::findArgChanges($oldSchema, $newSchema)['breakingChanges']);
}
public function testDetectsAdditionOfFieldArg()
{
$oldType = new ObjectType([
'name' => 'Type1',
'fields' => [
'field1' => [
'type' => Type::string(),
'args' => [
'arg1' => Type::string()
]]
]
]);
$newType = new ObjectType([
'name' => 'Type1',
'fields' => [
'field1' => [
'type' => Type::string(),
'args' => [
'arg1' => Type::string(),
'newRequiredArg' => Type::nonNull(Type::string()),
'newOptionalArg' => Type::int()
]]
]
]);
$oldSchema = new Schema([
'query' => new ObjectType([
'name' => 'root',
'fields' => [
'type1' => $oldType,
]
])
]);
$newSchema = new Schema([
'query' => new ObjectType([
'name' => 'root',
'fields' => [
'type1' => $newType
]
])
]);
$this->assertEquals(
[
'type' => FindBreakingChanges::BREAKING_CHANGE_NON_NULL_ARG_ADDED,
'description' => 'A non-null arg newRequiredArg on Type1->field1 was added.'
],
FindBreakingChanges::findArgChanges($oldSchema, $newSchema)['breakingChanges'][0]);
}
}