Repository: webonyx/graphql-php (language: php)

Issue:
Lexer wrong location when multiline comments
When using the lexer with a schema that has a multiline comments the location is wrong.

Taken the following schema
```
"""
testing
"""
scalar something
```
It ends up saying that the name token `scalar` is on line 2.



Discussion / hints:
Can you provide a pull request with a failing test case? The issue might be with the lexer, but I think a test for this would fit better with https://github.com/webonyx/graphql-php/blob/e8098fae49e2a007f389aa838796c6c154138744/tests/Language/SchemaParserTest.php#L166.

Fix patch:
diff --git a/src/Language/Lexer.php b/src/Language/Lexer.php
index c21261375..cec753d85 100644
--- a/src/Language/Lexer.php
+++ b/src/Language/Lexer.php
@@ -598,7 +598,14 @@ private function readBlockString(int $line, int $col, Token $prev): Token
                 $value .= $chunk . '"""';
                 $chunk = '';
             } else {
+                // move cursor back to before the first quote
                 $this->moveStringCursor(-2, -2);
+
+                if ($code === 10) { // new line
+                    ++$this->line;
+                    $this->lineStart = $this->position;
+                }
+
                 $chunk .= $char;
             }
 


Test patch:
diff --git a/tests/Language/SchemaParserTest.php b/tests/Language/SchemaParserTest.php
index 34526195d..b92467df3 100644
--- a/tests/Language/SchemaParserTest.php
+++ b/tests/Language/SchemaParserTest.php
@@ -199,6 +199,17 @@ public function testParsesTypeWithDescriptionMultiLineString(): void
             'loc' => $loc(0, 85),
         ];
         self::assertEquals($expected, $doc->toArray());
+
+        // ensure the lexer does not treat multi line comments as one line
+        $tokenAfterMultiLineComment = $doc->loc->startToken->next->next ?? null;
+        self::assertNotNull($tokenAfterMultiLineComment);
+        self::assertSame('Even with comments between them', trim($tokenAfterMultiLineComment->value ?? ''));
+        self::assertSame(5, $tokenAfterMultiLineComment->line);
+
+        $typeToken = $tokenAfterMultiLineComment->next;
+        self::assertNotNull($typeToken);
+        self::assertSame('type', $typeToken->value);
+        self::assertSame(6, $typeToken->line);
     }
 
     /** @see it('Simple extension') */