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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
+ Cannot return null for non-nullable field "parentType.fieldName".
```
- Simplified Deferred implementation
- Having an empty string in `deprecationReason` will now print the `@deprecated` directive (only a `null` `deprecationReason` won't print the `@deprecated` directive).

#### v0.13.5
- Fix coroutine executor when using with promise (#486)
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ parameters:

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 3
count: 2
path: src/Utils/SchemaPrinter.php

-
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/SchemaPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static function ($f, $i) use ($options) {
private static function printDeprecated($fieldOrEnumVal) : string
{
$reason = $fieldOrEnumVal->deprecationReason;
if (empty($reason)) {
if ($reason === null) {
return '';
}
if ($reason === '' || $reason === Directive::DEFAULT_DEPRECATION_REASON) {
Expand Down
42 changes: 42 additions & 0 deletions tests/Utils/SchemaPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace GraphQL\Tests\Utils;

use Generator;
use GraphQL\Language\DirectiveLocation;
use GraphQL\Type\Definition\CustomScalarType;
use GraphQL\Type\Definition\Directive;
Expand Down Expand Up @@ -148,6 +149,47 @@ public function testPrintNonNullArrayNonNullStringField() : void
);
}

/**
* @see it('Prints Field With "@deprecated" Directive')
*
* @dataProvider deprecationReasonDataProvider
*/
public function testPrintDeprecatedField(?string $deprecationReason, string $expectedDeprecationDirective) : void
{
$output = $this->printSingleFieldSchema([
'type' => Type::int(),
'deprecationReason' => $deprecationReason,
]);
self::assertSame(
'
type Query {
singleField: Int' . $expectedDeprecationDirective . '
}
',
$output
);
}

public function deprecationReasonDataProvider() : Generator
{
yield 'when deprecationReason is null' => [
null,
'',
];
yield 'when deprecationReason is empty string' => [
'',
' @deprecated',
];
yield 'when deprecationReason is the default deprecation reason' => [
Directive::DEFAULT_DEPRECATION_REASON,
' @deprecated',
];
yield 'when deprecationReason is not empty string' => [
'this is deprecated',
' @deprecated(reason: "this is deprecated")',
];
}

/**
* @see it('Print Object Field')
*/
Expand Down