Flask-GraphQL
v2.0.1Adds GraphQL support to your Flask application
6 KBMIT License Likely Unmaintained
$ uv add Flask-GraphQLFlask-GraphQL
Adds GraphQL support to your Flask application.
Usage
Just use the GraphQLView view from flask_graphql
from flask_graphql import GraphQLView
app.add_url_rule('/graphql', view_func=GraphQLView.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=GraphQLView.as_view('graphql', schema=schema, batch=True))
This will add /graphql and /graphiql endpoints to your app.
Supported options
-
schema: TheGraphQLSchemaobject that you want the view to
execute when it gets a valid request.
-
context: A value to pass as thecontextto thegraphql()
function.
-
root_value: Theroot_valueyou want to provide to
executor.execute.
-
pretty: Whether or not you want the response to be pretty printed
JSON.
-
executor: TheExecutorthat 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_)
You can also subclass GraphQLView and overwrite get_root_value(self, request) to have a dynamic root value per request.
class UserRootValue(GraphQLView):
def get_root_value(self, request):
return request.user
Details
- Version
- 2.0.1
- License
- MIT License
- Maintainer
- Syrus Akbary
Links
Maintainers
- Syrus Akbary · [email protected]