Skip to content

Commit 1487741

Browse files
committed
Preserve description for custom scalars (#181)
1 parent fb0ca60 commit 1487741

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/Type/Definition/ScalarType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class ScalarType extends Type implements OutputType, InputType, LeafTyp
3232
function __construct(array $config = [])
3333
{
3434
$this->name = isset($config['name']) ? $config['name'] : $this->tryInferName();
35+
$this->description = isset($config['description']) ? $config['description'] : $this->description;
3536
$this->astNode = isset($config['astNode']) ? $config['astNode'] : null;
3637
$this->config = $config;
3738

tests/Utils/BuildSchemaTest.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33

44
use GraphQL\GraphQL;
55
use GraphQL\Language\AST\EnumTypeDefinitionNode;
6-
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
76
use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
87
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
9-
use GraphQL\Language\AST\TypeNode;
108
use GraphQL\Language\Parser;
119
use GraphQL\Language\Printer;
1210
use GraphQL\Type\Definition\EnumType;
1311
use GraphQL\Type\Definition\ObjectType;
1412
use GraphQL\Utils\BuildSchema;
1513
use GraphQL\Utils\SchemaPrinter;
16-
1714
use GraphQL\Type\Definition\Directive;
18-
use GraphQL\Type\Definition\EnumValueDefinition;
1915

2016
class BuildSchemaTest extends \PHPUnit_Framework_TestCase
2117
{
@@ -1119,4 +1115,44 @@ interface Hello {
11191115
$this->assertArrayHasKey('Hello', $types);
11201116
$this->assertArrayHasKey('World', $types);
11211117
}
1118+
1119+
public function testScalarDescription()
1120+
{
1121+
$schemaDef = '
1122+
# An ISO-8601 encoded UTC date string.
1123+
scalar Date
1124+
1125+
type Query {
1126+
now: Date
1127+
test: String
1128+
}
1129+
';
1130+
$q = '
1131+
{
1132+
__type(name: "Date") {
1133+
name
1134+
description
1135+
}
1136+
strType: __type(name: "String") {
1137+
name
1138+
description
1139+
}
1140+
}
1141+
';
1142+
$schema = BuildSchema::build($schemaDef);
1143+
$result = GraphQL::executeQuery($schema, $q)->toArray();
1144+
$expected = ['data' => [
1145+
'__type' => [
1146+
'name' => 'Date',
1147+
'description' => 'An ISO-8601 encoded UTC date string.'
1148+
],
1149+
'strType' => [
1150+
'name' => 'String',
1151+
'description' => 'The `String` scalar type represents textual data, represented as UTF-8' . "\n" .
1152+
'character sequences. The String type is most often used by GraphQL to'. "\n" .
1153+
'represent free-form human-readable text.'
1154+
]
1155+
]];
1156+
$this->assertEquals($expected, $result);
1157+
}
11221158
}

0 commit comments

Comments
 (0)