Skip to content

async resolvers in graphene breaks using nested structures #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
raix opened this issue Jan 17, 2017 · 0 comments · Fixed by #102
Closed

async resolvers in graphene breaks using nested structures #101

raix opened this issue Jan 17, 2017 · 0 comments · Fixed by #102

Comments

@raix
Copy link
Contributor

raix commented Jan 17, 2017

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant