Skip to content

async resolvers in graphene breaks using nested structures #101

Closed
@raix

Description

@raix

Using python 3.6, linux+mac

I'm trying to fetch data via http but the nested call hangs - this can be replicated by using asyncio.sleep

Replication: comment out asyncio.sleep in fakeFetch to see the difference

from flask import Flask
from flask_graphql import GraphQLView
from graphql.execution.executors.asyncio import AsyncioExecutor
import graphene
import asyncio
import sys

app = Flask(__name__)

def Log(message):
    print(f"LOG: {message}", file=sys.stderr)

async def fakeFetch():
    Log('Wait a sec...')
    await asyncio.sleep(1) # Comment this out and things work
    return 'Async World'

class Bars(graphene.ObjectType):
    bar = graphene.String()
    async def resolve_bar(self, args, context, info):
        await fakeFetch()
        return 'Bar'

class Foo(graphene.ObjectType):
    bars = graphene.Field(Bars)
    async def resolve_bars(self, args, context, info):
        await fakeFetch()
        return Bars()

class Query(graphene.ObjectType):
    foo = graphene.Field(Foo)

    def resolve_foo(self, args, context, info):
        return Foo()

schema = graphene.Schema(query=Query)

app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True, executor=AsyncioExecutor() ))

if __name__ == "__main__":
    app.run()

Query:

{
  foo {
    bars {
      bar
    }
  }
}

requirements.txt

async-timeout==1.1.0
chardet==2.3.0
click==6.7
Flask==0.12
Flask-GraphQL==1.4.0
graphene==1.1.3
graphql-core==1.0.1
graphql-relay==0.4.5
itsdangerous==0.24
Jinja2==2.9.4
MarkupSafe==0.23
multidict==2.1.4
promise==1.0.1
six==1.10.0
typing==3.5.3.0
Werkzeug==0.11.15
yarl==0.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions