From 1a1d224dc2bbfd711605bcc54572815e520a4344 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 11 Mar 2025 15:19:16 +0100 Subject: [PATCH] Fix issue with kept deprecation reason When a type contains multiple fields and one of them is deprecated the following fields will be marked as deprecated. By resetting the value in each run we make sure the value is not kept. --- src/FieldsBuilder.php | 1 + tests/FieldsBuilderTest.php | 18 ++++++++++++++++ tests/Fixtures/TestDeprecatedField.php | 16 ++++++++++++++ .../TestObjectWithDeprecatedField.php | 21 +++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 tests/Fixtures/TestDeprecatedField.php create mode 100644 tests/Fixtures/TestObjectWithDeprecatedField.php diff --git a/src/FieldsBuilder.php b/src/FieldsBuilder.php index 10b0c620ae..c0dc7d27d1 100644 --- a/src/FieldsBuilder.php +++ b/src/FieldsBuilder.php @@ -689,6 +689,7 @@ private function getQueryFieldsFromSourceFields( $docBlockComment = rtrim($docBlockObj->getSummary() . "\n" . $docBlockObj->getDescription()->render()); $deprecated = $docBlockObj->getTagsByName('deprecated'); + $deprecationReason = null; if (count($deprecated) >= 1) { $deprecationReason = trim((string) $deprecated[0]); } diff --git a/tests/FieldsBuilderTest.php b/tests/FieldsBuilderTest.php index 0cd11d0d49..c280218fec 100644 --- a/tests/FieldsBuilderTest.php +++ b/tests/FieldsBuilderTest.php @@ -37,11 +37,13 @@ use TheCodingMachine\GraphQLite\Fixtures\TestControllerWithParamDateTime; use TheCodingMachine\GraphQLite\Fixtures\TestControllerWithReturnDateTime; use TheCodingMachine\GraphQLite\Fixtures\TestControllerWithUnionInputParam; +use TheCodingMachine\GraphQLite\Fixtures\TestDeprecatedField; use TheCodingMachine\GraphQLite\Fixtures\TestDoubleReturnTag; use TheCodingMachine\GraphQLite\Fixtures\TestEnum; use TheCodingMachine\GraphQLite\Fixtures\TestFieldBadInputType; use TheCodingMachine\GraphQLite\Fixtures\TestFieldBadOutputType; use TheCodingMachine\GraphQLite\Fixtures\TestObject; +use TheCodingMachine\GraphQLite\Fixtures\TestObjectWithDeprecatedField; use TheCodingMachine\GraphQLite\Fixtures\TestSelfType; use TheCodingMachine\GraphQLite\Fixtures\TestSourceFieldBadOutputType; use TheCodingMachine\GraphQLite\Fixtures\TestSourceFieldBadOutputType2; @@ -922,4 +924,20 @@ public function testSourceNameInSourceAndMagicFields(): void $result = $resolve($source, [], null, $this->createMock(ResolveInfo::class)); $this->assertSame('bar value', $result); } + + public function testDeprecationInDocblock(): void + { + $fieldsBuilder = $this->buildFieldsBuilder(); + $inputFields = $fieldsBuilder->getFields( + new TestDeprecatedField(), + 'Test', + ); + + $this->assertCount(2, $inputFields); + + $this->assertEquals('this is deprecated', $inputFields['deprecatedField']->deprecationReason); + $this->assertTrue( $inputFields['deprecatedField']->isDeprecated()); + $this->assertNull( $inputFields['name']->deprecationReason); + $this->assertFalse( $inputFields['name']->isDeprecated()); + } } diff --git a/tests/Fixtures/TestDeprecatedField.php b/tests/Fixtures/TestDeprecatedField.php new file mode 100644 index 0000000000..c417836ceb --- /dev/null +++ b/tests/Fixtures/TestDeprecatedField.php @@ -0,0 +1,16 @@ +