mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 14:26:08 +03:00
Uniform parsing of queries with short-hand syntax with regular queries
This commit is contained in:
parent
eb9ac66af8
commit
46816a7cda
@ -370,7 +370,7 @@ class Parser
|
|||||||
return new OperationDefinitionNode([
|
return new OperationDefinitionNode([
|
||||||
'operation' => 'query',
|
'operation' => 'query',
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'variableDefinitions' => null,
|
'variableDefinitions' => new NodeList([]),
|
||||||
'directives' => new NodeList([]),
|
'directives' => new NodeList([]),
|
||||||
'selectionSet' => $this->parseSelectionSet(),
|
'selectionSet' => $this->parseSelectionSet(),
|
||||||
'loc' => $this->loc($start)
|
'loc' => $this->loc($start)
|
||||||
|
@ -276,7 +276,7 @@ fragment $fragmentName on Type {
|
|||||||
'loc' => $loc(0, 40),
|
'loc' => $loc(0, 40),
|
||||||
'operation' => 'query',
|
'operation' => 'query',
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'variableDefinitions' => null,
|
'variableDefinitions' => [],
|
||||||
'directives' => [],
|
'directives' => [],
|
||||||
'selectionSet' => [
|
'selectionSet' => [
|
||||||
'kind' => NodeKind::SELECTION_SET,
|
'kind' => NodeKind::SELECTION_SET,
|
||||||
@ -350,6 +350,81 @@ fragment $fragmentName on Type {
|
|||||||
$this->assertEquals($expected, $this->nodeToArray($result));
|
$this->assertEquals($expected, $this->nodeToArray($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @it creates ast from nameless query without variables
|
||||||
|
*/
|
||||||
|
public function testParseCreatesAstFromNamelessQueryWithoutVariables()
|
||||||
|
{
|
||||||
|
$source = new Source('query {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
');
|
||||||
|
$result = Parser::parse($source);
|
||||||
|
|
||||||
|
$loc = function($start, $end) use ($source) {
|
||||||
|
return [
|
||||||
|
'start' => $start,
|
||||||
|
'end' => $end
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
$expected = [
|
||||||
|
'kind' => NodeKind::DOCUMENT,
|
||||||
|
'loc' => $loc(0, 30),
|
||||||
|
'definitions' => [
|
||||||
|
[
|
||||||
|
'kind' => NodeKind::OPERATION_DEFINITION,
|
||||||
|
'loc' => $loc(0, 29),
|
||||||
|
'operation' => 'query',
|
||||||
|
'name' => null,
|
||||||
|
'variableDefinitions' => [],
|
||||||
|
'directives' => [],
|
||||||
|
'selectionSet' => [
|
||||||
|
'kind' => NodeKind::SELECTION_SET,
|
||||||
|
'loc' => $loc(6, 29),
|
||||||
|
'selections' => [
|
||||||
|
[
|
||||||
|
'kind' => NodeKind::FIELD,
|
||||||
|
'loc' => $loc(10, 27),
|
||||||
|
'alias' => null,
|
||||||
|
'name' => [
|
||||||
|
'kind' => NodeKind::NAME,
|
||||||
|
'loc' => $loc(10, 14),
|
||||||
|
'value' => 'node'
|
||||||
|
],
|
||||||
|
'arguments' => [],
|
||||||
|
'directives' => [],
|
||||||
|
'selectionSet' => [
|
||||||
|
'kind' => NodeKind::SELECTION_SET,
|
||||||
|
'loc' => $loc(15, 27),
|
||||||
|
'selections' => [
|
||||||
|
[
|
||||||
|
'kind' => NodeKind::FIELD,
|
||||||
|
'loc' => $loc(21, 23),
|
||||||
|
'alias' => null,
|
||||||
|
'name' => [
|
||||||
|
'kind' => NodeKind::NAME,
|
||||||
|
'loc' => $loc(21, 23),
|
||||||
|
'value' => 'id'
|
||||||
|
],
|
||||||
|
'arguments' => [],
|
||||||
|
'directives' => [],
|
||||||
|
'selectionSet' => null
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $this->nodeToArray($result));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it allows parsing without source location information
|
* @it allows parsing without source location information
|
||||||
*/
|
*/
|
||||||
|
@ -575,6 +575,7 @@
|
|||||||
{
|
{
|
||||||
"kind": "OperationDefinition",
|
"kind": "OperationDefinition",
|
||||||
"operation": "query",
|
"operation": "query",
|
||||||
|
"variableDefinitions": [],
|
||||||
"directives": [],
|
"directives": [],
|
||||||
"selectionSet": {
|
"selectionSet": {
|
||||||
"kind": "SelectionSet",
|
"kind": "SelectionSet",
|
||||||
|
@ -1127,6 +1127,7 @@
|
|||||||
"end": 1086
|
"end": 1086
|
||||||
},
|
},
|
||||||
"operation": "query",
|
"operation": "query",
|
||||||
|
"variableDefinitions": [],
|
||||||
"directives": [],
|
"directives": [],
|
||||||
"selectionSet": {
|
"selectionSet": {
|
||||||
"kind": "SelectionSet",
|
"kind": "SelectionSet",
|
||||||
|
Loading…
Reference in New Issue
Block a user