diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php index d3dad3cc..708d5335 100644 --- a/src/Parser/Parser.php +++ b/src/Parser/Parser.php @@ -114,7 +114,10 @@ protected function parseOperation($type = Token::TYPE_QUERY) $this->eatMulti([Token::TYPE_COMMA]); $operation = $this->parseBodyItem($type, true); - $operation->setDirectives($directives); + $operation->setDirectives(array_merge( + $directives, + $operation->getDirectives() + )); $fields[] = $operation; } diff --git a/tests/Issues/Issue242/Issue242Test.php b/tests/Issues/Issue242/Issue242Test.php new file mode 100644 index 00000000..f53fb095 --- /dev/null +++ b/tests/Issues/Issue242/Issue242Test.php @@ -0,0 +1,58 @@ +parse($payload); + $this->assertEquals([ + 'queries' => [ + new Query( + 'user', + null, + [], + [ + new Field('name', null, [], [], new Location(1, 35)), + ], + [ + new Directive( + 'include', + [ + new Argument('if', new Literal(false, new Location(1, 26)), new Location(1, 23)), + ], + new Location(1, 15) + ), + ], + new Location(1, 9) + ) + ], + 'mutations' => [], + 'fragments' => [], + 'fragmentReferences' => [], + 'variables' => [], + 'variableReferences' => [], + ], $data); + } +}