2016-09-21 08:30:36 +03:00
Introspection Schema
====================
2019-05-16 00:27:35 +03:00
Relay Modern uses `Babel Relay Plugin <https://facebook.github.io/relay/docs/en/installation-and-setup> `__ which requires you to provide your GraphQL schema data.
2016-09-21 08:30:36 +03:00
2019-04-26 18:48:37 +03:00
Graphene comes with a Django management command to dump your schema
data to `` schema.json `` which is compatible with babel-relay-plugin.
2016-09-21 08:30:36 +03:00
Usage
-----
2019-03-31 13:30:29 +03:00
Include `` graphene_django `` to `` INSTALLED_APPS `` in your project
2016-09-21 08:30:36 +03:00
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.
2019-03-31 13:30:29 +03:00
The schema file is sorted to create a reproducible canonical representation.
2020-03-13 13:04:55 +03:00
GraphQL SDL Representation
--------------------------
The schema can also be exported as a GraphQL SDL file by changing the file
extension :
.. code :: bash
./manage.py graphql_schema --schema tutorial.quickstart.schema --out schema.graphql
When exporting the schema as a `` .graphql `` file the `` --indent `` option is
ignored.
2016-09-21 08:30:36 +03:00
Advanced Usage
--------------
2016-09-25 14:11:01 +03:00
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.
2019-06-10 03:06:50 +03:00
The `` --watch `` option can be used to run `` ./manage.py graphql_schema `` in watch mode, where it will automatically output a new schema every time there are file changes in your project
2016-09-21 08:30:36 +03:00
To simplify the command to `` ./manage.py graphql_schema `` , you can
specify the parameters in your settings.py:
.. code :: python
GRAPHENE = {
2023-07-18 15:16:52 +03:00
'SCHEMA': 'tutorial.quickstart.schema',
'SCHEMA_OUTPUT': 'data/schema.json', # defaults to schema.json,
'SCHEMA_INDENT': 2, # Defaults to None (displays all data on a single line)
2016-09-21 08:30:36 +03:00
}
Running `` ./manage.py graphql_schema `` dumps your schema to
`` <project root>/data/schema.json `` .
Help
----
Run `` ./manage.py graphql_schema -h `` for command usage.