Closed
Description
- GraphQL AioWS version: 0.2.0 (Note graphql_ws.__version__ still shows 0.1.0)
- Python version: 3.6
- Operating System: Windows
Description
Accessing a field with an async resolver in an object type that resolves with an async resolver doesn't seem to work.
What I Did
Consider the following modification to https://github.com/graphql-python/graphql-ws/blob/master/examples/aiohttp/schema.py
import asyncio
import graphene
class Query(graphene.ObjectType):
base = graphene.String()
class NewType(graphene.ObjectType):
new_field = graphene.String()
async def resolve_new_field(self, info):
await asyncio.sleep(1.)
return 'hello'
class Subscription(graphene.ObjectType):
new_type = graphene.Field(NewType)
async def resolve_new_type(root, info):
while True:
yield NewType()
await asyncio.sleep(1.)
schema = graphene.Schema(query=Query, subscription=Subscription)
Results in
TypeError: Object of type 'Promise' is not JSON serializable
--
Traceback (most recent call last):
File "src/cars/sub/app.py", line 43, in <module>
web.run_app(app, port=8000)
File "C:\programs\anaconda3\envs\cars\lib\site-packages\aiohttp\web.py", line
121, in run_app
loop.run_until_complete(runner.cleanup())
...
Changing resolve_new_field
to
def resolve_new_field(self, info):
return 'hello'
works as expected, but I should think having an async resolver here should be fine as well.
Metadata
Metadata
Assignees
Labels
No labels