Debian Codegraph @

tests/validation/test_unique_fragment_names.py

raw
1 from functools import partial
2
3 from graphql.validation import UniqueFragmentNamesRule
4
5 from .harness import assert_validation_errors
6
7 assert_errors = partial(assert_validation_errors, UniqueFragmentNamesRule)
8
9 assert_valid = partial(assert_errors, errors=[])
10
11
12 def describe_validate_unique_fragment_names():
13 def no_fragments():
14 assert_valid("""
15 {
16 field
17 }
18 """)
19
20 def one_fragment():
21 assert_valid("""
22 {
23 ...fragA
24 }
25 fragment fragA on Type {
26 field
27 }
28 """)
29
30 def many_fragments():
31 assert_valid("""
32 {
33 ...fragA
34 ...fragB
35 ...fragC
36 }
37 fragment fragA on Type {
38 fieldA
39 }
40 fragment fragB on Type {
41 fieldB
42 }
43 fragment fragC on Type {
44 fieldC
45 }
46 """)
47
48 def inline_fragments_are_always_unique():
49 assert_valid("""
50 {
51 ...on Type {
52 fieldA
53 }
54 ...on Type {
55 fieldB
56 }
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 fragments_named_the_same():
71 assert_errors(
72 """
73 {
74 ...fragA
75 }
76 fragment fragA on Type {
77 fieldA
78 }
79 fragment fragA on Type {
80 fieldB
81 }
82 """,
83 [
84 {
85 "message": "There can be only one fragment named 'fragA'.",
86 "locations": [(5, 22), (8, 22)],
87 },
88 ],
89 )
90
91 def fragments_named_the_same_without_being_referenced():
92 assert_errors(
93 """
94 fragment fragA on Type {
95 fieldA
96 }
97 fragment fragA on Type {
98 fieldB
99 }
100 """,
101 [
102 {
103 "message": "There can be only one fragment named 'fragA'.",
104 "locations": [(2, 22), (5, 22)],
105 },
106 ],
107 )