1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
from graphql.language import print_source_location, Source, SourceLocation
from ..utils import dedent
def describe_print_location():
def prints_minified_documents():
minified_source = Source(
"query SomeMinifiedQueryWithErrorInside("
"$foo:String!=FIRST_ERROR_HERE$bar:String)"
"{someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE)"
"{fieldA fieldB{fieldC fieldD...on THIRD_ERROR_HERE}}}"
)
first_location = print_source_location(
minified_source,
SourceLocation(1, minified_source.body.index("FIRST_ERROR_HERE") + 1),
)
assert first_location == dedent(
"""
GraphQL request:1:53
1 | query SomeMinifiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
| ^
| {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
""" # noqa: E501
)
second_location = print_source_location(
minified_source,
SourceLocation(1, minified_source.body.index("SECOND_ERROR_HERE") + 1),
)
assert second_location == dedent(
"""
GraphQL request:1:114
1 | query SomeMinifiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
| {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
| ^
| ..on THIRD_ERROR_HERE}}}
""" # noqa: E501
)
third_location = print_source_location(
minified_source,
SourceLocation(1, minified_source.body.index("THIRD_ERROR_HERE") + 1),
)
assert third_location == dedent(
"""
GraphQL request:1:166
1 | query SomeMinifiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
| {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
| ..on THIRD_ERROR_HERE}}}
| ^
""" # noqa: E501
)
def prints_single_digit_line_number_with_no_padding():
result = print_source_location(
Source("*", "Test", SourceLocation(9, 1)), SourceLocation(1, 1)
)
assert result == dedent(
"""
Test:9:1
9 | *
| ^
"""
)
def prints_line_numbers_with_correct_padding():
result = print_source_location(
Source("*\n", "Test", SourceLocation(9, 1)), SourceLocation(1, 1)
)
assert result == dedent(
"""
Test:9:1
9 | *
| ^
10 |
"""
)
|