Async/Await keywords with AyncioExecutor
AlecAivazis opened this issue · comments
Alec Aivazis commented
I'm running into a bug using the async
/await
keywords and the AsyncioExecutor. Here is my test:
from graphql.execution.executors.asyncio import AsyncioExecutor
import graphene
class Query(graphene.ObjectType):
recipes = graphene.String()
async def resolve_recipes(self, *_):
return 'hello'
schema = graphene.Schema(
query=Query,
executor=AsyncioExecutor()
)
executed = schema.execute("""
query {
recipes
}
""")
print(executed.data)
print(executed.errors)
which results in the following messages logged in my terminal:
/Users/alec/bin/python/graphql/execution/executor.py:110: RuntimeWarning: coroutine 'Query.resolve_recipes' was never awaited
result = resolve_field(exe_context, parent_type, source_value, field_asts)
OrderedDict([('recipes', '<coroutine object Query.resolve_recipes at 0x10eb0f360>')])
[]
Beau commented
Must be fixed now, I'm getting the expected result. (from your code I've only moved the executor down to the execute()
call, which is a recent change to graphql-core)
from graphql.execution.executors.asyncio import AsyncioExecutor
import graphene
class Query(graphene.ObjectType):
recipes = graphene.String()
async def resolve_recipes(self, *_):
return 'hello'
schema = graphene.Schema(
query=Query
)
executed = schema.execute("""
query {
recipes
}
""", executor=AsyncioExecutor())
print(executed.data)
print(executed.errors)
Results in
OrderedDict([('recipes', 'hello')])
[]
Alec Aivazis commented
Yep, just tested and its fixed. Thanks @bcb for letting me know and thanks @syrusakbary for all the hard work!