def create_app(path='/graphql', **kwargs):
app = Sanic(__name__)
app.debug = True
schema = kwargs.pop('schema', None) or Schema
async_executor = kwargs.pop('async_executor', False)
if async_executor:
@app.listener('before_server_start')
def init_async_executor(app, loop):
executor = AsyncioExecutor(loop)
app.add_route(GraphQLView.as_view(schema=schema, executor=executor, **kwargs), path)
@app.listener('before_server_stop')
def remove_graphql_endpoint(app, loop):
app.remove_route(path)
else:
app.add_route(GraphQLView.as_view(schema=schema, **kwargs), path)
app.client = SanicTestClient(app)
return app
评论列表
文章目录