Preserve description for custom scalars (#181)

This commit is contained in:
Vladimir Razuvaev 2017-10-14 00:45:23 +07:00
parent fb0ca607e2
commit 1487741f37
2 changed files with 41 additions and 4 deletions

View File

@ -32,6 +32,7 @@ abstract class ScalarType extends Type implements OutputType, InputType, LeafTyp
function __construct(array $config = [])
{
$this->name = isset($config['name']) ? $config['name'] : $this->tryInferName();
$this->description = isset($config['description']) ? $config['description'] : $this->description;
$this->astNode = isset($config['astNode']) ? $config['astNode'] : null;
$this->config = $config;

View File

@ -3,19 +3,15 @@ namespace GraphQL\Tests\Utils;
use GraphQL\GraphQL;
use GraphQL\Language\AST\EnumTypeDefinitionNode;
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use GraphQL\Language\AST\TypeNode;
use GraphQL\Language\Parser;
use GraphQL\Language\Printer;
use GraphQL\Type\Definition\EnumType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Utils\BuildSchema;
use GraphQL\Utils\SchemaPrinter;
use GraphQL\Type\Definition\Directive;
use GraphQL\Type\Definition\EnumValueDefinition;
class BuildSchemaTest extends \PHPUnit_Framework_TestCase
{
@ -1119,4 +1115,44 @@ type World implements Hello {
$this->assertArrayHasKey('Hello', $types);
$this->assertArrayHasKey('World', $types);
}
public function testScalarDescription()
{
$schemaDef = '
# An ISO-8601 encoded UTC date string.
scalar Date
type Query {
now: Date
test: String
}
';
$q = '
{
__type(name: "Date") {
name
description
}
strType: __type(name: "String") {
name
description
}
}
';
$schema = BuildSchema::build($schemaDef);
$result = GraphQL::executeQuery($schema, $q)->toArray();
$expected = ['data' => [
'__type' => [
'name' => 'Date',
'description' => 'An ISO-8601 encoded UTC date string.'
],
'strType' => [
'name' => 'String',
'description' => 'The `String` scalar type represents textual data, represented as UTF-8' . "\n" .
'character sequences. The String type is most often used by GraphQL to'. "\n" .
'represent free-form human-readable text.'
]
]];
$this->assertEquals($expected, $result);
}
}