sanic-graphql icon indicating copy to clipboard operation
sanic-graphql copied to clipboard

Minimal async fails

Open jack-burridge-tp opened this issue 5 years ago • 5 comments

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

jack-burridge-tp avatar Jan 07 '20 09:01 jack-burridge-tp

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

messa avatar Jan 07 '20 09:01 messa

I was using 1.1.3, and yeah 1.1.1 worked thanks

jack-burridge-tp avatar Jan 07 '20 09:01 jack-burridge-tp

Looks like the same thing as this:

  • https://github.com/graphql-python/aiohttp-graphql/issues/14
  • https://github.com/graphql-python/graphql-server-core/issues/32

messa avatar Jan 07 '20 09:01 messa

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 avatar Aug 29 '20 03:08 weiztech

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

weiztech avatar Aug 29 '20 04:08 weiztech