5
5
from graphql .error import INVALID
6
6
from graphql .type import (
7
7
GraphQLArgument ,
8
- GraphQLBoolean ,
9
8
GraphQLField ,
10
9
GraphQLFieldResolver ,
11
10
GraphQLInt ,
22
21
GraphQLOutputType ,
23
22
GraphQLInputField ,
24
23
GraphQLNonNull ,
25
- is_object_type ,
26
- )
27
-
28
-
29
- BlogImage = GraphQLObjectType (
30
- "Image" ,
31
- {
32
- "url" : GraphQLField (GraphQLString ),
33
- "width" : GraphQLField (GraphQLInt ),
34
- "height" : GraphQLField (GraphQLInt ),
35
- },
36
- )
37
-
38
-
39
- BlogAuthor = GraphQLObjectType (
40
- "Author" ,
41
- lambda : {
42
- "id" : GraphQLField (GraphQLString ),
43
- "name" : GraphQLField (GraphQLString ),
44
- "pic" : GraphQLField (
45
- BlogImage ,
46
- args = {
47
- "width" : GraphQLArgument (GraphQLInt ),
48
- "height" : GraphQLArgument (GraphQLInt ),
49
- },
50
- ),
51
- "recentArticle" : GraphQLField (BlogArticle ),
52
- },
53
- )
54
-
55
-
56
- BlogArticle = GraphQLObjectType (
57
- "Article" ,
58
- lambda : {
59
- "id" : GraphQLField (GraphQLString ),
60
- "isPublished" : GraphQLField (GraphQLBoolean ),
61
- "author" : GraphQLField (BlogAuthor ),
62
- "title" : GraphQLField (GraphQLString ),
63
- "body" : GraphQLField (GraphQLString ),
64
- },
65
- )
66
-
67
-
68
- BlogQuery = GraphQLObjectType (
69
- "Query" ,
70
- {
71
- "article" : GraphQLField (
72
- BlogArticle , args = {"id" : GraphQLArgument (GraphQLString )}
73
- ),
74
- "feed" : GraphQLField (GraphQLList (BlogArticle )),
75
- },
76
- )
77
-
78
-
79
- BlogMutation = GraphQLObjectType (
80
- "Mutation" , {"writeArticle" : GraphQLField (BlogArticle )}
81
- )
82
-
83
-
84
- BlogSubscription = GraphQLObjectType (
85
- "Subscription" ,
86
- {
87
- "articleSubscribe" : GraphQLField (
88
- args = {"id" : GraphQLArgument (GraphQLString )}, type_ = BlogArticle
89
- )
90
- },
91
24
)
92
25
93
26
ObjectType = GraphQLObjectType ("Object" , {})
@@ -105,47 +38,6 @@ def schema_with_field_type(type_: GraphQLOutputType) -> GraphQLSchema:
105
38
106
39
107
40
def describe_type_system_example ():
108
- def defines_a_query_only_schema ():
109
- BlogSchema = GraphQLSchema (BlogQuery )
110
-
111
- assert BlogSchema .query_type == BlogQuery
112
- assert is_object_type (BlogQuery )
113
-
114
- article_field = BlogQuery .fields ["article" ]
115
- assert article_field .type == BlogArticle
116
-
117
- assert is_object_type (BlogArticle )
118
- blog_article_fields = BlogArticle .fields
119
- title_field = blog_article_fields ["title" ]
120
- assert title_field .type == GraphQLString
121
- author_field = blog_article_fields ["author" ]
122
- assert author_field .type == BlogAuthor
123
-
124
- assert is_object_type (BlogAuthor )
125
- recent_article_field = BlogAuthor .fields ["recentArticle" ]
126
- assert recent_article_field .type == BlogArticle
127
-
128
- feed_field = BlogQuery .fields ["feed" ]
129
- assert feed_field .type .of_type == BlogArticle
130
-
131
- def defines_a_mutation_schema ():
132
- BlogSchema = GraphQLSchema (query = BlogQuery , mutation = BlogMutation )
133
-
134
- assert BlogSchema .mutation_type == BlogMutation
135
-
136
- assert is_object_type (BlogMutation )
137
- write_mutation = BlogMutation .fields ["writeArticle" ]
138
- assert write_mutation .type == BlogArticle
139
-
140
- def defines_a_subscription_schema ():
141
- BlogSchema = GraphQLSchema (query = BlogQuery , subscription = BlogSubscription )
142
-
143
- assert BlogSchema .subscription_type == BlogSubscription
144
-
145
- subscription = BlogSubscription .fields ["articleSubscribe" ]
146
- assert subscription .type == BlogArticle
147
- assert subscription .type .name == "Article"
148
-
149
41
def defines_an_enum_type_with_deprecated_value ():
150
42
EnumTypeWithDeprecatedValue = GraphQLEnumType (
151
43
name = "EnumWithDeprecatedValue" ,
@@ -200,65 +92,10 @@ def defines_an_object_type_with_deprecated_field():
200
92
assert deprecated_field .type is GraphQLString
201
93
assert deprecated_field .args == {}
202
94
203
- def includes_nested_input_objects_in_the_map ():
204
- NestedInputObject = GraphQLInputObjectType (
205
- "NestedInputObject" , {"value" : GraphQLInputField (GraphQLString )}
206
- )
207
- SomeInputObject = GraphQLInputObjectType (
208
- "SomeInputObject" , {"nested" : GraphQLInputField (NestedInputObject )}
209
- )
210
- SomeMutation = GraphQLObjectType (
211
- "SomeMutation" ,
212
- {
213
- "mutateSomething" : GraphQLField (
214
- BlogArticle , {"input" : GraphQLArgument (SomeInputObject )}
215
- )
216
- },
217
- )
218
- SomeSubscription = GraphQLObjectType (
219
- "SomeSubscription" ,
220
- {
221
- "subscribeToSomething" : GraphQLField (
222
- BlogArticle , {"input" : GraphQLArgument (SomeInputObject )}
223
- )
224
- },
225
- )
226
- schema = GraphQLSchema (
227
- query = BlogQuery , mutation = SomeMutation , subscription = SomeSubscription
228
- )
229
- assert schema .type_map ["NestedInputObject" ] is NestedInputObject
230
-
231
- def includes_interface_possible_types_in_the_type_map ():
232
- SomeInterface = GraphQLInterfaceType (
233
- "SomeInterface" , {"f" : GraphQLField (GraphQLInt )}
234
- )
235
- SomeSubtype = GraphQLObjectType (
236
- "SomeSubtype" , {"f" : GraphQLField (GraphQLInt )}, interfaces = [SomeInterface ]
237
- )
238
- schema = GraphQLSchema (
239
- query = GraphQLObjectType ("Query" , {"iface" : GraphQLField (SomeInterface )}),
240
- types = [SomeSubtype ],
241
- )
242
- assert schema .type_map ["SomeSubtype" ] is SomeSubtype
243
-
244
- def includes_interfaces_thunk_subtypes_in_the_type_map ():
245
- SomeInterface = GraphQLInterfaceType (
246
- "SomeInterface" , {"f" : GraphQLField (GraphQLInt )}
247
- )
248
- SomeSubtype = GraphQLObjectType (
249
- "SomeSubtype" ,
250
- {"f" : GraphQLField (GraphQLInt )},
251
- interfaces = lambda : [SomeInterface ],
252
- )
253
- schema = GraphQLSchema (
254
- query = GraphQLObjectType ("Query" , {"iface" : GraphQLField (SomeInterface )}),
255
- types = [SomeSubtype ],
256
- )
257
- assert schema .type_map ["SomeSubtype" ] is SomeSubtype
258
-
259
95
def stringifies_simple_types ():
260
96
assert str (GraphQLInt ) == "Int"
261
- assert str (BlogArticle ) == "Article"
97
+ assert str (ScalarType ) == "Scalar"
98
+ assert str (ObjectType ) == "Object"
262
99
assert str (InterfaceType ) == "Interface"
263
100
assert str (UnionType ) == "Union"
264
101
assert str (EnumType ) == "Enum"
0 commit comments