/
test_build_graphql_schema_from_sdl.py
177 lines (163 loc) · 5.82 KB
/
test_build_graphql_schema_from_sdl.py
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from collections import OrderedDict
from unittest.mock import Mock
import pytest
@pytest.mark.asyncio
async def test_build_schema(monkeypatch, clean_registry):
from tartiflette.resolver.factoryyy import ResolverExecutorFactory
from tartiflette.engine import _import_builtins
resolver_excutor = Mock()
monkeypatch.setattr(
ResolverExecutorFactory,
"get_resolver_executor",
Mock(return_value=resolver_excutor),
)
from tartiflette.schema.bakery import SchemaBakery
from tartiflette.types.argument import GraphQLArgument
from tartiflette.types.field import GraphQLField
from tartiflette.types.input_object import GraphQLInputObjectType
from tartiflette.types.interface import GraphQLInterfaceType
from tartiflette.types.list import GraphQLList
from tartiflette.types.non_null import GraphQLNonNull
from tartiflette.types.object import GraphQLObjectType
from tartiflette.types.union import GraphQLUnionType
schema_sdl = """
schema @enable_cache {
query: RootQuery
mutation: RootMutation
subscription: RootSubscription
}
union Group = Foo | Bar | Baz
interface Something {
oneField: [Int]
anotherField: [String]
aLastOne: [[Date!]]!
}
input UserInfo {
name: String
dateOfBirth: [Date]
graphQLFan: Boolean!
}
# directive @partner(goo: Anything) on ENUM_VALUE
\"\"\"
This is a docstring for the Test Object Type.
\"\"\"
type Test implements Unknown & Empty{
\"\"\"
This is a field description :D
\"\"\"
field(input: InputObject): String!
anotherField: [Int]
fieldWithDefaultValueArg(test: String = "default"): ID
simpleField: Date
}
"""
_, schema_sdl = await _import_builtins([], schema_sdl, "G")
_, schema_E = await _import_builtins([], "", "E")
clean_registry.register_sdl("G", schema_sdl)
clean_registry.register_sdl("E", schema_E)
generated_schema = SchemaBakery._preheat("G")
expected_schema = SchemaBakery._preheat("E")
expected_schema.query_type = "RootQuery"
expected_schema.mutation_type = "RootMutation"
expected_schema.subscription_type = "RootSubscription"
expected_schema.add_definition(
GraphQLUnionType(name="Group", gql_types=["Foo", "Bar", "Baz"])
)
expected_schema.add_definition(
GraphQLInterfaceType(
name="Something",
fields=OrderedDict(
oneField=GraphQLField(
name="oneField", gql_type=GraphQLList(gql_type="Int")
),
anotherField=GraphQLField(
name="anotherField",
gql_type=GraphQLList(gql_type="String"),
),
aLastOne=GraphQLField(
name="aLastOne",
gql_type=GraphQLNonNull(
gql_type=GraphQLList(
gql_type=GraphQLList(
gql_type=GraphQLNonNull(gql_type="Date")
)
)
),
),
),
)
)
expected_schema.add_definition(
GraphQLInputObjectType(
name="UserInfo",
fields=OrderedDict(
[
("name", GraphQLArgument(name="name", gql_type="String")),
(
"dateOfBirth",
GraphQLArgument(
name="dateOfBirth",
gql_type=GraphQLList(gql_type="Date"),
),
),
(
"graphQLFan",
GraphQLArgument(
name="graphQLFan",
gql_type=GraphQLNonNull(gql_type="Boolean"),
),
),
]
),
)
)
expected_schema.add_definition(
GraphQLObjectType(
name="Test",
fields=OrderedDict(
[
(
"field",
GraphQLField(
name="field",
gql_type=GraphQLNonNull(gql_type="String"),
arguments=OrderedDict(
input=GraphQLArgument(
name="input", gql_type="InputObject"
)
),
),
),
(
"anotherField",
GraphQLField(
name="anotherField",
gql_type=GraphQLList(gql_type="Int"),
),
),
(
"fieldWithDefaultValueArg",
GraphQLField(
name="fieldWithDefaultValueArg",
gql_type="ID",
arguments=OrderedDict(
test=GraphQLArgument(
name="test",
gql_type="String",
default_value="default",
)
),
),
),
(
"simpleField",
GraphQLField(name="simpleField", gql_type="Date"),
),
]
),
interfaces=["Unknown", "Empty"],
)
)
assert 5 < len(generated_schema._gql_types)
assert len(expected_schema._gql_types) == len(generated_schema._gql_types)
monkeypatch.undo()