1
+ import asyncio
2
+
1
3
from graphql .type .definition import (
2
4
GraphQLArgument ,
3
5
GraphQLField ,
@@ -12,6 +14,7 @@ def resolve_raises(*_):
12
14
raise Exception ("Throws!" )
13
15
14
16
17
+ # Sync schema
15
18
QueryRootType = GraphQLObjectType (
16
19
name = "QueryRoot" ,
17
20
fields = {
@@ -36,7 +39,7 @@ def resolve_raises(*_):
36
39
"test" : GraphQLField (
37
40
type_ = GraphQLString ,
38
41
args = {"who" : GraphQLArgument (GraphQLString )},
39
- resolve = lambda obj , info , who = "World" : "Hello %s" % who ,
42
+ resolve = lambda obj , info , who = "World" : f "Hello { who } " ,
40
43
),
41
44
},
42
45
)
@@ -49,3 +52,48 @@ def resolve_raises(*_):
49
52
)
50
53
51
54
Schema = GraphQLSchema (QueryRootType , MutationRootType )
55
+
56
+
57
+ # Schema with async methods
58
+ async def resolver_field_async_1 (_obj , info ):
59
+ await asyncio .sleep (0.001 )
60
+ return "hey"
61
+
62
+
63
+ async def resolver_field_async_2 (_obj , info ):
64
+ await asyncio .sleep (0.003 )
65
+ return "hey2"
66
+
67
+
68
+ def resolver_field_sync (_obj , info ):
69
+ return "hey3"
70
+
71
+
72
+ AsyncQueryType = GraphQLObjectType (
73
+ name = "AsyncQueryType" ,
74
+ fields = {
75
+ "a" : GraphQLField (GraphQLString , resolve = resolver_field_async_1 ),
76
+ "b" : GraphQLField (GraphQLString , resolve = resolver_field_async_2 ),
77
+ "c" : GraphQLField (GraphQLString , resolve = resolver_field_sync ),
78
+ },
79
+ )
80
+
81
+
82
+ def resolver_field_sync_1 (_obj , info ):
83
+ return "synced_one"
84
+
85
+
86
+ def resolver_field_sync_2 (_obj , info ):
87
+ return "synced_two"
88
+
89
+
90
+ SyncQueryType = GraphQLObjectType (
91
+ "SyncQueryType" ,
92
+ {
93
+ "a" : GraphQLField (GraphQLString , resolve = resolver_field_sync_1 ),
94
+ "b" : GraphQLField (GraphQLString , resolve = resolver_field_sync_2 ),
95
+ },
96
+ )
97
+
98
+ AsyncSchema = GraphQLSchema (AsyncQueryType )
99
+ SyncSchema = GraphQLSchema (SyncQueryType )
0 commit comments