Skip to content

Commit 7687071

Browse files
authored
Merge pull request #1071 from TaProhm/append-deprecated-for-inputs-fields
Allow deprecating input fields and arguments (InputObjectType)
2 parents 10d2ce4 + 27c7213 commit 7687071

File tree

8 files changed

+51
-1
lines changed

8 files changed

+51
-1
lines changed

src/Config/InputObjectTypeDefinition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function getDefinition(): ArrayNodeDefinition
3232
->append($this->descriptionSection())
3333
->append($this->defaultValueSection())
3434
->append($this->validationSection(self::VALIDATION_LEVEL_PROPERTY))
35+
->append($this->deprecationReasonSection())
3536
->end()
3637
->isRequired()
3738
->requiresAtLeastOneElement()

src/Config/Parser/MetadataParser/MetadataParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private static function inputMetadataToGQLConfiguration(ReflectionClass $reflect
398398
{
399399
$inputConfiguration = array_merge([
400400
'fields' => self::getGraphQLInputFieldsFromMetadatas($reflectionClass, self::getClassProperties($reflectionClass)),
401-
], self::getDescriptionConfiguration(static::getMetadatas($reflectionClass)));
401+
], self::getDescriptionConfiguration(static::getMetadatas($reflectionClass), true));
402402

403403
return ['type' => $inputAnnotation->isRelay ? 'relay-mutation-input' : 'input-object', 'config' => $inputConfiguration];
404404
}

tests/Config/Parser/MetadataParserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public function testInput(): void
230230
'diameter' => ['type' => 'Int'],
231231
'variable' => ['type' => 'Int!'],
232232
'tags' => ['type' => '[String]!'],
233+
'alienInvasion' => ['type' => 'Boolean!', 'deprecationReason' => 'No more alien invasions on planets'],
233234
],
234235
]);
235236
}

tests/Config/Parser/fixtures/annotations/Input/Planet.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ final class Planet
6060
*/
6161
#[GQL\Field(type: '[String]!')]
6262
public array $tags;
63+
64+
/**
65+
* @GQL\Field(type="Boolean!")
66+
*
67+
* @GQL\Deprecated("No more alien invasions on planets")
68+
*/
69+
#[GQL\Field(type: 'Boolean!')]
70+
#[GQL\Deprecated('No more alien invasions on planets')]
71+
public string $alienInvasion;
6372
}

tests/Config/Parser/fixtures/graphql/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface Character {
2727
friends: [Character]
2828
appearsIn: [Episode]!
2929
deprecatedField: String! @deprecated(reason: "This field was deprecated!")
30+
fieldWithDeprecatedArg(deprecatedArg: Boolean! = false @deprecated(reason: "This arg was deprecated!")): String!
3031
}
3132

3233
type Human implements Character {
@@ -52,6 +53,7 @@ input ReviewInput {
5253
stars: Int! = 5
5354
rate: Float! = 1.58
5455
commentary: String = null
56+
deprecatedInputField: String! @deprecated(reason: "This input field was deprecated!")
5557
}
5658

5759
scalar Year

tests/Config/Parser/fixtures/graphql/schema.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@
8888
'description' => null,
8989
'deprecationReason' => 'This field was deprecated!',
9090
],
91+
'fieldWithDeprecatedArg' => [
92+
'type' => 'String!',
93+
'description' => null,
94+
'args' => [
95+
'deprecatedArg' => [
96+
'type' => 'Boolean!',
97+
'description' => null,
98+
'defaultValue' => false,
99+
'deprecationReason' => 'This arg was deprecated!',
100+
],
101+
],
102+
],
91103
],
92104
],
93105
],
@@ -135,6 +147,11 @@
135147
'stars' => ['type' => 'Int!', 'description' => null, 'defaultValue' => 5],
136148
'rate' => ['type' => 'Float!', 'description' => null, 'defaultValue' => 1.58],
137149
'commentary' => ['type' => 'String', 'description' => null, 'defaultValue' => null],
150+
'deprecatedInputField' => [
151+
'type' => 'String!',
152+
'description' => null,
153+
'deprecationReason' => 'This input field was deprecated!',
154+
],
138155
],
139156
],
140157
],

tests/Functional/App/config/definition/mapping/deprecated.types.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ ObjectWithDeprecatedField:
1919
bar:
2020
type: String
2121
deprecationReason: "A terrible reason"
22+
23+
InputObjectWithDeprecatedField:
24+
type: input-object
25+
config:
26+
fields:
27+
baz:
28+
type: String
29+
deprecationReason: "A terrible reason for input"

tests/Functional/Type/DefinitionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Overblog\GraphQLBundle\Tests\Functional\Type;
66

77
use GraphQL\Type\Definition\EnumType;
8+
use GraphQL\Type\Definition\InputObjectType;
89
use GraphQL\Type\Definition\ObjectType;
910
use GraphQL\Type\Definition\Type;
1011
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
@@ -43,6 +44,17 @@ public function testDefinesAnObjectTypeWithDeprecatedField(): void
4344
$this->assertSame([], $field->args);
4445
}
4546

47+
public function testDefinesAnInputObjectTypeWithDeprecatedField(): void
48+
{
49+
/** @var InputObjectType $InputObjectWithDeprecatedField */
50+
$InputObjectWithDeprecatedField = $this->getType('InputObjectWithDeprecatedField');
51+
$field = $InputObjectWithDeprecatedField->getField('baz');
52+
$this->assertSame(Type::string(), $field->getType());
53+
$this->assertTrue($field->isDeprecated());
54+
$this->assertSame('A terrible reason for input', $field->deprecationReason);
55+
$this->assertSame('baz', $field->name);
56+
}
57+
4658
private function getType(string $type): ?Type
4759
{
4860
// @phpstan-ignore-next-line

0 commit comments

Comments
 (0)