From c7218c80c290d9eb72bf100c4524ad70b3e67121 Mon Sep 17 00:00:00 2001 From: Samuel Baptista Date: Wed, 25 Nov 2026 22:13:22 +0100 Subject: [PATCH 1/2] Partial input is partial even when input fields are already resolved The partial input was a clone of the input. When the fields of the input were already resolved, the clone kept them, so required fields stayed required and default values were kept. --- phpstan-baseline.neon | 6 ------ src/Factory/Type/PartialInputTypeFactory.php | 10 +++++----- tests/InputTypesTest.php | 10 ++++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4efcf69..7e9512e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -168,12 +168,6 @@ parameters: count: 1 path: src/Factory/Type/PartialInputTypeFactory.php - - - message: '#^Property GraphQL\\Type\\Definition\\InputObjectType\:\:\$config \(array\{name\?\: string\|null, description\?\: string\|null, isOneOf\?\: bool\|null, fields\: \(callable\(\)\: iterable\\)\|iterable\, parseValue\?\: \(callable\(array\\)\: mixed\)\|null, astNode\?\: GraphQL\\Language\\AST\\InputObjectTypeDefinitionNode\|null, extensionASTNodes\?\: array\\|null\}\) does not accept array\{name\?\: string\|null, description\?\: string\|null, isOneOf\?\: bool\|null, fields\: Closure\(\)\: list, parseValue\?\: \(callable\(array\\)\: mixed\)\|null, astNode\?\: GraphQL\\Language\\AST\\InputObjectTypeDefinitionNode\|null, extensionASTNodes\?\: array\\|null\}\.$#' - identifier: assign.propertyType - count: 1 - path: src/Factory/Type/PartialInputTypeFactory.php - - message: '#^Parameter \#1 \$property of method GraphQL\\Doctrine\\Factory\\AbstractFactory\:\:isPropertyExcluded\(\) expects ReflectionProperty, ReflectionProperty\|null given\.$#' identifier: argument.type diff --git a/src/Factory/Type/PartialInputTypeFactory.php b/src/Factory/Type/PartialInputTypeFactory.php index 2025cb6..9aede34 100644 --- a/src/Factory/Type/PartialInputTypeFactory.php +++ b/src/Factory/Type/PartialInputTypeFactory.php @@ -22,8 +22,8 @@ final class PartialInputTypeFactory extends AbstractTypeFactory */ public function create(string $className, string $typeName): InputObjectType { - $type = clone $this->types->getInput($className); - $fieldsGetter = $type->config['fields']; + $config = $this->types->getInput($className)->config; + $fieldsGetter = $config['fields']; $optionalFieldsGetter = function () use ($fieldsGetter): array { $optionalFields = []; @@ -40,9 +40,9 @@ public function create(string $className, string $typeName): InputObjectType return $optionalFields; }; - $type->config['fields'] = $optionalFieldsGetter; - $type->name = $typeName; + $config['name'] = $typeName; + $config['fields'] = $optionalFieldsGetter; - return $type; + return new InputObjectType($config); } } diff --git a/tests/InputTypesTest.php b/tests/InputTypesTest.php index 6f1fac6..512ed9f 100644 --- a/tests/InputTypesTest.php +++ b/tests/InputTypesTest.php @@ -35,6 +35,16 @@ public function testDefaultValuesPartialInput(): void $this->assertType('tests/data/DefaultValuePartialInput.graphqls', $actual); } + public function testPartialInputIsPartialWhenInputFieldsAreAlreadyResolved(): void + { + $input = $this->types->getInput(Blog\Model\Special\DefaultValue::class); + $input->getFields(); + + $partialInput = $this->types->getPartialInput(Blog\Model\Special\DefaultValue::class); + $this->assertType('tests/data/DefaultValuePartialInput.graphqls', $partialInput); + $this->assertType('tests/data/DefaultValueInput.graphqls', $input); + } + public function testSelfSupportInput(): void { $actual = $this->types->getInput(Blog\Model\Special\SelfSupport::class); From 0f90ba539de29151c72f36cd29464b91c14aec6a Mon Sep 17 00:00:00 2001 From: Samuel Baptista Date: Wed, 25 Nov 2026 22:30:50 +0100 Subject: [PATCH 2/2] Expect partial input to keep description and to leave input untouched --- tests/InputTypesTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/InputTypesTest.php b/tests/InputTypesTest.php index 512ed9f..c25521c 100644 --- a/tests/InputTypesTest.php +++ b/tests/InputTypesTest.php @@ -42,9 +42,23 @@ public function testPartialInputIsPartialWhenInputFieldsAreAlreadyResolved(): vo $partialInput = $this->types->getPartialInput(Blog\Model\Special\DefaultValue::class); $this->assertType('tests/data/DefaultValuePartialInput.graphqls', $partialInput); + } + + public function testInputIsNotPartialWhenPartialInputFieldsAreAlreadyResolved(): void + { + $partialInput = $this->types->getPartialInput(Blog\Model\Special\DefaultValue::class); + $partialInput->getFields(); + + $input = $this->types->getInput(Blog\Model\Special\DefaultValue::class); $this->assertType('tests/data/DefaultValueInput.graphqls', $input); } + public function testPartialInputHasSameDescriptionAsInput(): void + { + $partialInput = $this->types->getPartialInput(Post::class); + self::assertSame('A blog post with title and body.', $partialInput->description); + } + public function testSelfSupportInput(): void { $actual = $this->types->getInput(Blog\Model\Special\SelfSupport::class);