|
| 1 | +GraphQL-Flask |
| 2 | +============= |
| 3 | + |
| 4 | +|Build Status| |Coverage Status| |PyPI version| |
| 5 | + |
| 6 | +Adds GraphQL support to your Flask application. |
| 7 | + |
| 8 | +Usage |
| 9 | +----- |
| 10 | + |
| 11 | +Just create a ``GraphQL`` instance from ``graphql_flask`` |
| 12 | + |
| 13 | +.. code:: python |
| 14 | +
|
| 15 | + from graphql_flask import GraphQL |
| 16 | +
|
| 17 | + graphql_blueprint = GraphQL(app, schema=schema) |
| 18 | +
|
| 19 | +This will add ``/graphql`` and ``/graphiql`` endpoints to your app. |
| 20 | + |
| 21 | +Customization |
| 22 | +------------- |
| 23 | + |
| 24 | +This package provides the following Views: \* ``GraphQLView``: endpoint |
| 25 | +for expose the GraphQL schema \* ``GraphiQLView``: Graphical Interface |
| 26 | +for operate with GraphQL easily |
| 27 | + |
| 28 | +You can also add only the views you want to use: |
| 29 | + |
| 30 | +.. code:: python |
| 31 | +
|
| 32 | + from graphql_flask import GraphQLView, GraphiQLView |
| 33 | +
|
| 34 | + app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema)) |
| 35 | +
|
| 36 | +Supported options |
| 37 | +~~~~~~~~~~~~~~~~~ |
| 38 | + |
| 39 | +- ``schema``: The ``GraphQLSchema`` object that you want the view to |
| 40 | + execute when it gets a valid request. |
| 41 | +- ``pretty``: Whether or not you want the response to be pretty printed |
| 42 | + JSON. |
| 43 | +- ``executor``: The ``Executor`` that you want to use to execute |
| 44 | + queries. |
| 45 | +- ``root_value``: The ``root_value`` you want to provide to |
| 46 | + ``executor.execute``. |
| 47 | +- ``default_query``: The ``default_query`` you want to provide to |
| 48 | + GraphiQL interface. |
| 49 | + |
| 50 | +You can also subclass ``GraphQLView`` and overwrite |
| 51 | +``get_root_value(self, request)`` to have a dynamic root value per |
| 52 | +request. |
| 53 | + |
| 54 | +.. code:: python |
| 55 | +
|
| 56 | + class UserRootValue(GraphQLView): |
| 57 | + def get_root_value(self, request): |
| 58 | + return request.user |
| 59 | +
|
| 60 | +.. |Build Status| image:: https://travis-ci.org/graphql-python/graphql-flask.svg?branch=master |
| 61 | + :target: https://travis-ci.org/graphql-python/graphql-flask |
| 62 | +.. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphql-flask/badge.svg?branch=master&service=github |
| 63 | + :target: https://coveralls.io/github/graphql-python/graphql-flask?branch=master |
| 64 | +.. |PyPI version| image:: https://badge.fury.io/py/graphql-flask.svg |
| 65 | + :target: https://badge.fury.io/py/graphql-flask |
0 commit comments