Skip to content

async breaks using it in nested structures #403

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 · 1 comment
Closed

async breaks using it in nested structures #403

raix opened this issue Jan 17, 2017 · 1 comment

Comments

@raix
Copy link

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 - I'm guessing it might have to do with graphene? or core?
(or my lack of python experience - being a node dev I might have the wrong mindset)

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
@raix
Copy link
Author

raix commented Jan 17, 2017

opened new graphql-python/graphql-core#101 - fixing in graphql-core

@raix raix closed this as completed Jan 17, 2017
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

No branches or pull requests

1 participant