Skip to content

Commit d17c80a

Browse files
authored
Fix issue with kept deprecation reason (#735)
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.
1 parent 434b7ea commit d17c80a

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

Diff for: src/FieldsBuilder.php

+1
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ private function getQueryFieldsFromSourceFields(
689689
$docBlockComment = rtrim($docBlockObj->getSummary() . "\n" . $docBlockObj->getDescription()->render());
690690

691691
$deprecated = $docBlockObj->getTagsByName('deprecated');
692+
$deprecationReason = null;
692693
if (count($deprecated) >= 1) {
693694
$deprecationReason = trim((string) $deprecated[0]);
694695
}

Diff for: tests/FieldsBuilderTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
use TheCodingMachine\GraphQLite\Fixtures\TestControllerWithParamDateTime;
3838
use TheCodingMachine\GraphQLite\Fixtures\TestControllerWithReturnDateTime;
3939
use TheCodingMachine\GraphQLite\Fixtures\TestControllerWithUnionInputParam;
40+
use TheCodingMachine\GraphQLite\Fixtures\TestDeprecatedField;
4041
use TheCodingMachine\GraphQLite\Fixtures\TestDoubleReturnTag;
4142
use TheCodingMachine\GraphQLite\Fixtures\TestEnum;
4243
use TheCodingMachine\GraphQLite\Fixtures\TestFieldBadInputType;
4344
use TheCodingMachine\GraphQLite\Fixtures\TestFieldBadOutputType;
4445
use TheCodingMachine\GraphQLite\Fixtures\TestObject;
46+
use TheCodingMachine\GraphQLite\Fixtures\TestObjectWithDeprecatedField;
4547
use TheCodingMachine\GraphQLite\Fixtures\TestSelfType;
4648
use TheCodingMachine\GraphQLite\Fixtures\TestSourceFieldBadOutputType;
4749
use TheCodingMachine\GraphQLite\Fixtures\TestSourceFieldBadOutputType2;
@@ -922,4 +924,20 @@ public function testSourceNameInSourceAndMagicFields(): void
922924
$result = $resolve($source, [], null, $this->createMock(ResolveInfo::class));
923925
$this->assertSame('bar value', $result);
924926
}
927+
928+
public function testDeprecationInDocblock(): void
929+
{
930+
$fieldsBuilder = $this->buildFieldsBuilder();
931+
$inputFields = $fieldsBuilder->getFields(
932+
new TestDeprecatedField(),
933+
'Test',
934+
);
935+
936+
$this->assertCount(2, $inputFields);
937+
938+
$this->assertEquals('this is deprecated', $inputFields['deprecatedField']->deprecationReason);
939+
$this->assertTrue( $inputFields['deprecatedField']->isDeprecated());
940+
$this->assertNull( $inputFields['name']->deprecationReason);
941+
$this->assertFalse( $inputFields['name']->isDeprecated());
942+
}
925943
}

Diff for: tests/Fixtures/TestDeprecatedField.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TheCodingMachine\GraphQLite\Fixtures;
6+
7+
use TheCodingMachine\GraphQLite\Annotations\SourceField;
8+
use TheCodingMachine\GraphQLite\Annotations\Type;
9+
10+
#[Type(class: TestObjectWithDeprecatedField::class)]
11+
#[SourceField(name: 'deprecatedField')]
12+
#[SourceField(name: 'name')]
13+
class TestDeprecatedField
14+
{
15+
16+
}

Diff for: tests/Fixtures/TestObjectWithDeprecatedField.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TheCodingMachine\GraphQLite\Fixtures;
6+
7+
class TestObjectWithDeprecatedField
8+
{
9+
10+
/** @deprecated this is deprecated */
11+
public function getDeprecatedField(): string
12+
{
13+
return 'deprecatedField';
14+
}
15+
16+
public function getName(): string
17+
{
18+
return 'Foo';
19+
}
20+
21+
}

0 commit comments

Comments
 (0)