将graphql支持添加到webob(pyramid/pylons/…)应用程序中
WebOb-GraphQL的Python项目详细描述
将GraphQL支持添加到WebOB(金字塔、挂架…)应用程序中。
安装
要安装webob graphql,只需在shell中运行此命令
pip install "webob-graphql>=1.0.dev"
用法
只需使用webob_graphql
中的serve_graphql_request函数金字塔
frompyramid.viewimportview_configfromwebob_graphqlimportserve_graphql_request@view_config(route_name='graphql',# The serve_graphql_request method will detect what's the best renderer# to use, so it will do the json render automatically.# In summary, don't use the renderer='json' here :))defgraphql_view(request):returnserve_graphql_request(request,schema)# Optional, for adding batch query support (used in Apollo-Client)returnserve_graphql_request(request,schema,batch_enabled=True)
支持的选项
- schema:要视图的GraphQLSchema对象 在收到有效请求时执行。
- context:作为context传递给^{tt7}的值。$ 功能。
- root_value:要提供给的root_value。 executor.execute。
- format_error:如果要使用自定义错误格式化程序。
- pretty:是否希望正确打印响应 json。
- executor:要用于执行的Executor。 询问。
- graphiql_enabled:如果True(默认),则可能存在 GraphiQL加载时 直接从浏览器(用于调试和 探索)。
- render_graphiql:用于呈现graphiql的自定义函数(这个 函数应该有参数result和params。
- batch_enabled:启用批处理支持(用于 Apollo-Client 或 ReactRelayNetworkLayer)