Debian Codegraph @

tests/validation/test_unique_operation_names.py

raw
1 from functools import partial
2
3 from graphql.validation import UniqueOperationNamesRule
4
5 from .harness import assert_validation_errors
6
7 assert_errors = partial(assert_validation_errors, UniqueOperationNamesRule)
8
9 assert_valid = partial(assert_errors, errors=[])
10
11
12 def describe_validate_unique_operation_names():
13 def no_operations():
14 assert_valid("""
15 fragment fragA on Type {
16 field
17 }
18 """)
19
20 def one_anon_operation():
21 assert_valid("""
22 {
23 field
24 }
25 """)
26
27 def one_named_operation():
28 assert_valid("""
29 query Foo {
30 field
31 }
32 """)
33
34 def multiple_operations():
35 assert_valid("""
36 query Foo {
37 field
38 }
39
40 query Bar {
41 field
42 }
43 """)
44
45 def multiple_operations_of_different_types():
46 assert_valid("""
47 query Foo {
48 field
49 }
50
51 mutation Bar {
52 field
53 }
54
55 subscription Baz {
56 field
57 }
58 """)
59
60 def fragment_and_operation_named_the_same():
61 assert_valid("""
62 query Foo {
63 ...Foo
64 }
65 fragment Foo on Type {
66 field
67 }
68 """)
69
70 def multiple_operations_of_same_name():
71 assert_errors(
72 """
73 query Foo {
74 fieldA
75 }
76 query Foo {
77 fieldB
78 }
79 """,
80 [
81 {
82 "message": "There can be only one operation named 'Foo'.",
83 "locations": [(2, 19), (5, 19)],
84 },
85 ],
86 )
87
88 def multiple_ops_of_same_name_of_different_types_mutation():
89 assert_errors(
90 """
91 query Foo {
92 fieldA
93 }
94 mutation Foo {
95 fieldB
96 }
97 """,
98 [
99 {
100 "message": "There can be only one operation named 'Foo'.",
101 "locations": [(2, 19), (5, 22)],
102 },
103 ],
104 )
105
106 def multiple_ops_of_same_name_of_different_types_subscription():
107 assert_errors(
108 """
109 query Foo {
110 fieldA
111 }
112 subscription Foo {
113 fieldB
114 }
115 """,
116 [
117 {
118 "message": "There can be only one operation named 'Foo'.",
119 "locations": [(2, 19), (5, 26)],
120 },
121 ],
122 )