Skip to content
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

Minimal async fails #19

Open
jack-burridge-tp opened this issue Jan 7, 2020 · 5 comments
Open

Minimal async fails #19

jack-burridge-tp opened this issue Jan 7, 2020 · 5 comments

Comments

@jack-burridge-tp
Copy link

I have a minimal async example

from graphene import ObjectType, String, Schema
from graphql.execution.executors.asyncio import AsyncioExecutor
from sanic import Sanic
from sanic_graphql import GraphQLView


class Query(ObjectType):
    hello = String(name=String(default_value="stranger"))
    goodbye = String()

    async def resolve_hello(root, info, name):
        return f'Hello {name}!'

    def resolve_goodbye(root, info):
        return 'See ya!'


schema = Schema(query=Query)

app = Sanic(__name__)
app.debug = True


@app.listener('before_server_start')
def init_graphql(app, loop):
    app.add_route(GraphQLView.as_view(schema=schema, executor=AsyncioExecutor(loop=loop)), '/graphql')


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

I can do a synchronous resolve

{
  goodbye
}

But running

{
  hello
}

Fails and the server stops, I'm assuming something is blocking the event loop but I can't find where

@messa
Copy link

messa commented Jan 7, 2020

What version of graphql-server-core are you using? Can you try 1.1.1 exactly?

@jack-burridge-tp
Copy link
Author

I was using 1.1.3, and yeah 1.1.1 worked thanks

@messa
Copy link

messa commented Jan 7, 2020

@weiztech
Copy link

I have the same issue, without async working fine.

graphql-core
Version: 2.1

graphql-server-core
Version: 1.1.1

sanic
Version: 18.12.0

@weiztech
Copy link

its working now, using decorator @app.listener('before_server_start')

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

3 participants