1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
.. _gql_cli:
gql-cli
=======
GQL provides a python script, called `gql-cli` which allows you to execute
GraphQL queries directly from the terminal.
This script supports http(s) or websockets protocols.
Usage
-----
.. argparse::
:module: gql.cli
:func: get_parser
:prog: gql-cli
Examples
--------
Simple query using https
^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: shell
$ echo 'query { continent(code:"AF") { name } }' | gql-cli https://countries.trevorblades.com
{"continent": {"name": "Africa"}}
Simple query using websockets
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: shell
$ echo 'query { continent(code:"AF") { name } }' | gql-cli wss://countries.trevorblades.com/graphql
{"continent": {"name": "Africa"}}
Query with variable
^^^^^^^^^^^^^^^^^^^
.. code-block:: shell
$ echo 'query getContinent($code:ID!) { continent(code:$code) { name } }' | gql-cli https://countries.trevorblades.com --variables code:AF
{"continent": {"name": "Africa"}}
Interactive usage
^^^^^^^^^^^^^^^^^
Insert your query in the terminal, then press Ctrl-D to execute it.
.. code-block:: shell
$ gql-cli wss://countries.trevorblades.com/graphql --variables code:AF
Execute query saved in a file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Put the query in a file:
.. code-block:: shell
$ echo 'query {
continent(code:"AF") {
name
}
}' > query.gql
Then execute query from the file:
.. code-block:: shell
$ cat query.gql | gql-cli wss://countries.trevorblades.com/graphql
{"continent": {"name": "Africa"}}
Print the GraphQL schema in a file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: shell
$ gql-cli https://countries.trevorblades.com/graphql --print-schema > schema.graphql
.. note::
By default, deprecated input fields are not requested from the backend.
You can add :code:`--schema-download input_value_deprecation:true` to request them.
.. note::
You can add :code:`--schema-download descriptions:false` to request a compact schema
without comments.
|