mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-26 03:24:07 +03:00
fcc3de2a90
When we use the `graphql_schema` management command, the output can vary from run to run depending on arbitrary factors (because there is no guarantee made about the order used to output JSON dictionary keys). This makes it difficult to compare two schema's at different points in time. We address this by including a new `canonical` flag to the command, which uses standard `json.dump` funcitonality to sort dictionary keys and force pretty-printed output.
58 lines
1.6 KiB
ReStructuredText
58 lines
1.6 KiB
ReStructuredText
Introspection Schema
|
|
====================
|
|
|
|
Relay uses `Babel Relay
|
|
Plugin <https://facebook.github.io/relay/docs/guides-babel-plugin.html>`__
|
|
that requires you to provide your GraphQL schema data.
|
|
|
|
Graphene comes with a management command for Django to dump your schema
|
|
data to ``schema.json`` that is compatible with babel-relay-plugin.
|
|
|
|
Usage
|
|
-----
|
|
|
|
Include ``graphene_django`` to ``INSTALLED_APPS`` in your project
|
|
settings:
|
|
|
|
.. code:: python
|
|
|
|
INSTALLED_APPS += ('graphene_django')
|
|
|
|
Assuming your Graphene schema is at ``tutorial.quickstart.schema``, run
|
|
the command:
|
|
|
|
.. code:: bash
|
|
|
|
./manage.py graphql_schema --schema tutorial.quickstart.schema --out schema.json
|
|
|
|
It dumps your full introspection schema to ``schema.json`` inside your
|
|
project root directory. Point ``babel-relay-plugin`` to this file and
|
|
you're ready to use Relay with Graphene GraphQL implementation.
|
|
|
|
The schema file is sorted to create a reproducible canonical representation.
|
|
|
|
Advanced Usage
|
|
--------------
|
|
|
|
The ``--indent`` option can be used to specify the number of indentation spaces to
|
|
be used in the output. Defaults to `None` which displays all data on a single line.
|
|
|
|
To simplify the command to ``./manage.py graphql_schema``, you can
|
|
specify the parameters in your settings.py:
|
|
|
|
.. code:: python
|
|
|
|
GRAPHENE = {
|
|
'SCHEMA': 'tutorial.quickstart.schema',
|
|
'SCHEMA_OUTPUT': 'data/schema.json' # defaults to schema.json
|
|
}
|
|
|
|
|
|
Running ``./manage.py graphql_schema`` dumps your schema to
|
|
``<project root>/data/schema.json``.
|
|
|
|
Help
|
|
----
|
|
|
|
Run ``./manage.py graphql_schema -h`` for command usage.
|