Adds GraphQL support to your Quart application.
Just use the AsyncGraphQLView
view from quart_graphql
from quart_graphql import AsyncGraphQLView
app.add_url_rule('/graphql', view_func=AsyncGraphQLView.as_view('graphql', schema=schema, graphiql=True))
# Optional, for adding batch query support (used in Apollo-Client)
app.add_url_rule('/graphql/batch', view_func=AsyncGraphQLView.as_view('graphql', schema=schema, batch=True))
This will add /graphql
and /graphiql
endpoints to your app.
schema
: TheGraphQLSchema
object that you want the view to execute when it gets a valid request.context
: A value to pass as thecontext
to thegraphql()
function.root_value
: Theroot_value
you want to provide toexecutor.execute
.pretty
: Whether or not you want the response to be pretty printed JSON.executor
: TheExecutor
that you want to use to execute queries.graphiql
: IfTrue
, may present GraphiQL when loaded directly from a browser (a useful tool for debugging and exploration).graphiql_template
: Inject a Jinja template string to customize GraphiQL.batch
: Set the GraphQL view as batch (for using in Apollo-Client or ReactRelayNetworkLayer)middleware
: A list of graphql middlewares.
You can also subclass AsyncGraphQLView
and overwrite get_root_value(self, request)
to have a dynamic root value
per request.
class UserRootValue(AsyncGraphQLView):
def get_root_value(self, request):
return request.user