sanic-graphql
sanic-graphql copied to clipboard
Minimal async fails
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
What version of graphql-server-core are you using? Can you try 1.1.1 exactly?
I was using 1.1.3, and yeah 1.1.1 worked thanks
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
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
its working now, using decorator @app.listener('before_server_start')