1+ import asyncio
2+
13from graphql .type .definition import (
24 GraphQLArgument ,
35 GraphQLField ,
@@ -12,6 +14,7 @@ def resolve_raises(*_):
1214 raise Exception ("Throws!" )
1315
1416
17+ # Sync schema
1518QueryRootType = GraphQLObjectType (
1619 name = "QueryRoot" ,
1720 fields = {
@@ -36,7 +39,7 @@ def resolve_raises(*_):
3639 "test" : GraphQLField (
3740 type_ = GraphQLString ,
3841 args = {"who" : GraphQLArgument (GraphQLString )},
39- resolve = lambda obj , info , who = "World" : "Hello %s" % who ,
42+ resolve = lambda obj , info , who = "World" : f "Hello { who } " ,
4043 ),
4144 },
4245)
@@ -49,3 +52,48 @@ def resolve_raises(*_):
4952)
5053
5154Schema = 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