Debian Codegraph @

tests/validation/test_lone_anonymous_operation.py

raw
1 from functools import partial
2
3 from graphql.validation import LoneAnonymousOperationRule
4
5 from .harness import assert_validation_errors
6
7 assert_errors = partial(assert_validation_errors, LoneAnonymousOperationRule)
8
9 assert_valid = partial(assert_errors, errors=[])
10
11
12 def describe_validate_anonymous_operation_must_be_alone():
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 multiple_named_operation():
28 assert_valid("""
29 query Foo {
30 field
31 }
32
33 query Bar {
34 field
35 }
36 """)
37
38 def anon_operation_with_fragment():
39 assert_valid("""
40 {
41 ...Foo
42 }
43 fragment Foo on Type {
44 field
45 }
46 """)
47
48 def multiple_anon_operations():
49 assert_errors(
50 """
51 {
52 fieldA
53 }
54 {
55 fieldB
56 }
57 """,
58 [
59 {
60 "message": "This anonymous operation"
61 " must be the only defined operation.",
62 "locations": [(2, 13)],
63 },
64 {
65 "message": "This anonymous operation"
66 " must be the only defined operation.",
67 "locations": [(5, 13)],
68 },
69 ],
70 )
71
72 def anon_operation_with_a_mutation():
73 assert_errors(
74 """
75 {
76 fieldA
77 }
78 mutation Foo {
79 fieldB
80 }
81 """,
82 [
83 {
84 "message": "This anonymous operation"
85 " must be the only defined operation.",
86 "locations": [(2, 13)],
87 },
88 ],
89 )
90
91 def anon_operation_with_a_subscription():
92 assert_errors(
93 """
94 {
95 fieldA
96 }
97 subscription Foo {
98 fieldB
99 }
100 """,
101 [
102 {
103 "message": "This anonymous operation"
104 " must be the only defined operation.",
105 "locations": [(2, 13)],
106 },
107 ],
108 )