Gql-cli — Gql 3 3.3.0 Documentation
- Introduction
- Usage
- Transports
- Advanced
- gql-cli
- Usage
- Positional Arguments
- Named Arguments
- AWS AppSync options
- Examples
- Simple query using https
- Simple query using websockets
- Query with variable
- Interactive usage
- Execute query saved in a file
- Print the GraphQL schema in a file
- Usage
- Reference
- »
- gql-cli
- View page source
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¶
Send GraphQL queries from the command line using http(s) or websockets. If used interactively, write your query, then use Ctrl-D (EOF) to execute it.
usage: gql-cli [-h] [-V [VARIABLES ...]] [-H [HEADERS ...]] [--version] [-d | -v] [-o OPERATION_NAME] [--print-schema] [--schema-download [SCHEMA_DOWNLOAD ...]] [--execute-timeout EXECUTE_TIMEOUT] [--transport {auto,aiohttp,httpx,phoenix,websockets,aiohttp_websockets,appsync_http,appsync_websockets}] [--api-key API_KEY | --jwt JWT] serverPositional Arguments¶
serverthe server url starting with http://, https://, ws:// or wss://
Named Arguments¶
-V, --variablesquery variables in the form key:json_value
-H, --headershttp headers in the form key:value
--versionshow program’s version number and exit
-d, --debugprint lots of debugging statements (loglevel==DEBUG)
-v, --verboseshow low level messages (loglevel==INFO)
-o, --operation-nameset the operation_name value
--print-schemaget the schema from instrospection and print it
Default: False
--schema-download select the introspection query arguments to download the schema.Only useful if –print-schema is used. By default, it will:
request field descriptions
request deprecated input fields
Possible options:
--execute-timeout
descriptions:false for a compact schema without comments
input_value_deprecation:false to omit deprecated input fields
specified_by_url:true
schema_description:true
directive_is_repeatable:true
input_object_one_of:true
set the execute_timeout argument of the Client (default: 10)
Default: 10
--transportPossible choices: auto, aiohttp, httpx, phoenix, websockets, aiohttp_websockets, appsync_http, appsync_websockets
select the transport. ‘auto’ by default: aiohttp or websockets depending on url scheme
Default: “auto”
AWS AppSync options¶
By default, for an AppSync backend, the IAM authentication is chosen.
If you want API key or JWT authentication, you can provide one of the following arguments:
--api-keyProvide an API key for authentication
--jwtProvide an JSON Web token for authentication
Examples¶
Simple query using https¶
$echo'query { continent(code:"AF") { name } }'|gql-clihttps://countries.trevorblades.com {"continent":{"name":"Africa"}}Simple query using websockets¶
$echo'query { continent(code:"AF") { name } }'|gql-cliwss://countries.trevorblades.com/graphql {"continent":{"name":"Africa"}}Query with variable¶
$echo'query getContinent($code:ID!) { continent(code:$code) { name } }'|gql-clihttps://countries.trevorblades.com--variablescode:AF {"continent":{"name":"Africa"}}Interactive usage¶
Insert your query in the terminal, then press Ctrl-D to execute it.
$gql-cliwss://countries.trevorblades.com/graphql--variablescode:AFExecute query saved in a file¶
Put the query in a file:
$echo'query { continent(code:"AF") { name } }'>query.gqlThen execute query from the file:
$catquery.gql|gql-cliwss://countries.trevorblades.com/graphql {"continent":{"name":"Africa"}}Print the GraphQL schema in a file¶
$gql-clihttps://countries.trevorblades.com/graphql--print-schema>schema.graphqlNote
You can add --schema-download descriptions:false to request a compact schema without comments.
Warning
By default, from gql version 4.0, deprecated input fields are requested from the backend. It is possible that some old backends do not support this feature. In that case you can add --schema-download input_value_deprecation:false to go back to the previous behavior.