Skip to content

Commit 428f3d8

Browse files
committed
Allow comments on the last line of the query (fixes #39)
1 parent 52818aa commit 428f3d8

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ a query language for APIs created by Facebook.
1313
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
1414

1515
The current version 1.1.0b0 of GraphQL-core-next is up-to-date with GraphQL.js version
16-
14.4.0. All parts of the API are covered by an extensive test suite of currently 1881
16+
14.4.0. All parts of the API are covered by an extensive test suite of currently 1882
1717
unit tests.
1818

1919

graphql/language/lexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def read_comment(self, start: int, line: int, col: int, prev: Token) -> Token:
169169
position = start
170170
while True:
171171
position += 1
172-
if position > body_length:
172+
if position >= body_length:
173173
break
174174
char = body[position]
175175
if char < " " and char != "\t":

tests/language/test_parser.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,25 @@ def contains_references_to_start_and_end_tokens():
389389
assert isinstance(end_token, Token)
390390
assert end_token.kind == TokenKind.EOF
391391

392+
def allows_comments_everywhere_in_the_source():
393+
# make sure first and last line can be comment
394+
result = parse(
395+
"""# top comment
396+
{
397+
field # field comment
398+
}
399+
# bottom comment"""
400+
)
401+
top_comment = result.loc.start_token.next
402+
assert top_comment.kind is TokenKind.COMMENT
403+
assert top_comment.value == " top comment"
404+
field_comment = top_comment.next.next.next
405+
assert field_comment.kind is TokenKind.COMMENT
406+
assert field_comment.value == " field comment"
407+
bottom_comment = field_comment.next.next
408+
assert bottom_comment.kind is TokenKind.COMMENT
409+
assert bottom_comment.value == " bottom comment"
410+
392411

393412
def describe_parse_value():
394413
def parses_null_value():

0 commit comments

Comments
 (0)