app.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:sanic-graphql 作者: graphql-python 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号