Debian Codegraph @

tests/validation/test_unique_variable_names.py

raw
1 from functools import partial
2
3 from graphql.validation import UniqueVariableNamesRule
4
5 from .harness import assert_validation_errors
6
7 assert_errors = partial(assert_validation_errors, UniqueVariableNamesRule)
8
9 assert_valid = partial(assert_errors, errors=[])
10
11
12 def describe_validate_unique_variable_names():
13 def unique_variable_names():
14 assert_valid("""
15 query A($x: Int, $y: String) { __typename }
16 query B($x: String, $y: Int) { __typename }
17 """)
18
19 def duplicate_variable_names():
20 assert_errors(
21 """
22 query A($x: Int, $x: Int, $x: String) { __typename }
23 query B($x: String, $x: Int) { __typename }
24 query C($x: Int, $x: Int) { __typename }
25 """,
26 [
27 {
28 "message": "There can be only one variable named '$x'.",
29 "locations": [(2, 22), (2, 31), (2, 40)],
30 },
31 {
32 "message": "There can be only one variable named '$x'.",
33 "locations": [(3, 22), (3, 34)],
34 },
35 {
36 "message": "There can be only one variable named '$x'.",
37 "locations": [(4, 22), (4, 31)],
38 },
39 ],
40 )