Debian Codegraph @

tests/validation/test_unique_input_field_names.py

raw
1 from functools import partial
2
3 from graphql.validation import UniqueInputFieldNamesRule
4
5 from .harness import assert_validation_errors
6
7 assert_errors = partial(assert_validation_errors, UniqueInputFieldNamesRule)
8
9 assert_valid = partial(assert_errors, errors=[])
10
11
12 def describe_validate_unique_input_field_names():
13 def input_object_with_fields():
14 assert_valid("""
15 {
16 field(arg: { f: true })
17 }
18 """)
19
20 def same_input_object_within_two_args():
21 assert_valid("""
22 {
23 field(arg1: { f: true }, arg2: { f: true })
24 }
25 """)
26
27 def multiple_input_object_fields():
28 assert_valid("""
29 {
30 field(arg: { f1: "value", f2: "value", f3: "value" })
31 }
32 """)
33
34 def allows_for_nested_input_objects_with_similar_fields():
35 assert_valid("""
36 {
37 field(arg: {
38 deep: {
39 deep: {
40 id: 1
41 }
42 id: 1
43 }
44 id: 1
45 })
46 }
47 """)
48
49 def duplicate_input_object_fields():
50 assert_errors(
51 """
52 {
53 field(arg: { f1: "value", f1: "value" })
54 }
55 """,
56 [
57 {
58 "message": "There can be only one input field named 'f1'.",
59 "locations": [(3, 28), (3, 41)],
60 },
61 ],
62 )
63
64 def many_duplicate_input_object_fields():
65 assert_errors(
66 """
67 {
68 field(arg: { f1: "value", f1: "value", f1: "value" })
69 }
70 """,
71 [
72 {
73 "message": "There can be only one input field named 'f1'.",
74 "locations": [(3, 28), (3, 41)],
75 },
76 {
77 "message": "There can be only one input field named 'f1'.",
78 "locations": [(3, 28), (3, 54)],
79 },
80 ],
81 )
82
83 def nested_duplicate_input_object_fields():
84 assert_errors(
85 """
86 {
87 field(arg: { f1: {f2: "value", f2: "value" }})
88 }
89 """,
90 [
91 {
92 "message": "There can be only one input field named 'f2'.",
93 "locations": [(3, 33), (3, 46)],
94 },
95 ],
96 )