diff --git a/src/Config/InputObjectTypeDefinition.php b/src/Config/InputObjectTypeDefinition.php index 63cb1e471..5ed2fd46c 100644 --- a/src/Config/InputObjectTypeDefinition.php +++ b/src/Config/InputObjectTypeDefinition.php @@ -32,6 +32,7 @@ public function getDefinition(): ArrayNodeDefinition ->append($this->descriptionSection()) ->append($this->defaultValueSection()) ->append($this->validationSection(self::VALIDATION_LEVEL_PROPERTY)) + ->append($this->deprecationReasonSection()) ->end() ->isRequired() ->requiresAtLeastOneElement() diff --git a/src/Config/Parser/MetadataParser/MetadataParser.php b/src/Config/Parser/MetadataParser/MetadataParser.php index 471c42e73..473923435 100644 --- a/src/Config/Parser/MetadataParser/MetadataParser.php +++ b/src/Config/Parser/MetadataParser/MetadataParser.php @@ -398,7 +398,7 @@ private static function inputMetadataToGQLConfiguration(ReflectionClass $reflect { $inputConfiguration = array_merge([ 'fields' => self::getGraphQLInputFieldsFromMetadatas($reflectionClass, self::getClassProperties($reflectionClass)), - ], self::getDescriptionConfiguration(static::getMetadatas($reflectionClass))); + ], self::getDescriptionConfiguration(static::getMetadatas($reflectionClass), true)); return ['type' => $inputAnnotation->isRelay ? 'relay-mutation-input' : 'input-object', 'config' => $inputConfiguration]; } diff --git a/tests/Config/Parser/MetadataParserTest.php b/tests/Config/Parser/MetadataParserTest.php index c6feb7b9f..52519aba7 100644 --- a/tests/Config/Parser/MetadataParserTest.php +++ b/tests/Config/Parser/MetadataParserTest.php @@ -230,6 +230,7 @@ public function testInput(): void 'diameter' => ['type' => 'Int'], 'variable' => ['type' => 'Int!'], 'tags' => ['type' => '[String]!'], + 'alienInvasion' => ['type' => 'Boolean!', 'deprecationReason' => 'No more alien invasions on planets'], ], ]); } diff --git a/tests/Config/Parser/fixtures/annotations/Input/Planet.php b/tests/Config/Parser/fixtures/annotations/Input/Planet.php index b6716bdb7..e326be69f 100644 --- a/tests/Config/Parser/fixtures/annotations/Input/Planet.php +++ b/tests/Config/Parser/fixtures/annotations/Input/Planet.php @@ -60,4 +60,13 @@ final class Planet */ #[GQL\Field(type: '[String]!')] public array $tags; + + /** + * @GQL\Field(type="Boolean!") + * + * @GQL\Deprecated("No more alien invasions on planets") + */ + #[GQL\Field(type: 'Boolean!')] + #[GQL\Deprecated('No more alien invasions on planets')] + public string $alienInvasion; } diff --git a/tests/Config/Parser/fixtures/graphql/schema.graphql b/tests/Config/Parser/fixtures/graphql/schema.graphql index dab2bbd09..5398244b1 100644 --- a/tests/Config/Parser/fixtures/graphql/schema.graphql +++ b/tests/Config/Parser/fixtures/graphql/schema.graphql @@ -27,6 +27,7 @@ interface Character { friends: [Character] appearsIn: [Episode]! deprecatedField: String! @deprecated(reason: "This field was deprecated!") + fieldWithDeprecatedArg(deprecatedArg: Boolean! = false @deprecated(reason: "This arg was deprecated!")): String! } type Human implements Character { @@ -52,6 +53,7 @@ input ReviewInput { stars: Int! = 5 rate: Float! = 1.58 commentary: String = null + deprecatedInputField: String! @deprecated(reason: "This input field was deprecated!") } scalar Year diff --git a/tests/Config/Parser/fixtures/graphql/schema.php b/tests/Config/Parser/fixtures/graphql/schema.php index 215bf935c..b56f77328 100644 --- a/tests/Config/Parser/fixtures/graphql/schema.php +++ b/tests/Config/Parser/fixtures/graphql/schema.php @@ -88,6 +88,18 @@ 'description' => null, 'deprecationReason' => 'This field was deprecated!', ], + 'fieldWithDeprecatedArg' => [ + 'type' => 'String!', + 'description' => null, + 'args' => [ + 'deprecatedArg' => [ + 'type' => 'Boolean!', + 'description' => null, + 'defaultValue' => false, + 'deprecationReason' => 'This arg was deprecated!', + ], + ], + ], ], ], ], @@ -135,6 +147,11 @@ 'stars' => ['type' => 'Int!', 'description' => null, 'defaultValue' => 5], 'rate' => ['type' => 'Float!', 'description' => null, 'defaultValue' => 1.58], 'commentary' => ['type' => 'String', 'description' => null, 'defaultValue' => null], + 'deprecatedInputField' => [ + 'type' => 'String!', + 'description' => null, + 'deprecationReason' => 'This input field was deprecated!', + ], ], ], ], diff --git a/tests/Functional/App/config/definition/mapping/deprecated.types.yml b/tests/Functional/App/config/definition/mapping/deprecated.types.yml index b4a6577b6..b30c9cb21 100644 --- a/tests/Functional/App/config/definition/mapping/deprecated.types.yml +++ b/tests/Functional/App/config/definition/mapping/deprecated.types.yml @@ -19,3 +19,11 @@ ObjectWithDeprecatedField: bar: type: String deprecationReason: "A terrible reason" + +InputObjectWithDeprecatedField: + type: input-object + config: + fields: + baz: + type: String + deprecationReason: "A terrible reason for input" diff --git a/tests/Functional/Type/DefinitionTest.php b/tests/Functional/Type/DefinitionTest.php index cab3b5b24..b3e4a9319 100644 --- a/tests/Functional/Type/DefinitionTest.php +++ b/tests/Functional/Type/DefinitionTest.php @@ -5,6 +5,7 @@ namespace Overblog\GraphQLBundle\Tests\Functional\Type; use GraphQL\Type\Definition\EnumType; +use GraphQL\Type\Definition\InputObjectType; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; use Overblog\GraphQLBundle\Tests\Functional\TestCase; @@ -43,6 +44,17 @@ public function testDefinesAnObjectTypeWithDeprecatedField(): void $this->assertSame([], $field->args); } + public function testDefinesAnInputObjectTypeWithDeprecatedField(): void + { + /** @var InputObjectType $InputObjectWithDeprecatedField */ + $InputObjectWithDeprecatedField = $this->getType('InputObjectWithDeprecatedField'); + $field = $InputObjectWithDeprecatedField->getField('baz'); + $this->assertSame(Type::string(), $field->getType()); + $this->assertTrue($field->isDeprecated()); + $this->assertSame('A terrible reason for input', $field->deprecationReason); + $this->assertSame('baz', $field->name); + } + private function getType(string $type): ?Type { // @phpstan-ignore-next-line