Debian Codegraph @

tests/validation/test_executable_definitions.py

raw
1 from functools import partial
2
3 from graphql.validation import ExecutableDefinitionsRule
4
5 from .harness import assert_validation_errors
6
7 assert_errors = partial(assert_validation_errors, ExecutableDefinitionsRule)
8
9 assert_valid = partial(assert_errors, errors=[])
10
11
12 def describe_validate_executable_definitions():
13 def with_only_operation():
14 assert_valid("""
15 query Foo {
16 dog {
17 name
18 }
19 }
20 """)
21
22 def with_operation_and_fragment():
23 assert_valid("""
24 query Foo {
25 dog {
26 name
27 ...Frag
28 }
29 }
30
31 fragment Frag on Dog {
32 name
33 }
34 """)
35
36 def with_type_definition():
37 assert_errors(
38 """
39 query Foo {
40 dog {
41 name
42 }
43 }
44
45 type Cow {
46 name: String
47 }
48
49 extend type Dog {
50 color: String
51 }
52 """,
53 [
54 {
55 "message": "The 'Cow' definition is not executable.",
56 "locations": [(8, 13)],
57 },
58 {
59 "message": "The 'Dog' definition is not executable.",
60 "locations": [(12, 13)],
61 },
62 ],
63 )
64
65 def with_schema_definition():
66 assert_errors(
67 """
68 schema {
69 query: Query
70 }
71
72 type Query {
73 test: String
74 }
75
76 extend schema @directive
77 """,
78 [
79 {
80 "message": "The schema definition is not executable.",
81 "locations": [(2, 13)],
82 },
83 {
84 "message": "The 'Query' definition is not executable.",
85 "locations": [(6, 13)],
86 },
87 {
88 "message": "The schema definition is not executable.",
89 "locations": [(10, 13)],
90 },
91 ],
92 )