From ea29c8f030c4660d8d414265f0ff9f5958aba81c Mon Sep 17 00:00:00 2001 From: Hans Ott Date: Fri, 1 Dec 2017 20:30:14 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bug=20with=20integer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It failed to parse '100' & '200' --- src/Query/Lexer.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Query/Lexer.php b/src/Query/Lexer.php index ca9c2fb..e140e81 100644 --- a/src/Query/Lexer.php +++ b/src/Query/Lexer.php @@ -131,21 +131,25 @@ private function str() private function integerPart() { - $number = $this->scanner->next(); + if ($this->scanner->eof()) { + throw $this->getError('Expected an integer or a float but instead reached end'); + } + $location = $this->getLocation(); - if ($number === '-') { + $next = $this->scanner->peek(); + $number = ''; + if ($next === '-') { + $number .= $next; + $this->scanner->next(); if ($this->scanner->eof()) { - throw $this->getError('Expected a digit but instead reached end'); - } - $next = $this->scanner->peek(); - if (ctype_digit($next) === false) { - throw $this->getError("Expected a digit but instead found \"{$next}\""); + throw $this->getError('Expected an integer or a float but instead reached end'); } } $next = $this->scanner->peek(); if ($next === '0') { - $number .= $this->scanner->next(); + $number .= $next; + $this->scanner->next(); return array($number, $location); } From d3f2e5e52126ee518fb1d4eea4d37f605f45e61e Mon Sep 17 00:00:00 2001 From: Hans Ott Date: Fri, 1 Dec 2017 20:31:04 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20Make=20name=20of=20mutation?= =?UTF-8?q?=20and=20subscription=20optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Query/Parser.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Query/Parser.php b/src/Query/Parser.php index 1801f0a..1b920be 100644 --- a/src/Query/Parser.php +++ b/src/Query/Parser.php @@ -369,7 +369,12 @@ private function parseDefinition() if ($this->is(Token::T_MUTATION)) { $location = $this->expect(Token::T_MUTATION)->location; - $name = $this->expect(Token::T_NAME)->value; + + $name = null; + if ($this->is(Token::T_NAME)) { + $name = $this->expect(Token::T_NAME)->value; + } + $variables = $this->parseVariableDefinitionList(); $directives = $this->parseDirectiveList(); $selectionSet = $this->parseSelectionSet(); @@ -379,7 +384,12 @@ private function parseDefinition() if ($this->is(Token::T_SUBSCRIPTION)) { $location = $this->expect(Token::T_SUBSCRIPTION)->location; - $name = $this->expect(Token::T_NAME)->value; + + $name = null; + if ($this->is(Token::T_NAME)) { + $name = $this->expect(Token::T_NAME)->value; + } + $variables = $this->parseVariableDefinitionList(); $directives = $this->parseDirectiveList(); $selectionSet = $this->parseSelectionSet(); From ed44f9f7b4849deea80b1c71c8c8fa94b1389d80 Mon Sep 17 00:00:00 2001 From: Hans Ott Date: Fri, 1 Dec 2017 20:31:51 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85=20Improve=20test=20suite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will make adding tests much easier. Constructing these AST objects by hand is error prone and BORING --- .editorconfig | 3 + bin/graphql-parser | 36 ++ composer.json | 3 +- src/Query/Parser.php | 2 + tests/ParserTest.php | 40 +++ .../test_it_parses_a_mutation_like_story | 163 +++++++++ tests/parsing/test_it_parses_a_named_query | 104 ++++++ ...test_it_parses_a_query_with_a_single_field | 67 ++++ ..._a_short_hand_query_with_a_field_of_a_type | 100 ++++++ ...ses_a_short_hand_query_with_a_single_field | 67 ++++ tests/parsing/test_it_parses_aliases | 128 +++++++ tests/parsing/test_it_parses_all_values | 274 ++++++++++++++ tests/parsing/test_it_parses_an_empty_doc | 8 + .../test_it_parses_an_empty_short_hand_query | 45 +++ tests/parsing/test_it_parses_directives | 154 ++++++++ ...t_it_parses_fields_with_multiple_arguments | 117 ++++++ tests/parsing/test_it_parses_fragments | 339 ++++++++++++++++++ tests/parsing/test_it_parses_inline_fragments | 227 ++++++++++++ tests/parsing/test_it_parses_input_objects | 142 ++++++++ .../parsing/test_it_parses_list_of_named_type | 149 ++++++++ tests/parsing/test_it_parses_nested_fields | 289 +++++++++++++++ .../parsing/test_it_parses_strings_with_emoji | 92 +++++ .../parsing/test_it_parses_user_with_id_name | 128 +++++++ tests/parsing/test_it_parses_variables | 234 ++++++++++++ tests/parsing/test_it_parses_with_comments | 130 +++++++ 25 files changed, 3040 insertions(+), 1 deletion(-) create mode 100755 bin/graphql-parser create mode 100644 tests/ParserTest.php create mode 100644 tests/parsing/test_it_parses_a_mutation_like_story create mode 100644 tests/parsing/test_it_parses_a_named_query create mode 100644 tests/parsing/test_it_parses_a_query_with_a_single_field create mode 100644 tests/parsing/test_it_parses_a_short_hand_query_with_a_field_of_a_type create mode 100644 tests/parsing/test_it_parses_a_short_hand_query_with_a_single_field create mode 100644 tests/parsing/test_it_parses_aliases create mode 100644 tests/parsing/test_it_parses_all_values create mode 100644 tests/parsing/test_it_parses_an_empty_doc create mode 100644 tests/parsing/test_it_parses_an_empty_short_hand_query create mode 100644 tests/parsing/test_it_parses_directives create mode 100644 tests/parsing/test_it_parses_fields_with_multiple_arguments create mode 100644 tests/parsing/test_it_parses_fragments create mode 100644 tests/parsing/test_it_parses_inline_fragments create mode 100644 tests/parsing/test_it_parses_input_objects create mode 100644 tests/parsing/test_it_parses_list_of_named_type create mode 100644 tests/parsing/test_it_parses_nested_fields create mode 100644 tests/parsing/test_it_parses_strings_with_emoji create mode 100644 tests/parsing/test_it_parses_user_with_id_name create mode 100644 tests/parsing/test_it_parses_variables create mode 100644 tests/parsing/test_it_parses_with_comments diff --git a/.editorconfig b/.editorconfig index cd8eb86..63cb0ed 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[/tests/parsing/*] +indent_size = 2 diff --git a/bin/graphql-parser b/bin/graphql-parser new file mode 100755 index 0000000..25c4fe1 --- /dev/null +++ b/bin/graphql-parser @@ -0,0 +1,36 @@ +#!/usr/bin/env php +create(); + +try { + $document = $parser->parse($graphql); +} catch (\HansOtt\GraphQL\Shared\SyntaxError $e) { + echo "Syntax Error: {$e->getMessage()}\n"; + exit(1); +} catch (\HansOtt\GraphQL\Shared\ParseError $e) { + echo "Parse Error: {$e->getMessage()}\n"; + exit(1); +} + +var_dump($document); diff --git a/composer.json b/composer.json index 13c6646..553f1c7 100644 --- a/composer.json +++ b/composer.json @@ -40,5 +40,6 @@ }, "config": { "sort-packages": true - } + }, + "bin": ["bin/graphql-parser"] } diff --git a/src/Query/Parser.php b/src/Query/Parser.php index 1b920be..4de8f1d 100644 --- a/src/Query/Parser.php +++ b/src/Query/Parser.php @@ -442,6 +442,8 @@ private function parseDocument() /** * @param string $query * + * @throws \HansOtt\GraphQL\Shared\SyntaxError + * * @return Document */ public function parse($query) diff --git a/tests/ParserTest.php b/tests/ParserTest.php new file mode 100644 index 0000000..530d78d --- /dev/null +++ b/tests/ParserTest.php @@ -0,0 +1,40 @@ +fail("{$file} is not a valid test case"); + } + list ($graphql, $expectedOutput) = $parts; + $pathInfo = pathinfo($file); + $cases[] = array($graphql, trim($expectedOutput), $pathInfo['filename']); + } + + return $cases; + } + + /** + * @dataProvider getParseTests + * + * @param string $graphql + * @param string $expectedOutput + * @param string $message + */ + public function test_it_parses_graphql($graphql, $expectedOutput, $message) + { + $graphql = escapeshellarg($graphql); + $output = shell_exec(__DIR__."/../bin/graphql-parser {$graphql}"); + $this->assertEquals($expectedOutput, trim($output), $message); + } +} diff --git a/tests/parsing/test_it_parses_a_mutation_like_story b/tests/parsing/test_it_parses_a_mutation_like_story new file mode 100644 index 0000000..0f566f7 --- /dev/null +++ b/tests/parsing/test_it_parses_a_mutation_like_story @@ -0,0 +1,163 @@ +mutation { + likeStory(storyID: 12345) { + story { + likeCount + } + } +} +---- +object(HansOtt\GraphQL\Query\Document)#47 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationMutation)#46 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#45 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#44 (6) { + ["name"]=> + string(9) "likeStory" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#39 (3) { + ["name"]=> + string(7) "storyID" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueInt)#38 (2) { + ["value"]=> + int(12345) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#18 (2) { + ["line"]=> + int(2) + ["column"]=> + int(22) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#14 (2) { + ["line"]=> + int(2) + ["column"]=> + int(14) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#43 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#42 (6) { + ["name"]=> + string(5) "story" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#41 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#40 (6) { + ["name"]=> + string(9) "likeCount" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#28 (2) { + ["line"]=> + int(4) + ["column"]=> + int(8) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#26 (2) { + ["line"]=> + int(3) + ["column"]=> + int(12) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#24 (2) { + ["line"]=> + int(3) + ["column"]=> + int(6) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#22 (2) { + ["line"]=> + int(2) + ["column"]=> + int(30) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#10 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(1) + ["column"]=> + int(10) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_a_named_query b/tests/parsing/test_it_parses_a_named_query new file mode 100644 index 0000000..49a5b89 --- /dev/null +++ b/tests/parsing/test_it_parses_a_named_query @@ -0,0 +1,104 @@ +query getAuthor { + author { + name + } +} +---- +object(HansOtt\GraphQL\Query\Document)#29 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#28 (5) { + ["name"]=> + string(9) "getAuthor" + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#27 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#26 (6) { + ["name"]=> + string(6) "author" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#25 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#24 (6) { + ["name"]=> + string(4) "name" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(3) + ["column"]=> + int(6) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#14 (2) { + ["line"]=> + int(2) + ["column"]=> + int(11) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#10 (2) { + ["line"]=> + int(1) + ["column"]=> + int(17) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_a_query_with_a_single_field b/tests/parsing/test_it_parses_a_query_with_a_single_field new file mode 100644 index 0000000..217522d --- /dev/null +++ b/tests/parsing/test_it_parses_a_query_with_a_single_field @@ -0,0 +1,67 @@ +query { author } +---- +object(HansOtt\GraphQL\Query\Document)#19 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#18 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#17 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#16 (6) { + ["name"]=> + string(6) "author" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#10 (2) { + ["line"]=> + int(1) + ["column"]=> + int(9) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(1) + ["column"]=> + int(7) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_a_short_hand_query_with_a_field_of_a_type b/tests/parsing/test_it_parses_a_short_hand_query_with_a_field_of_a_type new file mode 100644 index 0000000..cf5e6da --- /dev/null +++ b/tests/parsing/test_it_parses_a_short_hand_query_with_a_field_of_a_type @@ -0,0 +1,100 @@ +{ author { name } } +---- +object(HansOtt\GraphQL\Query\Document)#25 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#24 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#23 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#22 (6) { + ["name"]=> + string(6) "author" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#21 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#20 (6) { + ["name"]=> + string(4) "name" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(1) + ["column"]=> + int(12) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#10 (2) { + ["line"]=> + int(1) + ["column"]=> + int(10) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(1) + ["column"]=> + int(3) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_a_short_hand_query_with_a_single_field b/tests/parsing/test_it_parses_a_short_hand_query_with_a_single_field new file mode 100644 index 0000000..a3db9e3 --- /dev/null +++ b/tests/parsing/test_it_parses_a_short_hand_query_with_a_single_field @@ -0,0 +1,67 @@ +{ author } +---- +object(HansOtt\GraphQL\Query\Document)#17 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#16 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#15 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#14 (6) { + ["name"]=> + string(6) "author" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(1) + ["column"]=> + int(3) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_aliases b/tests/parsing/test_it_parses_aliases new file mode 100644 index 0000000..6daa313 --- /dev/null +++ b/tests/parsing/test_it_parses_aliases @@ -0,0 +1,128 @@ +{ + first: changeTheNumber(newNumber: 1) { + theNumber + } +} +---- +object(HansOtt\GraphQL\Query\Document)#41 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#40 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#39 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#38 (6) { + ["name"]=> + string(15) "changeTheNumber" + ["alias"]=> + string(5) "first" + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#35 (3) { + ["name"]=> + string(9) "newNumber" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueInt)#34 (2) { + ["value"]=> + int(1) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(2) + ["column"]=> + int(37) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(2) + ["column"]=> + int(27) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#37 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#36 (6) { + ["name"]=> + string(9) "theNumber" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#26 (2) { + ["line"]=> + int(3) + ["column"]=> + int(6) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#24 (2) { + ["line"]=> + int(2) + ["column"]=> + int(41) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_all_values b/tests/parsing/test_it_parses_all_values new file mode 100644 index 0000000..13cc62f --- /dev/null +++ b/tests/parsing/test_it_parses_all_values @@ -0,0 +1,274 @@ +{ author(id: [1, $name, PUBLISHED, "string", 1.0, null, true, false, ["nested list"], { nestedObject: { nestedObject: {} } }]) } +---- +object(HansOtt\GraphQL\Query\Document)#108 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#107 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#106 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#105 (6) { + ["name"]=> + string(6) "author" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#104 (3) { + ["name"]=> + string(2) "id" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueList)#103 (2) { + ["values":"HansOtt\GraphQL\Query\ValueList":private]=> + array(10) { + [0]=> + object(HansOtt\GraphQL\Query\ValueInt)#88 (2) { + ["value"]=> + int(1) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#18 (2) { + ["line"]=> + int(1) + ["column"]=> + int(14) + } + } + [1]=> + object(HansOtt\GraphQL\Query\ValueVariable)#89 (2) { + ["name"]=> + string(4) "name" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#22 (2) { + ["line"]=> + int(1) + ["column"]=> + int(18) + } + } + [2]=> + object(HansOtt\GraphQL\Query\ValueEnum)#90 (2) { + ["value"]=> + string(9) "PUBLISHED" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#28 (2) { + ["line"]=> + int(1) + ["column"]=> + int(25) + } + } + [3]=> + object(HansOtt\GraphQL\Query\ValueString)#91 (2) { + ["value"]=> + string(6) "string" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#32 (2) { + ["line"]=> + int(1) + ["column"]=> + int(36) + } + } + [4]=> + object(HansOtt\GraphQL\Query\ValueFloat)#92 (2) { + ["value"]=> + float(1) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#36 (2) { + ["line"]=> + int(1) + ["column"]=> + int(45) + } + } + [5]=> + object(HansOtt\GraphQL\Query\ValueNull)#93 (1) { + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#40 (2) { + ["line"]=> + int(1) + ["column"]=> + int(51) + } + } + [6]=> + object(HansOtt\GraphQL\Query\ValueBoolean)#94 (2) { + ["isTrue":"HansOtt\GraphQL\Query\ValueBoolean":private]=> + bool(true) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#44 (2) { + ["line"]=> + int(1) + ["column"]=> + int(57) + } + } + [7]=> + object(HansOtt\GraphQL\Query\ValueBoolean)#95 (2) { + ["isTrue":"HansOtt\GraphQL\Query\ValueBoolean":private]=> + bool(false) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#48 (2) { + ["line"]=> + int(1) + ["column"]=> + int(63) + } + } + [8]=> + object(HansOtt\GraphQL\Query\ValueList)#97 (2) { + ["values":"HansOtt\GraphQL\Query\ValueList":private]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\ValueString)#96 (2) { + ["value"]=> + string(11) "nested list" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#54 (2) { + ["line"]=> + int(1) + ["column"]=> + int(71) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#52 (2) { + ["line"]=> + int(1) + ["column"]=> + int(70) + } + } + [9]=> + object(HansOtt\GraphQL\Query\ValueObject)#102 (2) { + ["fields"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\ValueObjectField)#98 (3) { + ["name"]=> + string(12) "nestedObject" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueObject)#101 (2) { + ["fields"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\ValueObjectField)#99 (3) { + ["name"]=> + string(12) "nestedObject" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueObject)#100 (2) { + ["fields"]=> + array(0) { + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#72 (2) { + ["line"]=> + int(1) + ["column"]=> + int(119) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#68 (2) { + ["line"]=> + int(1) + ["column"]=> + int(105) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#66 (2) { + ["line"]=> + int(1) + ["column"]=> + int(103) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#62 (2) { + ["line"]=> + int(1) + ["column"]=> + int(89) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#60 (2) { + ["line"]=> + int(1) + ["column"]=> + int(87) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(1) + ["column"]=> + int(14) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(1) + ["column"]=> + int(10) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(1) + ["column"]=> + int(3) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_an_empty_doc b/tests/parsing/test_it_parses_an_empty_doc new file mode 100644 index 0000000..c84994e --- /dev/null +++ b/tests/parsing/test_it_parses_an_empty_doc @@ -0,0 +1,8 @@ +---- +object(HansOtt\GraphQL\Query\Document)#8 (2) { + ["definitions"]=> + array(0) { + } + ["location"]=> + NULL +} diff --git a/tests/parsing/test_it_parses_an_empty_short_hand_query b/tests/parsing/test_it_parses_an_empty_short_hand_query new file mode 100644 index 0000000..b46376c --- /dev/null +++ b/tests/parsing/test_it_parses_an_empty_short_hand_query @@ -0,0 +1,45 @@ +{} +---- +object(HansOtt\GraphQL\Query\Document)#14 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#13 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#12 (2) { + ["selections"]=> + array(0) { + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_directives b/tests/parsing/test_it_parses_directives new file mode 100644 index 0000000..462b404 --- /dev/null +++ b/tests/parsing/test_it_parses_directives @@ -0,0 +1,154 @@ +{ + foo @skip(if: true) + bar + foo +} +---- +object(HansOtt\GraphQL\Query\Document)#40 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#39 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#38 (2) { + ["selections"]=> + array(3) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#35 (6) { + ["name"]=> + string(3) "foo" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Directive)#34 (3) { + ["name"]=> + string(4) "skip" + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#33 (3) { + ["name"]=> + string(2) "if" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueBoolean)#32 (2) { + ["isTrue":"HansOtt\GraphQL\Query\ValueBoolean":private]=> + bool(true) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(2) + ["column"]=> + int(18) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(2) + ["column"]=> + int(14) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#10 (2) { + ["line"]=> + int(2) + ["column"]=> + int(8) + } + } + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + [1]=> + object(HansOtt\GraphQL\Query\SelectionField)#36 (6) { + ["name"]=> + string(3) "bar" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#24 (2) { + ["line"]=> + int(3) + ["column"]=> + int(4) + } + } + [2]=> + object(HansOtt\GraphQL\Query\SelectionField)#37 (6) { + ["name"]=> + string(3) "foo" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#26 (2) { + ["line"]=> + int(4) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_fields_with_multiple_arguments b/tests/parsing/test_it_parses_fields_with_multiple_arguments new file mode 100644 index 0000000..9a73c33 --- /dev/null +++ b/tests/parsing/test_it_parses_fields_with_multiple_arguments @@ -0,0 +1,117 @@ +{ + picture(width: 200, height: 100) +} +---- +object(HansOtt\GraphQL\Query\Document)#39 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#38 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#37 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#36 (6) { + ["name"]=> + string(7) "picture" + ["alias"]=> + NULL + ["arguments"]=> + array(2) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#33 (3) { + ["name"]=> + string(5) "width" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueInt)#32 (2) { + ["value"]=> + int(200) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(2) + ["column"]=> + int(18) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(2) + ["column"]=> + int(12) + } + } + [1]=> + object(HansOtt\GraphQL\Query\Argument)#35 (3) { + ["name"]=> + string(6) "height" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueInt)#34 (2) { + ["value"]=> + int(100) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#24 (2) { + ["line"]=> + int(2) + ["column"]=> + int(31) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(2) + ["column"]=> + int(24) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_fragments b/tests/parsing/test_it_parses_fragments new file mode 100644 index 0000000..422afe1 --- /dev/null +++ b/tests/parsing/test_it_parses_fragments @@ -0,0 +1,339 @@ +{ + foo + ...Ignored + ...Matching + bar +} + +fragment Ignored on UnknownType { + qux + baz +} + +fragment Matching on Query { + bar + qux + foo +} +---- +object(HansOtt\GraphQL\Query\Document)#77 (2) { + ["definitions"]=> + array(3) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#63 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#62 (2) { + ["selections"]=> + array(4) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#58 (6) { + ["name"]=> + string(3) "foo" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + [1]=> + object(HansOtt\GraphQL\Query\SelectionFragmentSpread)#59 (2) { + ["fragmentName"]=> + string(7) "Ignored" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#10 (2) { + ["line"]=> + int(3) + ["column"]=> + int(4) + } + } + [2]=> + object(HansOtt\GraphQL\Query\SelectionFragmentSpread)#60 (2) { + ["fragmentName"]=> + string(8) "Matching" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#14 (2) { + ["line"]=> + int(4) + ["column"]=> + int(4) + } + } + [3]=> + object(HansOtt\GraphQL\Query\SelectionField)#61 (6) { + ["name"]=> + string(3) "bar" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#18 (2) { + ["line"]=> + int(5) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + [1]=> + object(HansOtt\GraphQL\Query\Fragment)#69 (5) { + ["name"]=> + string(7) "Ignored" + ["typeCondition"]=> + object(HansOtt\GraphQL\Query\TypeCondition)#65 (2) { + ["namedType"]=> + object(HansOtt\GraphQL\Query\TypeNamed)#64 (2) { + ["name"]=> + string(11) "UnknownType" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#28 (2) { + ["line"]=> + int(8) + ["column"]=> + int(22) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#26 (2) { + ["line"]=> + int(8) + ["column"]=> + int(19) + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#68 (2) { + ["selections"]=> + array(2) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#66 (6) { + ["name"]=> + string(3) "qux" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#32 (2) { + ["line"]=> + int(9) + ["column"]=> + int(4) + } + } + [1]=> + object(HansOtt\GraphQL\Query\SelectionField)#67 (6) { + ["name"]=> + string(3) "baz" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#34 (2) { + ["line"]=> + int(10) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#30 (2) { + ["line"]=> + int(8) + ["column"]=> + int(34) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#22 (2) { + ["line"]=> + int(8) + ["column"]=> + int(2) + } + } + [2]=> + object(HansOtt\GraphQL\Query\Fragment)#76 (5) { + ["name"]=> + string(8) "Matching" + ["typeCondition"]=> + object(HansOtt\GraphQL\Query\TypeCondition)#71 (2) { + ["namedType"]=> + object(HansOtt\GraphQL\Query\TypeNamed)#70 (2) { + ["name"]=> + string(5) "Query" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#44 (2) { + ["line"]=> + int(13) + ["column"]=> + int(23) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#42 (2) { + ["line"]=> + int(13) + ["column"]=> + int(20) + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#75 (2) { + ["selections"]=> + array(3) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#72 (6) { + ["name"]=> + string(3) "bar" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#48 (2) { + ["line"]=> + int(14) + ["column"]=> + int(4) + } + } + [1]=> + object(HansOtt\GraphQL\Query\SelectionField)#73 (6) { + ["name"]=> + string(3) "qux" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#50 (2) { + ["line"]=> + int(15) + ["column"]=> + int(4) + } + } + [2]=> + object(HansOtt\GraphQL\Query\SelectionField)#74 (6) { + ["name"]=> + string(3) "foo" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#52 (2) { + ["line"]=> + int(16) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#46 (2) { + ["line"]=> + int(13) + ["column"]=> + int(29) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#38 (2) { + ["line"]=> + int(13) + ["column"]=> + int(2) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_inline_fragments b/tests/parsing/test_it_parses_inline_fragments new file mode 100644 index 0000000..a62d5b8 --- /dev/null +++ b/tests/parsing/test_it_parses_inline_fragments @@ -0,0 +1,227 @@ +{ + firstSearchResult { + ... on Person { + name + } + ... on Photo { + height + } + } +} +---- +object(HansOtt\GraphQL\Query\Document)#56 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#55 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#54 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#53 (6) { + ["name"]=> + string(17) "firstSearchResult" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#52 (2) { + ["selections"]=> + array(2) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionInlineFragment)#46 (4) { + ["typeCondition"]=> + object(HansOtt\GraphQL\Query\TypeCondition)#43 (2) { + ["namedType"]=> + object(HansOtt\GraphQL\Query\TypeNamed)#42 (2) { + ["name"]=> + string(6) "Person" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(3) + ["column"]=> + int(13) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#14 (2) { + ["line"]=> + int(3) + ["column"]=> + int(10) + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#45 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#44 (6) { + ["name"]=> + string(4) "name" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(4) + ["column"]=> + int(8) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#18 (2) { + ["line"]=> + int(3) + ["column"]=> + int(20) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(3) + ["column"]=> + int(6) + } + } + [1]=> + object(HansOtt\GraphQL\Query\SelectionInlineFragment)#51 (4) { + ["typeCondition"]=> + object(HansOtt\GraphQL\Query\TypeCondition)#48 (2) { + ["namedType"]=> + object(HansOtt\GraphQL\Query\TypeNamed)#47 (2) { + ["name"]=> + string(5) "Photo" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#28 (2) { + ["line"]=> + int(6) + ["column"]=> + int(13) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#26 (2) { + ["line"]=> + int(6) + ["column"]=> + int(10) + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#50 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#49 (6) { + ["name"]=> + string(6) "height" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#32 (2) { + ["line"]=> + int(7) + ["column"]=> + int(8) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#30 (2) { + ["line"]=> + int(6) + ["column"]=> + int(19) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#24 (2) { + ["line"]=> + int(6) + ["column"]=> + int(6) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#10 (2) { + ["line"]=> + int(2) + ["column"]=> + int(22) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_input_objects b/tests/parsing/test_it_parses_input_objects new file mode 100644 index 0000000..147d76f --- /dev/null +++ b/tests/parsing/test_it_parses_input_objects @@ -0,0 +1,142 @@ +{ + nearestThing(location: { lon: 12.43, lat: -53.211 }) +} +---- +object(HansOtt\GraphQL\Query\Document)#49 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#48 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#47 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#46 (6) { + ["name"]=> + string(12) "nearestThing" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#45 (3) { + ["name"]=> + string(8) "location" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueObject)#44 (2) { + ["fields"]=> + array(2) { + [0]=> + object(HansOtt\GraphQL\Query\ValueObjectField)#40 (3) { + ["name"]=> + string(3) "lon" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueFloat)#41 (2) { + ["value"]=> + float(12.43) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#22 (2) { + ["line"]=> + int(2) + ["column"]=> + int(33) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#18 (2) { + ["line"]=> + int(2) + ["column"]=> + int(29) + } + } + [1]=> + object(HansOtt\GraphQL\Query\ValueObjectField)#42 (3) { + ["name"]=> + string(3) "lat" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueFloat)#43 (2) { + ["value"]=> + float(-53.211) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#30 (2) { + ["line"]=> + int(2) + ["column"]=> + int(45) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#26 (2) { + ["line"]=> + int(2) + ["column"]=> + int(41) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(2) + ["column"]=> + int(27) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(2) + ["column"]=> + int(17) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_list_of_named_type b/tests/parsing/test_it_parses_list_of_named_type new file mode 100644 index 0000000..56ea6dc --- /dev/null +++ b/tests/parsing/test_it_parses_list_of_named_type @@ -0,0 +1,149 @@ +query TakesListOfBooleanBang($booleans: [Boolean!]) { + booleanList(booleanListArg: $booleans) +} +---- +object(HansOtt\GraphQL\Query\Document)#58 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#57 (5) { + ["name"]=> + string(22) "TakesListOfBooleanBang" + ["variables"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\VariableDefinition)#52 (4) { + ["variable"]=> + object(HansOtt\GraphQL\Query\ValueVariable)#48 (2) { + ["name"]=> + string(8) "booleans" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(1) + ["column"]=> + int(30) + } + } + ["type"]=> + object(HansOtt\GraphQL\Query\TypeList)#51 (2) { + ["type"]=> + object(HansOtt\GraphQL\Query\TypeNonNull)#50 (2) { + ["type"]=> + object(HansOtt\GraphQL\Query\TypeNamed)#49 (2) { + ["name"]=> + string(7) "Boolean" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(1) + ["column"]=> + int(42) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(1) + ["column"]=> + int(42) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#18 (2) { + ["line"]=> + int(1) + ["column"]=> + int(41) + } + } + ["defaultValue"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(1) + ["column"]=> + int(30) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#56 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#55 (6) { + ["name"]=> + string(11) "booleanList" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#54 (3) { + ["name"]=> + string(14) "booleanListArg" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueVariable)#53 (2) { + ["name"]=> + string(8) "booleans" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#38 (2) { + ["line"]=> + int(2) + ["column"]=> + int(32) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#34 (2) { + ["line"]=> + int(2) + ["column"]=> + int(16) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#30 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#28 (2) { + ["line"]=> + int(1) + ["column"]=> + int(53) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_nested_fields b/tests/parsing/test_it_parses_nested_fields new file mode 100644 index 0000000..55fdd02 --- /dev/null +++ b/tests/parsing/test_it_parses_nested_fields @@ -0,0 +1,289 @@ +{ + me { + id + firstName + lastName + birthday { + month + day + } + friends { + name + } + } +} +---- +object(HansOtt\GraphQL\Query\Document)#56 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#55 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#54 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#53 (6) { + ["name"]=> + string(2) "me" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#52 (2) { + ["selections"]=> + array(5) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#42 (6) { + ["name"]=> + string(2) "id" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(3) + ["column"]=> + int(6) + } + } + [1]=> + object(HansOtt\GraphQL\Query\SelectionField)#43 (6) { + ["name"]=> + string(9) "firstName" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#14 (2) { + ["line"]=> + int(4) + ["column"]=> + int(6) + } + } + [2]=> + object(HansOtt\GraphQL\Query\SelectionField)#44 (6) { + ["name"]=> + string(8) "lastName" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(5) + ["column"]=> + int(6) + } + } + [3]=> + object(HansOtt\GraphQL\Query\SelectionField)#48 (6) { + ["name"]=> + string(8) "birthday" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#47 (2) { + ["selections"]=> + array(2) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#45 (6) { + ["name"]=> + string(5) "month" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#22 (2) { + ["line"]=> + int(7) + ["column"]=> + int(8) + } + } + [1]=> + object(HansOtt\GraphQL\Query\SelectionField)#46 (6) { + ["name"]=> + string(3) "day" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#24 (2) { + ["line"]=> + int(8) + ["column"]=> + int(8) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(6) + ["column"]=> + int(15) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#18 (2) { + ["line"]=> + int(6) + ["column"]=> + int(6) + } + } + [4]=> + object(HansOtt\GraphQL\Query\SelectionField)#51 (6) { + ["name"]=> + string(7) "friends" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#50 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#49 (6) { + ["name"]=> + string(4) "name" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#32 (2) { + ["line"]=> + int(11) + ["column"]=> + int(8) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#30 (2) { + ["line"]=> + int(10) + ["column"]=> + int(14) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#28 (2) { + ["line"]=> + int(10) + ["column"]=> + int(6) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#10 (2) { + ["line"]=> + int(2) + ["column"]=> + int(7) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_strings_with_emoji b/tests/parsing/test_it_parses_strings_with_emoji new file mode 100644 index 0000000..ee79d85 --- /dev/null +++ b/tests/parsing/test_it_parses_strings_with_emoji @@ -0,0 +1,92 @@ +{ author(name: "\" \t \ud83d\ude00\n yo") } +---- +object(HansOtt\GraphQL\Query\Document)#29 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#28 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#27 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#26 (6) { + ["name"]=> + string(6) "author" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#25 (3) { + ["name"]=> + string(4) "name" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueString)#24 (2) { + ["value"]=> + string(12) "" 😀 + yo" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(1) + ["column"]=> + int(16) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(1) + ["column"]=> + int(10) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(1) + ["column"]=> + int(3) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_user_with_id_name b/tests/parsing/test_it_parses_user_with_id_name new file mode 100644 index 0000000..9392d01 --- /dev/null +++ b/tests/parsing/test_it_parses_user_with_id_name @@ -0,0 +1,128 @@ +{ + user(id: 4) { + name + } +} +---- +object(HansOtt\GraphQL\Query\Document)#37 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#36 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#35 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#34 (6) { + ["name"]=> + string(4) "user" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#31 (3) { + ["name"]=> + string(2) "id" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueInt)#30 (2) { + ["value"]=> + int(4) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(2) + ["column"]=> + int(12) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(2) + ["column"]=> + int(9) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#33 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#32 (6) { + ["name"]=> + string(4) "name" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#22 (2) { + ["line"]=> + int(3) + ["column"]=> + int(6) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(2) + ["column"]=> + int(16) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_variables b/tests/parsing/test_it_parses_variables new file mode 100644 index 0000000..dd909ea --- /dev/null +++ b/tests/parsing/test_it_parses_variables @@ -0,0 +1,234 @@ +query getZuckProfile($devicePicSize: Int) { + user(id: 4) { + id + name + profilePic(size: $devicePicSize) + } +} +---- +object(HansOtt\GraphQL\Query\Document)#76 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#75 (5) { + ["name"]=> + string(14) "getZuckProfile" + ["variables"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\VariableDefinition)#64 (4) { + ["variable"]=> + object(HansOtt\GraphQL\Query\ValueVariable)#62 (2) { + ["name"]=> + string(13) "devicePicSize" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(1) + ["column"]=> + int(22) + } + } + ["type"]=> + object(HansOtt\GraphQL\Query\TypeNamed)#63 (2) { + ["name"]=> + string(3) "Int" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#18 (2) { + ["line"]=> + int(1) + ["column"]=> + int(38) + } + } + ["defaultValue"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(1) + ["column"]=> + int(22) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#74 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#73 (6) { + ["name"]=> + string(4) "user" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#66 (3) { + ["name"]=> + string(2) "id" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueInt)#65 (2) { + ["value"]=> + int(4) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#32 (2) { + ["line"]=> + int(2) + ["column"]=> + int(12) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#28 (2) { + ["line"]=> + int(2) + ["column"]=> + int(9) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#72 (2) { + ["selections"]=> + array(3) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#67 (6) { + ["name"]=> + string(2) "id" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#38 (2) { + ["line"]=> + int(3) + ["column"]=> + int(6) + } + } + [1]=> + object(HansOtt\GraphQL\Query\SelectionField)#68 (6) { + ["name"]=> + string(4) "name" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#40 (2) { + ["line"]=> + int(4) + ["column"]=> + int(6) + } + } + [2]=> + object(HansOtt\GraphQL\Query\SelectionField)#71 (6) { + ["name"]=> + string(10) "profilePic" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#70 (3) { + ["name"]=> + string(4) "size" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueVariable)#69 (2) { + ["name"]=> + string(13) "devicePicSize" + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#50 (2) { + ["line"]=> + int(5) + ["column"]=> + int(23) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#46 (2) { + ["line"]=> + int(5) + ["column"]=> + int(17) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#42 (2) { + ["line"]=> + int(5) + ["column"]=> + int(6) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#36 (2) { + ["line"]=> + int(2) + ["column"]=> + int(16) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#24 (2) { + ["line"]=> + int(2) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#22 (2) { + ["line"]=> + int(1) + ["column"]=> + int(43) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(1) + ["column"]=> + int(1) + } +} diff --git a/tests/parsing/test_it_parses_with_comments b/tests/parsing/test_it_parses_with_comments new file mode 100644 index 0000000..d43ecc6 --- /dev/null +++ b/tests/parsing/test_it_parses_with_comments @@ -0,0 +1,130 @@ +# `user` represents one of many users in a graph of data, referred to by a +# unique identifier. +{ + user(id: 4) { + name + } +} +---- +object(HansOtt\GraphQL\Query\Document)#37 (2) { + ["definitions"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\OperationQuery)#36 (5) { + ["name"]=> + NULL + ["variables"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#35 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#34 (6) { + ["name"]=> + string(4) "user" + ["alias"]=> + NULL + ["arguments"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\Argument)#31 (3) { + ["name"]=> + string(2) "id" + ["value"]=> + object(HansOtt\GraphQL\Query\ValueInt)#30 (2) { + ["value"]=> + int(4) + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#16 (2) { + ["line"]=> + int(4) + ["column"]=> + int(12) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#12 (2) { + ["line"]=> + int(4) + ["column"]=> + int(9) + } + } + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + object(HansOtt\GraphQL\Query\SelectionSet)#33 (2) { + ["selections"]=> + array(1) { + [0]=> + object(HansOtt\GraphQL\Query\SelectionField)#32 (6) { + ["name"]=> + string(4) "name" + ["alias"]=> + NULL + ["arguments"]=> + array(0) { + } + ["directives"]=> + array(0) { + } + ["selectionSet"]=> + NULL + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#22 (2) { + ["line"]=> + int(5) + ["column"]=> + int(6) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#20 (2) { + ["line"]=> + int(4) + ["column"]=> + int(16) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#8 (2) { + ["line"]=> + int(4) + ["column"]=> + int(4) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(3) + ["column"]=> + int(2) + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(3) + ["column"]=> + int(2) + } + } + } + ["location"]=> + object(HansOtt\GraphQL\Query\Location)#6 (2) { + ["line"]=> + int(3) + ["column"]=> + int(2) + } +}