File: test_executable_definitions.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 (96 lines) | stat: -rw-r--r-- 2,234 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
from functools import partial

from graphql.validation import ExecutableDefinitionsRule

from .harness import assert_validation_errors

assert_errors = partial(assert_validation_errors, ExecutableDefinitionsRule)

assert_valid = partial(assert_errors, errors=[])


def describe_validate_executable_definitions():
    def with_only_operation():
        assert_valid(
            """
            query Foo {
              dog {
                name
              }
            }
            """
        )

    def with_operation_and_fragment():
        assert_valid(
            """
            query Foo {
              dog {
                name
                ...Frag
              }
            }

            fragment Frag on Dog {
              name
            }
            """
        )

    def with_type_definition():
        assert_errors(
            """
            query Foo {
              dog {
                name
              }
            }

            type Cow {
              name: String
            }

            extend type Dog {
              color: String
            }
            """,
            [
                {
                    "message": "The 'Cow' definition is not executable.",
                    "locations": [(8, 13)],
                },
                {
                    "message": "The 'Dog' definition is not executable.",
                    "locations": [(12, 13)],
                },
            ],
        )

    def with_schema_definition():
        assert_errors(
            """
            schema {
              query: Query
            }

            type Query {
              test: String
            }

            extend schema @directive
            """,
            [
                {
                    "message": "The schema definition is not executable.",
                    "locations": [(2, 13)],
                },
                {
                    "message": "The 'Query' definition is not executable.",
                    "locations": [(6, 13)],
                },
                {
                    "message": "The schema definition is not executable.",
                    "locations": [(10, 13)],
                },
            ],
        )