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..c25521c 100644 --- a/tests/InputTypesTest.php +++ b/tests/InputTypesTest.php @@ -35,6 +35,30 @@ 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); + } + + 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);