Skip to content

Commit f8a6a8a

Browse files
committed
Fixed #98
1 parent 59dacf9 commit f8a6a8a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

graphql/error/syntax_error.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ def highlight_source_at_location(source, location):
2929
format = (u'{:>' + str(pad_len) + '}: {}\n').format
3030
if line >= 2:
3131
result += format(line - 1, lines[line - 2])
32-
result += format(line, lines[line - 1])
33-
result += ' ' * (1 + pad_len + location.column) + '^\n'
32+
if line <= len(lines):
33+
result += format(line, lines[line - 1])
34+
result += ' ' * (1 + pad_len + location.column) + '^\n'
3435
if line < len(lines):
3536
result += format(line + 1, lines[line])
3637
return result

graphql/language/tests/test_parser.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ def test_repr_loc():
1414
assert repr(loc) == '<Loc start=10 end=25 source=foo>'
1515

1616

17+
def test_empty_parse():
18+
with raises(GraphQLSyntaxError) as excinfo:
19+
parse("")
20+
assert (
21+
u'Syntax Error GraphQL (1:1) Unexpected EOF\n'
22+
u'\n'
23+
) == excinfo.value.message
24+
25+
1726
def test_parse_provides_useful_errors():
1827
with raises(GraphQLSyntaxError) as excinfo:
1928
parse("""{""")
@@ -32,15 +41,18 @@ def test_parse_provides_useful_errors():
3241
parse("""{ ...MissingOn }
3342
fragment MissingOn Type
3443
""")
35-
assert 'Syntax Error GraphQL (2:20) Expected "on", found Name "Type"' in str(excinfo.value)
44+
assert 'Syntax Error GraphQL (2:20) Expected "on", found Name "Type"' in str(
45+
excinfo.value)
3646

3747
with raises(GraphQLSyntaxError) as excinfo:
3848
parse('{ field: {} }')
39-
assert 'Syntax Error GraphQL (1:10) Expected Name, found {' in str(excinfo.value)
49+
assert 'Syntax Error GraphQL (1:10) Expected Name, found {' in str(
50+
excinfo.value)
4051

4152
with raises(GraphQLSyntaxError) as excinfo:
4253
parse('notanoperation Foo { field }')
43-
assert 'Syntax Error GraphQL (1:1) Unexpected Name "notanoperation"' in str(excinfo.value)
54+
assert 'Syntax Error GraphQL (1:1) Unexpected Name "notanoperation"' in str(
55+
excinfo.value)
4456

4557
with raises(GraphQLSyntaxError) as excinfo:
4658
parse('...')
@@ -50,7 +62,8 @@ def test_parse_provides_useful_errors():
5062
def test_parse_provides_useful_error_when_using_source():
5163
with raises(GraphQLSyntaxError) as excinfo:
5264
parse(Source('query', 'MyQuery.graphql'))
53-
assert 'Syntax Error MyQuery.graphql (1:6) Expected {, found EOF' in str(excinfo.value)
65+
assert 'Syntax Error MyQuery.graphql (1:6) Expected {, found EOF' in str(
66+
excinfo.value)
5467

5568

5669
def test_parses_variable_inline_values():

0 commit comments

Comments
 (0)