mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
testDetectsAdditionOfFieldArg
This commit is contained in:
parent
42d8ac07f9
commit
0fd5abc833
@ -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."
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user