2018-09-11 14:11:24 +03:00
Exporting the Hasura GraphQL schema
===================================
2018-12-03 15:12:24 +03:00
.. contents :: Table of contents
:backlinks: none
:depth: 1
:local:
2018-10-19 20:00:31 +03:00
If you need to share, introspect or export the GraphQL schema, you can use community tooling such as
2019-04-22 10:57:02 +03:00
`graphqurl <https://github.com/hasura/graphqurl> `__ , `Apollo CLI <https://github.com/apollographql/apollo-tooling> `__ ,
2019-01-24 17:16:34 +03:00
`get-graphql-schema <https://github.com/prismagraphql/get-graphql-schema> `__ , etc.
2018-09-11 14:11:24 +03:00
2019-01-04 20:25:48 +03:00
Using **graphqurl**
-------------------
2018-12-03 15:12:24 +03:00
2018-09-11 14:11:24 +03:00
For example, using `` graphqurl `` , you can get the schema as follows:
Run `` npm install -g graphqurl `` to install `` graphqurl `` . Then you can run the following commands to download the
2018-10-10 09:32:03 +03:00
GraphQL schema:
2018-09-11 14:11:24 +03:00
.. code-block :: bash
2019-05-10 09:05:11 +03:00
# If the GraphQL engine is running at https://my-graphql-engine.com/v1/graphql,
2019-04-22 10:57:02 +03:00
# without an admin secret
2019-05-10 09:05:11 +03:00
gq https://my-graphql-engine.com/v1/graphql --introspect > schema.graphql
2018-09-11 14:11:24 +03:00
2019-02-14 12:37:47 +03:00
# If Hasura GraphQL Engine is running with an admin secret
2019-05-10 09:05:11 +03:00
gq https://my-graphql-engine.com/v1/graphql -H 'X-Hasura-Admin-Secret: adminsecretkey' --introspect > schema.graphql
2018-09-11 14:11:24 +03:00
By default, it downloads the schema in `` .graphql `` format. If you want it in JSON format, you can use an additional
2018-10-10 09:32:03 +03:00
flag `` --format json `` :
2018-09-11 14:11:24 +03:00
.. code-block :: bash
# Getting the schema in .json format
2019-05-10 09:05:11 +03:00
gq https://my-graphql-engine.com/v1/graphql --introspect --format json > schema.json
2019-04-22 10:57:02 +03:00
Using **Apollo CLI**
--------------------
Using Apollo CLI, you can get the schema as follows:
Run `` npm install -g apollo `` to install the Apollo CLI. You can then run the following command to download the GraphQL schema:
.. code-block :: bash
2019-05-10 09:05:11 +03:00
# If the GraphQL engine is running at https://my-graphql-engine.com/v1/graphql,
2019-04-22 10:57:02 +03:00
# without an admin secret
2019-05-10 09:05:11 +03:00
apollo schema:download --endpoint https://my-graphql-engine.com/v1/graphql
2019-04-22 10:57:02 +03:00
# If Hasura GraphQL Engine is running with an admin secret
2019-05-10 09:05:11 +03:00
apollo schema:download --endpoint https://my-graphql-engine.com/v1/graphql --header 'X-Hasura-Admin-Secret: adminsecretkey'
2019-04-22 10:57:02 +03:00
Note that `` apollo schema:download `` is an alias of the command `apollo service:download <https://github.com/apollographql/apollo-tooling#apollo-servicedownload-output> `__ .
By default, this downloads the schema to a file called `` schema.json `` . This command has no other output types.