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