File: test_unique_fragment_names.py

package info (click to toggle)
graphql-core 3.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,384 kB
  • sloc: python: 45,812; makefile: 26; sh: 13
file content (117 lines) | stat: -rw-r--r-- 2,540 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from functools import partial

from graphql.validation import UniqueFragmentNamesRule

from .harness import assert_validation_errors

assert_errors = partial(assert_validation_errors, UniqueFragmentNamesRule)

assert_valid = partial(assert_errors, errors=[])


def describe_validate_unique_fragment_names():
    def no_fragments():
        assert_valid(
            """
            {
              field
            }
            """
        )

    def one_fragment():
        assert_valid(
            """
            {
              ...fragA
            }
            fragment fragA on Type {
              field
            }
            """
        )

    def many_fragments():
        assert_valid(
            """
            {
              ...fragA
              ...fragB
              ...fragC
            }
            fragment fragA on Type {
              fieldA
            }
            fragment fragB on Type {
              fieldB
            }
            fragment fragC on Type {
              fieldC
            }
            """
        )

    def inline_fragments_are_always_unique():
        assert_valid(
            """
            {
              ...on Type {
                fieldA
              }
              ...on Type {
                fieldB
              }
            }
            """
        )

    def fragment_and_operation_named_the_same():
        assert_valid(
            """
            query Foo {
              ...Foo
            }
            fragment Foo on Type {
              field
            }
            """
        )

    def fragments_named_the_same():
        assert_errors(
            """
            {
              ...fragA
            }
            fragment fragA on Type {
              fieldA
            }
            fragment fragA on Type {
              fieldB
            }
            """,
            [
                {
                    "message": "There can be only one fragment named 'fragA'.",
                    "locations": [(5, 22), (8, 22)],
                },
            ],
        )

    def fragments_named_the_same_without_being_referenced():
        assert_errors(
            """
            fragment fragA on Type {
              fieldA
            }
            fragment fragA on Type {
              fieldB
            }
            """,
            [
                {
                    "message": "There can be only one fragment named 'fragA'.",
                    "locations": [(2, 22), (5, 22)],
                },
            ],
        )