Skip to content

Latest commit

 

History

History
80 lines (51 loc) · 1.72 KB

intro.rst

File metadata and controls

80 lines (51 loc) · 1.72 KB

gql-cli

GQL provides a python 3.6+ script, called gql-cli which allows you to execute GraphQL queries directly from the terminal.

This script supports http(s) or websockets protocols.

Usage

Examples

Simple query using https

$ echo 'query { continent(code:"AF") { name } }' | gql-cli https://countries.trevorblades.com
{"continent": {"name": "Africa"}}

Simple query using websockets

$ echo 'query { continent(code:"AF") { name } }' | gql-cli wss://countries.trevorblades.com/graphql
{"continent": {"name": "Africa"}}

Query with variable

$ 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.

$ gql-cli wss://countries.trevorblades.com/graphql --variables code:AF

Execute query saved in a file

Put the query in a file:

$ echo 'query {
  continent(code:"AF") {
    name
  }
}' > query.gql

Then execute query from the file:

$ cat query.gql | gql-cli wss://countries.trevorblades.com/graphql
{"continent": {"name": "Africa"}}

Print the GraphQL schema in a file

$ gql-cli https://countries.trevorblades.com/graphql --print-schema > schema.graphql