diff --git a/src/Utils/FindBreakingChanges.php b/src/Utils/FindBreakingChanges.php index 8f5a906..c44d78d 100644 --- a/src/Utils/FindBreakingChanges.php +++ b/src/Utils/FindBreakingChanges.php @@ -324,7 +324,7 @@ class FindBreakingChanges foreach ($newTypeFieldsDef as $fieldName => $fieldDef) { if (!isset($oldTypeFieldsDef[$fieldName]) && $fieldDef->getType() instanceof NonNull) { $newTypeName = $newType->name; - $breakingFieldChanges[] = ['type' => self::BREAKING_CHANGE_NON_NULL_INPUT_FIELD_ADDED, 'description' => "A non-null field ${fieldName} on input type ${$newTypeName} was added"]; + $breakingFieldChanges[] = ['type' => self::BREAKING_CHANGE_NON_NULL_INPUT_FIELD_ADDED, 'description' => "A non-null field ${fieldName} on input type ${newTypeName} was added."]; } } } diff --git a/tests/Utils/FindBreakingChangesTest.php b/tests/Utils/FindBreakingChangesTest.php index ac792f4..ed87628 100644 --- a/tests/Utils/FindBreakingChangesTest.php +++ b/tests/Utils/FindBreakingChangesTest.php @@ -428,4 +428,49 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedFieldChanges, FindBreakingChanges::findFieldsThatChangedType($oldSchema, $newSchema)); } + + public function testDetectsNonNullFieldAddedToInputType() + { + $oldInputType = new InputObjectType([ + 'name' => 'InputType1', + 'fields' => [ + 'field1' => Type::string() + ] + ]); + + $newInputType = new InputObjectType([ + 'name' => 'InputType1', + 'fields' => [ + 'field1' => Type::string(), + 'requiredField' => Type::nonNull(Type::int()), + 'optionalField' => Type::boolean() + ] + ]); + + $oldSchema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'root', + 'fields' => [ + 'type1' => $oldInputType + ] + ]) + ]); + + $newSchema = new Schema([ + 'query' => new ObjectType([ + 'name' => 'root', + 'fields' => [ + 'type1' => $newInputType + ] + ]) + ]); + + $this->assertEquals( + [ + 'type' => FindBreakingChanges::BREAKING_CHANGE_NON_NULL_INPUT_FIELD_ADDED, + 'description' => 'A non-null field requiredField on input type InputType1 was added.' + ], + FindBreakingChanges::findFieldsThatChangedType($oldSchema, $newSchema)[0] + ); + } } \ No newline at end of file