Skip to content

Commit

Permalink
Merge pull request #1071 from TaProhm/append-deprecated-for-inputs-fi…
Browse files Browse the repository at this point in the history
…elds

Allow deprecating input fields and arguments (InputObjectType)
  • Loading branch information
Vincz authored Jun 14, 2023
2 parents 10d2ce4 + 27c7213 commit 7687071
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Config/InputObjectTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Parser/MetadataParser/MetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions tests/Config/Parser/MetadataParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
],
]);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Config/Parser/fixtures/annotations/Input/Planet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions tests/Config/Parser/fixtures/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
17 changes: 17 additions & 0 deletions tests/Config/Parser/fixtures/graphql/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
],
],
],
],
],
],
Expand Down Expand Up @@ -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!',
],
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 12 additions & 0 deletions tests/Functional/Type/DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7687071

Please sign in to comment.