mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-16 20:33:14 +03:00
Preserve description for custom scalars (#181)
This commit is contained in:
parent
fb0ca607e2
commit
1487741f37
@ -32,6 +32,7 @@ abstract class ScalarType extends Type implements OutputType, InputType, LeafTyp
|
|||||||
function __construct(array $config = [])
|
function __construct(array $config = [])
|
||||||
{
|
{
|
||||||
$this->name = isset($config['name']) ? $config['name'] : $this->tryInferName();
|
$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->astNode = isset($config['astNode']) ? $config['astNode'] : null;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
|
||||||
|
@ -3,19 +3,15 @@ namespace GraphQL\Tests\Utils;
|
|||||||
|
|
||||||
use GraphQL\GraphQL;
|
use GraphQL\GraphQL;
|
||||||
use GraphQL\Language\AST\EnumTypeDefinitionNode;
|
use GraphQL\Language\AST\EnumTypeDefinitionNode;
|
||||||
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
|
|
||||||
use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
|
use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
|
||||||
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
|
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
|
||||||
use GraphQL\Language\AST\TypeNode;
|
|
||||||
use GraphQL\Language\Parser;
|
use GraphQL\Language\Parser;
|
||||||
use GraphQL\Language\Printer;
|
use GraphQL\Language\Printer;
|
||||||
use GraphQL\Type\Definition\EnumType;
|
use GraphQL\Type\Definition\EnumType;
|
||||||
use GraphQL\Type\Definition\ObjectType;
|
use GraphQL\Type\Definition\ObjectType;
|
||||||
use GraphQL\Utils\BuildSchema;
|
use GraphQL\Utils\BuildSchema;
|
||||||
use GraphQL\Utils\SchemaPrinter;
|
use GraphQL\Utils\SchemaPrinter;
|
||||||
|
|
||||||
use GraphQL\Type\Definition\Directive;
|
use GraphQL\Type\Definition\Directive;
|
||||||
use GraphQL\Type\Definition\EnumValueDefinition;
|
|
||||||
|
|
||||||
class BuildSchemaTest extends \PHPUnit_Framework_TestCase
|
class BuildSchemaTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -1119,4 +1115,44 @@ type World implements Hello {
|
|||||||
$this->assertArrayHasKey('Hello', $types);
|
$this->assertArrayHasKey('Hello', $types);
|
||||||
$this->assertArrayHasKey('World', $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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user