| 1 |
from graphql.language import parse_value, print_ast |
| 2 |
from graphql.utilities.sort_value_node import sort_value_node |
| 3 |
|
| 4 |
|
| 5 |
def describe_sort_value_node(): |
| 6 |
def _expect_sorted_value(source: str, expected: str) -> None: |
| 7 |
assert print_ast(sort_value_node(parse_value(source))) == expected |
| 8 |
|
| 9 |
def do_not_change_non_object_values(): |
| 10 |
_expect_sorted_value("1", "1") |
| 11 |
_expect_sorted_value("3.14", "3.14") |
| 12 |
_expect_sorted_value("null", "null") |
| 13 |
_expect_sorted_value("true", "true") |
| 14 |
_expect_sorted_value("false", "false") |
| 15 |
_expect_sorted_value('"cba"', '"cba"') |
| 16 |
_expect_sorted_value( |
| 17 |
'[1, 3.14, null, false, "cba"]', '[1, 3.14, null, false, "cba"]' |
| 18 |
) |
| 19 |
_expect_sorted_value( |
| 20 |
'[[1, 3.14, null, false, "cba"]]', '[[1, 3.14, null, false, "cba"]]' |
| 21 |
) |
| 22 |
|
| 23 |
def sort_input_object_fields(): |
| 24 |
_expect_sorted_value("{ b: 2, a: 1 }", "{a: 1, b: 2}") |
| 25 |
_expect_sorted_value("{ a: { c: 3, b: 2 } }", "{a: {b: 2, c: 3}}") |
| 26 |
_expect_sorted_value( |
| 27 |
"[{ b: 2, a: 1 }, { d: 4, c: 3}]", |
| 28 |
"[{a: 1, b: 2}, {c: 3, d: 4}]", |
| 29 |
) |
| 30 |
_expect_sorted_value( |
| 31 |
"{ b: { g: 7, f: 6 }, c: 3 , a: { d: 4, e: 5 } }", |
| 32 |
"{a: {d: 4, e: 5}, b: {f: 6, g: 7}, c: 3}", |
| 33 |
) |