55from graphql .error import INVALID
66from graphql .type import (
77 GraphQLArgument ,
8- GraphQLBoolean ,
98 GraphQLField ,
109 GraphQLFieldResolver ,
1110 GraphQLInt ,
2221 GraphQLOutputType ,
2322 GraphQLInputField ,
2423 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- },
9124)
9225
9326ObjectType = GraphQLObjectType ("Object" , {})
@@ -105,47 +38,6 @@ def schema_with_field_type(type_: GraphQLOutputType) -> GraphQLSchema:
10538
10639
10740def 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-
14941 def defines_an_enum_type_with_deprecated_value ():
15042 EnumTypeWithDeprecatedValue = GraphQLEnumType (
15143 name = "EnumWithDeprecatedValue" ,
@@ -200,65 +92,10 @@ def defines_an_object_type_with_deprecated_field():
20092 assert deprecated_field .type is GraphQLString
20193 assert deprecated_field .args == {}
20294
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-
25995 def stringifies_simple_types ():
26096 assert str (GraphQLInt ) == "Int"
261- assert str (BlogArticle ) == "Article"
97+ assert str (ScalarType ) == "Scalar"
98+ assert str (ObjectType ) == "Object"
26299 assert str (InterfaceType ) == "Interface"
263100 assert str (UnionType ) == "Union"
264101 assert str (EnumType ) == "Enum"
0 commit comments