File: test_scalar_leafs.py

package info (click to toggle)
graphql-core 3.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,452 kB
  • sloc: python: 46,922; makefile: 26; sh: 13
file content (143 lines) | stat: -rw-r--r-- 4,160 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from functools import partial

from graphql.validation import ScalarLeafsRule

from .harness import assert_validation_errors

assert_errors = partial(assert_validation_errors, ScalarLeafsRule)

assert_valid = partial(assert_errors, errors=[])


def describe_validate_scalar_leafs():
    def valid_scalar_selection():
        assert_valid(
            """
            fragment scalarSelection on Dog {
              barks
            }
            """
        )

    def object_type_missing_selection():
        assert_errors(
            """
            query directQueryOnObjectWithoutSubFields {
              human
            }
            """,
            [
                {
                    "message": "Field 'human' of type 'Human'"
                    " must have a selection of subfields."
                    " Did you mean 'human { ... }'?",
                    "locations": [(3, 15)],
                },
            ],
        )

    def interface_type_missing_selection():
        assert_errors(
            """
            {
              human { pets }
            }
            """,
            [
                {
                    "message": "Field 'pets' of type '[Pet]'"
                    " must have a selection of subfields."
                    " Did you mean 'pets { ... }'?",
                    "locations": [(3, 23)],
                },
            ],
        )

    def valid_scalar_selection_with_args():
        assert_valid(
            """
            fragment scalarSelectionWithArgs on Dog {
              doesKnowCommand(dogCommand: SIT)
            }
            """
        )

    def scalar_selection_not_allowed_on_boolean():
        assert_errors(
            """
            fragment scalarSelectionsNotAllowedOnBoolean on Dog {
              barks { sinceWhen }
            }
            """,
            [
                {
                    "message": "Field 'barks' must not have a selection"
                    " since type 'Boolean' has no subfields.",
                    "locations": [(3, 21)],
                },
            ],
        )

    def scalar_selection_not_allowed_on_enum():
        assert_errors(
            """
            fragment scalarSelectionsNotAllowedOnEnum on Cat {
              furColor { inHexDec }
            }
            """,
            [
                {
                    "message": "Field 'furColor' must not have a selection"
                    " since type 'FurColor' has no subfields.",
                    "locations": [(3, 24)],
                },
            ],
        )

    def scalar_selection_not_allowed_with_args():
        assert_errors(
            """
            fragment scalarSelectionsNotAllowedWithArgs on Dog {
              doesKnowCommand(dogCommand: SIT) { sinceWhen }
            }
            """,
            [
                {
                    "message": "Field 'doesKnowCommand' must not have a selection"
                    " since type 'Boolean' has no subfields.",
                    "locations": [(3, 48)],
                },
            ],
        )

    def scalar_selection_not_allowed_with_directives():
        assert_errors(
            """
            fragment scalarSelectionsNotAllowedWithDirectives on Dog {
              name @include(if: true) { isAlsoHumanName }
            }
            """,
            [
                {
                    "message": "Field 'name' must not have a selection"
                    " since type 'String' has no subfields.",
                    "locations": [(3, 39)],
                },
            ],
        )

    def scalar_selection_not_allowed_with_directives_and_args():
        assert_errors(
            """
            fragment scalarSelectionsNotAllowedWithDirectivesAndArgs on Dog {
              doesKnowCommand(dogCommand: SIT) @include(if: true) { sinceWhen }
            }
            """,
            [
                {
                    "message": "Field 'doesKnowCommand' must not have a selection"
                    " since type 'Boolean' has no subfields.",
                    "locations": [(3, 67)],
                },
            ],
        )