2016-04-23 21:24:41 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Tests\Language;
|
|
|
|
|
2017-07-05 14:42:27 +03:00
|
|
|
use GraphQL\Error\SyntaxError;
|
2016-11-19 13:31:47 +03:00
|
|
|
use GraphQL\Language\AST\NodeKind;
|
2016-04-23 21:24:41 +03:00
|
|
|
use GraphQL\Language\Parser;
|
2018-02-12 14:23:39 +03:00
|
|
|
use GraphQL\Language\SourceLocation;
|
2016-04-23 21:24:41 +03:00
|
|
|
|
|
|
|
class SchemaParserTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-10-16 22:57:24 +03:00
|
|
|
// Describe: Schema Parser
|
|
|
|
|
2016-04-23 21:24:41 +03:00
|
|
|
/**
|
|
|
|
* @it Simple type
|
|
|
|
*/
|
|
|
|
public function testSimpleType()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
type Hello {
|
|
|
|
world: String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(6, 11)),
|
|
|
|
'interfaces' => [],
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNode(
|
|
|
|
$this->nameNode('world', $loc(16, 21)),
|
|
|
|
$this->typeNode('String', $loc(23, 29)),
|
|
|
|
$loc(16, 29)
|
|
|
|
)
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(1, 31),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0, 31)
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
2018-02-08 21:33:54 +03:00
|
|
|
/**
|
|
|
|
* @it parses type with description string
|
|
|
|
*/
|
|
|
|
public function testParsesTypeWithDescriptionString()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
"Description"
|
|
|
|
type Hello {
|
|
|
|
world: String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'kind' => NodeKind::DOCUMENT,
|
|
|
|
'definitions' => [
|
|
|
|
[
|
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
|
|
|
'name' => $this->nameNode('Hello', $loc(20, 25)),
|
|
|
|
'interfaces' => [],
|
|
|
|
'directives' => [],
|
|
|
|
'fields' => [
|
|
|
|
$this->fieldNode(
|
|
|
|
$this->nameNode('world', $loc(30, 35)),
|
|
|
|
$this->typeNode('String', $loc(37, 43)),
|
|
|
|
$loc(30, 43)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
'loc' => $loc(1, 45),
|
|
|
|
'description' => [
|
|
|
|
'kind' => NodeKind::STRING,
|
|
|
|
'value' => 'Description',
|
|
|
|
'loc' => $loc(1, 14),
|
|
|
|
'block' => false
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'loc' => $loc(0, 45)
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it parses type with description multi-linestring
|
|
|
|
*/
|
|
|
|
public function testParsesTypeWithDescriptionMultiLineString()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
"""
|
|
|
|
Description
|
|
|
|
"""
|
|
|
|
# Even with comments between them
|
|
|
|
type Hello {
|
|
|
|
world: String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'kind' => NodeKind::DOCUMENT,
|
|
|
|
'definitions' => [
|
|
|
|
[
|
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
|
|
|
'name' => $this->nameNode('Hello', $loc(60, 65)),
|
|
|
|
'interfaces' => [],
|
|
|
|
'directives' => [],
|
|
|
|
'fields' => [
|
|
|
|
$this->fieldNode(
|
|
|
|
$this->nameNode('world', $loc(70, 75)),
|
|
|
|
$this->typeNode('String', $loc(77, 83)),
|
|
|
|
$loc(70, 83)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
'loc' => $loc(1, 85),
|
|
|
|
'description' => [
|
|
|
|
'kind' => NodeKind::STRING,
|
|
|
|
'value' => 'Description',
|
|
|
|
'loc' => $loc(1, 20),
|
|
|
|
'block' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'loc' => $loc(0, 85)
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
|
|
|
}
|
|
|
|
|
2016-04-23 21:24:41 +03:00
|
|
|
/**
|
|
|
|
* @it Simple extension
|
|
|
|
*/
|
|
|
|
public function testSimpleExtension()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
extend type Hello {
|
|
|
|
world: String
|
2016-10-16 22:57:24 +03:00
|
|
|
}
|
|
|
|
';
|
2016-04-23 21:24:41 +03:00
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {
|
|
|
|
return TestUtils::locArray($start, $end);
|
|
|
|
};
|
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2018-02-11 15:27:26 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_EXTENSION,
|
|
|
|
'name' => $this->nameNode('Hello', $loc(13, 18)),
|
|
|
|
'interfaces' => [],
|
|
|
|
'directives' => [],
|
|
|
|
'fields' => [
|
|
|
|
$this->fieldNode(
|
|
|
|
$this->nameNode('world', $loc(23, 28)),
|
|
|
|
$this->typeNode('String', $loc(30, 36)),
|
|
|
|
$loc(23, 36)
|
|
|
|
)
|
2016-10-16 22:57:24 +03:00
|
|
|
],
|
2016-04-23 21:24:41 +03:00
|
|
|
'loc' => $loc(1, 38)
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0, 39)
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
2018-02-11 15:27:26 +03:00
|
|
|
/**
|
|
|
|
* @it Extension without fields
|
|
|
|
*/
|
|
|
|
public function testExtensionWithoutFields()
|
|
|
|
{
|
|
|
|
$body = 'extend type Hello implements Greeting';
|
|
|
|
$doc = Parser::parse($body);
|
|
|
|
$loc = function($start, $end) {
|
|
|
|
return TestUtils::locArray($start, $end);
|
|
|
|
};
|
|
|
|
$expected = [
|
|
|
|
'kind' => NodeKind::DOCUMENT,
|
|
|
|
'definitions' => [
|
|
|
|
[
|
|
|
|
'kind' => NodeKind::OBJECT_TYPE_EXTENSION,
|
|
|
|
'name' => $this->nameNode('Hello', $loc(12, 17)),
|
|
|
|
'interfaces' => [
|
|
|
|
$this->typeNode('Greeting', $loc(29, 37)),
|
|
|
|
],
|
|
|
|
'directives' => [],
|
|
|
|
'fields' => [],
|
|
|
|
'loc' => $loc(0, 37)
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'loc' => $loc(0, 37)
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
|
|
|
}
|
|
|
|
|
2018-02-12 14:23:39 +03:00
|
|
|
/**
|
|
|
|
* @it Extension without anything throws
|
|
|
|
*/
|
|
|
|
public function testExtensionWithoutAnythingThrows()
|
|
|
|
{
|
|
|
|
$this->expectSyntaxError(
|
|
|
|
'extend type Hello',
|
|
|
|
'Unexpected <EOF>',
|
|
|
|
$this->loc(1, 18)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-08 21:33:54 +03:00
|
|
|
/**
|
|
|
|
* @it Extension do not include descriptions
|
|
|
|
*/
|
2018-02-12 14:23:39 +03:00
|
|
|
public function testExtensionDoNotIncludeDescriptions()
|
|
|
|
{
|
2018-02-08 21:33:54 +03:00
|
|
|
$body = '
|
2018-02-11 15:27:26 +03:00
|
|
|
"Description"
|
|
|
|
extend type Hello {
|
|
|
|
world: String
|
|
|
|
}';
|
2018-02-12 14:23:39 +03:00
|
|
|
$this->expectSyntaxError(
|
|
|
|
$body,
|
|
|
|
'Unexpected Name "extend"',
|
|
|
|
$this->loc(3, 7)
|
|
|
|
);
|
2018-02-11 15:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Extension do not include descriptions
|
|
|
|
*/
|
2018-02-12 14:23:39 +03:00
|
|
|
public function testExtensionDoNotIncludeDescriptions2()
|
|
|
|
{
|
2018-02-11 15:27:26 +03:00
|
|
|
$body = '
|
|
|
|
extend "Description" type Hello {
|
|
|
|
world: String
|
|
|
|
}
|
2018-02-08 21:33:54 +03:00
|
|
|
}';
|
2018-02-12 14:23:39 +03:00
|
|
|
$this->expectSyntaxError(
|
|
|
|
$body,
|
|
|
|
'Unexpected String "Description"',
|
|
|
|
$this->loc(2, 14)
|
|
|
|
);
|
2018-02-08 21:33:54 +03:00
|
|
|
}
|
|
|
|
|
2016-04-23 21:24:41 +03:00
|
|
|
/**
|
|
|
|
* @it Simple non-null type
|
|
|
|
*/
|
|
|
|
public function testSimpleNonNullType()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
type Hello {
|
|
|
|
world: String!
|
|
|
|
}';
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {
|
|
|
|
return TestUtils::locArray($start, $end);
|
|
|
|
};
|
2016-04-23 21:24:41 +03:00
|
|
|
$doc = Parser::parse($body);
|
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(6,11)),
|
|
|
|
'interfaces' => [],
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNode(
|
|
|
|
$this->nameNode('world', $loc(16, 21)),
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::NON_NULL_TYPE,
|
2016-04-23 21:24:41 +03:00
|
|
|
'type' => $this->typeNode('String', $loc(23, 29)),
|
|
|
|
'loc' => $loc(23, 30)
|
2016-10-16 22:57:24 +03:00
|
|
|
],
|
2016-04-23 21:24:41 +03:00
|
|
|
$loc(16,30)
|
|
|
|
)
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(1,32),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0,32)
|
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple type inheriting interface
|
|
|
|
*/
|
|
|
|
public function testSimpleTypeInheritingInterface()
|
|
|
|
{
|
2018-02-11 15:27:26 +03:00
|
|
|
$body = 'type Hello implements World { field: String }';
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) { return TestUtils::locArray($start, $end); };
|
2016-04-23 21:24:41 +03:00
|
|
|
$doc = Parser::parse($body);
|
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(5, 10)),
|
|
|
|
'interfaces' => [
|
|
|
|
$this->typeNode('World', $loc(22, 27))
|
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2018-02-11 15:27:26 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNode(
|
|
|
|
$this->nameNode('field', $loc(30, 35)),
|
|
|
|
$this->typeNode('String', $loc(37, 43)),
|
|
|
|
$loc(30, 43)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
'loc' => $loc(0, 45),
|
2017-02-03 16:03:29 +03:00
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2018-02-11 15:27:26 +03:00
|
|
|
'loc' => $loc(0, 45)
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple type inheriting multiple interfaces
|
|
|
|
*/
|
|
|
|
public function testSimpleTypeInheritingMultipleInterfaces()
|
|
|
|
{
|
2018-02-11 15:27:26 +03:00
|
|
|
$body = 'type Hello implements Wo, rld { field: String }';
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
$doc = Parser::parse($body);
|
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(5, 10)),
|
|
|
|
'interfaces' => [
|
|
|
|
$this->typeNode('Wo', $loc(22,24)),
|
|
|
|
$this->typeNode('rld', $loc(26,29))
|
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2018-02-11 15:27:26 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNode(
|
|
|
|
$this->nameNode('field', $loc(32, 37)),
|
|
|
|
$this->typeNode('String', $loc(39, 45)),
|
|
|
|
$loc(32, 45)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
'loc' => $loc(0, 47),
|
2017-02-03 16:03:29 +03:00
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2018-02-11 15:27:26 +03:00
|
|
|
'loc' => $loc(0, 47)
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Single value enum
|
|
|
|
*/
|
|
|
|
public function testSingleValueEnum()
|
|
|
|
{
|
|
|
|
$body = 'enum Hello { WORLD }';
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
$doc = Parser::parse($body);
|
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::ENUM_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(5, 10)),
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'values' => [$this->enumValueNode('WORLD', $loc(13, 18))],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(0, 20),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
|
|
|
'loc' => $loc(0, 20)
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Double value enum
|
|
|
|
*/
|
|
|
|
public function testDoubleValueEnum()
|
|
|
|
{
|
|
|
|
$body = 'enum Hello { WO, RLD }';
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
$doc = Parser::parse($body);
|
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::ENUM_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(5, 10)),
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'values' => [
|
|
|
|
$this->enumValueNode('WO', $loc(13, 15)),
|
|
|
|
$this->enumValueNode('RLD', $loc(17, 20))
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(0, 22),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
|
|
|
'loc' => $loc(0, 22)
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple interface
|
|
|
|
*/
|
|
|
|
public function testSimpleInterface()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
interface Hello {
|
|
|
|
world: String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::INTERFACE_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(11, 16)),
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNode(
|
|
|
|
$this->nameNode('world', $loc(21, 26)),
|
|
|
|
$this->typeNode('String', $loc(28, 34)),
|
|
|
|
$loc(21, 34)
|
|
|
|
)
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(1, 36),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0,36)
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple field with arg
|
|
|
|
*/
|
|
|
|
public function testSimpleFieldWithArg()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
type Hello {
|
|
|
|
world(flag: Boolean): String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(6, 11)),
|
|
|
|
'interfaces' => [],
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNodeWithArgs(
|
|
|
|
$this->nameNode('world', $loc(16, 21)),
|
|
|
|
$this->typeNode('String', $loc(38, 44)),
|
|
|
|
[
|
|
|
|
$this->inputValueNode(
|
|
|
|
$this->nameNode('flag', $loc(22, 26)),
|
|
|
|
$this->typeNode('Boolean', $loc(28, 35)),
|
|
|
|
null,
|
|
|
|
$loc(22, 35)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
$loc(16, 44)
|
|
|
|
)
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(1, 46),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0, 46)
|
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple field with arg with default value
|
|
|
|
*/
|
|
|
|
public function testSimpleFieldWithArgWithDefaultValue()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
type Hello {
|
|
|
|
world(flag: Boolean = true): String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(6, 11)),
|
|
|
|
'interfaces' => [],
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNodeWithArgs(
|
|
|
|
$this->nameNode('world', $loc(16, 21)),
|
|
|
|
$this->typeNode('String', $loc(45, 51)),
|
|
|
|
[
|
|
|
|
$this->inputValueNode(
|
|
|
|
$this->nameNode('flag', $loc(22, 26)),
|
|
|
|
$this->typeNode('Boolean', $loc(28, 35)),
|
2016-11-19 13:31:47 +03:00
|
|
|
['kind' => NodeKind::BOOLEAN, 'value' => true, 'loc' => $loc(38, 42)],
|
2016-04-23 21:24:41 +03:00
|
|
|
$loc(22, 42)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
$loc(16, 51)
|
|
|
|
)
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(1, 53),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0, 53)
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple field with list arg
|
|
|
|
*/
|
|
|
|
public function testSimpleFieldWithListArg()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
type Hello {
|
|
|
|
world(things: [String]): String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(6, 11)),
|
|
|
|
'interfaces' => [],
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNodeWithArgs(
|
|
|
|
$this->nameNode('world', $loc(16, 21)),
|
|
|
|
$this->typeNode('String', $loc(41, 47)),
|
|
|
|
[
|
|
|
|
$this->inputValueNode(
|
|
|
|
$this->nameNode('things', $loc(22,28)),
|
2016-11-19 13:31:47 +03:00
|
|
|
['kind' => NodeKind::LIST_TYPE, 'type' => $this->typeNode('String', $loc(31, 37)), 'loc' => $loc(30, 38)],
|
2016-04-23 21:24:41 +03:00
|
|
|
null,
|
|
|
|
$loc(22, 38)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
$loc(16, 47)
|
|
|
|
)
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(1, 49),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0, 49)
|
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple field with two args
|
|
|
|
*/
|
|
|
|
public function testSimpleFieldWithTwoArgs()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
type Hello {
|
|
|
|
world(argOne: Boolean, argTwo: Int): String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(6, 11)),
|
|
|
|
'interfaces' => [],
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->fieldNodeWithArgs(
|
|
|
|
$this->nameNode('world', $loc(16, 21)),
|
|
|
|
$this->typeNode('String', $loc(53, 59)),
|
|
|
|
[
|
|
|
|
$this->inputValueNode(
|
|
|
|
$this->nameNode('argOne', $loc(22, 28)),
|
|
|
|
$this->typeNode('Boolean', $loc(30, 37)),
|
|
|
|
null,
|
|
|
|
$loc(22, 37)
|
|
|
|
),
|
|
|
|
$this->inputValueNode(
|
|
|
|
$this->nameNode('argTwo', $loc(39, 45)),
|
|
|
|
$this->typeNode('Int', $loc(47, 50)),
|
|
|
|
null,
|
|
|
|
$loc(39, 50)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
$loc(16, 59)
|
|
|
|
)
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(1, 61),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0, 61)
|
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple union
|
|
|
|
*/
|
|
|
|
public function testSimpleUnion()
|
|
|
|
{
|
|
|
|
$body = 'union Hello = World';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::UNION_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(6, 11)),
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'types' => [$this->typeNode('World', $loc(14, 19))],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(0, 19),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
|
|
|
'loc' => $loc(0, 19)
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Union with two types
|
|
|
|
*/
|
|
|
|
public function testUnionWithTwoTypes()
|
|
|
|
{
|
|
|
|
$body = 'union Hello = Wo | Rld';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::UNION_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(6, 11)),
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'types' => [
|
|
|
|
$this->typeNode('Wo', $loc(14, 16)),
|
|
|
|
$this->typeNode('Rld', $loc(19, 22))
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(0, 22),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
|
|
|
'loc' => $loc(0, 22)
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
2017-07-05 14:42:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Union with two types and leading pipe
|
|
|
|
*/
|
|
|
|
public function testUnionWithTwoTypesAndLeadingPipe()
|
|
|
|
{
|
|
|
|
$body = 'union Hello = | Wo | Rld';
|
|
|
|
$doc = Parser::parse($body);
|
|
|
|
$expected = [
|
|
|
|
'kind' => 'Document',
|
|
|
|
'definitions' => [
|
|
|
|
[
|
|
|
|
'kind' => 'UnionTypeDefinition',
|
|
|
|
'name' => $this->nameNode('Hello', ['start' => 6, 'end' => 11]),
|
|
|
|
'directives' => [],
|
|
|
|
'types' => [
|
|
|
|
$this->typeNode('Wo', ['start' => 16, 'end' => 18]),
|
|
|
|
$this->typeNode('Rld', ['start' => 21, 'end' => 24]),
|
|
|
|
],
|
|
|
|
'loc' => ['start' => 0, 'end' => 24],
|
|
|
|
'description' => null
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'loc' => ['start' => 0, 'end' => 24],
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Union fails with no types
|
|
|
|
*/
|
|
|
|
public function testUnionFailsWithNoTypes()
|
|
|
|
{
|
2018-02-12 14:23:39 +03:00
|
|
|
$this->expectSyntaxError(
|
|
|
|
'union Hello = |',
|
|
|
|
'Expected Name, found <EOF>',
|
|
|
|
$this->loc(1, 16)
|
|
|
|
);
|
2017-07-05 14:42:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Union fails with leading douple pipe
|
|
|
|
*/
|
|
|
|
public function testUnionFailsWithLeadingDoublePipe()
|
|
|
|
{
|
2018-02-12 14:23:39 +03:00
|
|
|
$this->expectSyntaxError(
|
|
|
|
'union Hello = || Wo | Rld',
|
|
|
|
'Expected Name, found |',
|
|
|
|
$this->loc(1, 16)
|
|
|
|
);
|
2017-07-05 14:42:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Union fails with double pipe
|
|
|
|
*/
|
|
|
|
public function testUnionFailsWithDoublePipe()
|
|
|
|
{
|
2018-02-12 14:23:39 +03:00
|
|
|
$this->expectSyntaxError(
|
|
|
|
'union Hello = Wo || Rld',
|
|
|
|
'Expected Name, found |',
|
|
|
|
$this->loc(1, 19)
|
|
|
|
);
|
2017-07-05 14:42:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Union fails with trailing pipe
|
|
|
|
*/
|
|
|
|
public function testUnionFailsWithTrailingPipe()
|
|
|
|
{
|
2018-02-12 14:23:39 +03:00
|
|
|
$this->expectSyntaxError(
|
|
|
|
'union Hello = | Wo | Rld |',
|
|
|
|
'Expected Name, found <EOF>',
|
|
|
|
$this->loc(1, 27)
|
|
|
|
);
|
2017-07-05 14:42:27 +03:00
|
|
|
}
|
|
|
|
|
2016-04-23 21:24:41 +03:00
|
|
|
/**
|
|
|
|
* @it Scalar
|
|
|
|
*/
|
|
|
|
public function testScalar()
|
|
|
|
{
|
|
|
|
$body = 'scalar Hello';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::SCALAR_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(7, 12)),
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(0, 12),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
|
|
|
'loc' => $loc(0, 12)
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple input object
|
|
|
|
*/
|
|
|
|
public function testSimpleInputObject()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
input Hello {
|
|
|
|
world: String
|
|
|
|
}';
|
|
|
|
$doc = Parser::parse($body);
|
2016-10-16 22:57:24 +03:00
|
|
|
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
|
2016-04-23 21:24:41 +03:00
|
|
|
|
2016-10-16 22:57:24 +03:00
|
|
|
$expected = [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::DOCUMENT,
|
2016-04-23 21:24:41 +03:00
|
|
|
'definitions' => [
|
2016-10-16 22:57:24 +03:00
|
|
|
[
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::INPUT_OBJECT_TYPE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode('Hello', $loc(7, 12)),
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2016-04-23 21:24:41 +03:00
|
|
|
'fields' => [
|
|
|
|
$this->inputValueNode(
|
|
|
|
$this->nameNode('world', $loc(17, 22)),
|
|
|
|
$this->typeNode('String', $loc(24, 30)),
|
|
|
|
null,
|
|
|
|
$loc(17, 30)
|
|
|
|
)
|
|
|
|
],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc(1, 32),
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
]
|
2016-04-23 21:24:41 +03:00
|
|
|
],
|
2016-10-16 22:57:24 +03:00
|
|
|
'loc' => $loc(0, 32)
|
|
|
|
];
|
|
|
|
$this->assertEquals($expected, TestUtils::nodeToArray($doc));
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Simple input object with args should fail
|
|
|
|
*/
|
|
|
|
public function testSimpleInputObjectWithArgsShouldFail()
|
|
|
|
{
|
|
|
|
$body = '
|
2018-02-12 14:23:39 +03:00
|
|
|
input Hello {
|
|
|
|
world(foo: Int): String
|
|
|
|
}';
|
|
|
|
$this->expectSyntaxError(
|
|
|
|
$body,
|
|
|
|
'Expected :, found (',
|
|
|
|
$this->loc(3, 14)
|
|
|
|
);
|
2018-02-11 15:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it Directive with incorrect locations
|
|
|
|
*/
|
|
|
|
public function testDirectiveWithIncorrectLocationShouldFail()
|
|
|
|
{
|
|
|
|
$body = '
|
|
|
|
directive @foo on FIELD | INCORRECT_LOCATION
|
|
|
|
';
|
2018-02-12 14:23:39 +03:00
|
|
|
$this->expectSyntaxError(
|
|
|
|
$body,
|
|
|
|
'Unexpected Name "INCORRECT_LOCATION"',
|
|
|
|
$this->loc(2, 33)
|
|
|
|
);
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function typeNode($name, $loc)
|
|
|
|
{
|
2016-10-16 22:57:24 +03:00
|
|
|
return [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::NAMED_TYPE,
|
|
|
|
'name' => ['kind' => NodeKind::NAME, 'value' => $name, 'loc' => $loc],
|
2016-04-23 21:24:41 +03:00
|
|
|
'loc' => $loc
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function nameNode($name, $loc)
|
|
|
|
{
|
2016-10-16 22:57:24 +03:00
|
|
|
return [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::NAME,
|
2016-04-23 21:24:41 +03:00
|
|
|
'value' => $name,
|
|
|
|
'loc' => $loc
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function fieldNode($name, $type, $loc)
|
|
|
|
{
|
|
|
|
return $this->fieldNodeWithArgs($name, $type, [], $loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function fieldNodeWithArgs($name, $type, $args, $loc)
|
|
|
|
{
|
2016-10-16 22:57:24 +03:00
|
|
|
return [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::FIELD_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $name,
|
|
|
|
'arguments' => $args,
|
|
|
|
'type' => $type,
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc,
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function enumValueNode($name, $loc)
|
|
|
|
{
|
2016-10-16 22:57:24 +03:00
|
|
|
return [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::ENUM_VALUE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $this->nameNode($name, $loc),
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc,
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function inputValueNode($name, $type, $defaultValue, $loc)
|
|
|
|
{
|
2016-10-16 22:57:24 +03:00
|
|
|
return [
|
2016-11-19 13:31:47 +03:00
|
|
|
'kind' => NodeKind::INPUT_VALUE_DEFINITION,
|
2016-04-23 21:24:41 +03:00
|
|
|
'name' => $name,
|
|
|
|
'type' => $type,
|
|
|
|
'defaultValue' => $defaultValue,
|
2016-10-16 22:57:24 +03:00
|
|
|
'directives' => [],
|
2017-02-03 16:03:29 +03:00
|
|
|
'loc' => $loc,
|
|
|
|
'description' => null
|
2016-10-16 22:57:24 +03:00
|
|
|
];
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|
2018-02-12 14:23:39 +03:00
|
|
|
|
|
|
|
private function loc($line, $column)
|
|
|
|
{
|
|
|
|
return new SourceLocation($line, $column);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function expectSyntaxError($text, $message, $location)
|
|
|
|
{
|
|
|
|
$this->setExpectedException(SyntaxError::class, $message);
|
|
|
|
try {
|
|
|
|
Parser::parse($text);
|
|
|
|
} catch (SyntaxError $error) {
|
|
|
|
$this->assertEquals([$location], $error->getLocations());
|
|
|
|
throw $error;
|
|
|
|
}
|
|
|
|
}
|
2016-04-23 21:24:41 +03:00
|
|
|
}
|