Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/FieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/FieldsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
16 changes: 16 additions & 0 deletions tests/Fixtures/TestDeprecatedField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace TheCodingMachine\GraphQLite\Fixtures;

use TheCodingMachine\GraphQLite\Annotations\SourceField;
use TheCodingMachine\GraphQLite\Annotations\Type;

#[Type(class: TestObjectWithDeprecatedField::class)]
#[SourceField(name: 'deprecatedField')]
#[SourceField(name: 'name')]
class TestDeprecatedField
{

}
21 changes: 21 additions & 0 deletions tests/Fixtures/TestObjectWithDeprecatedField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace TheCodingMachine\GraphQLite\Fixtures;

class TestObjectWithDeprecatedField
{

/** @deprecated this is deprecated */
public function getDeprecatedField(): string
{
return 'deprecatedField';
}

public function getName(): string
{
return 'Foo';
}

}
Loading