Skip to main content

GraphQL client in the terminal.

Project description

Build and execute GraphQL queries in the terminal.

This project is inspired by https://graphiql-online.com.

https://github.com/eerimoq/gqt/raw/main/docs/assets/showcase.gif

Installation

pip3 install gqt

It’s recommended to install bat for pretty output.

Controls

  • Press h or ? for help.

Examples

Set default GraphQL endpoint:

export GQT_ENDPOINT=https://mys-lang.org/graphql

Interactively create a query and execute it:

gqt
{
    "statistics": {
        "numberOfGraphqlRequests": 3
    }
}

Repeat last query:

gqt -r
{
    "statistics": {
        "numberOfGraphqlRequests": 4
    }
}

Print the query instead of executing it:

gqt -q
query Query {
  statistics {
    numberOfGraphqlRequests
  }
}

YAML output:

gqt -y
statistics:
  numberOfGraphqlRequests: 8

Name queries:

gqt -n stats -y
statistics:
  numberOfGraphqlRequests: 8
gqt -n time -y
standardLibrary:
  package:
    latestRelease:
      version: 0.20.0
gqt -n stats -y -r
statistics:
  numberOfGraphqlRequests: 9
gqt -n time -y -r
standardLibrary:
  package:
    latestRelease:
      version: 0.20.0

List cached queries:

gqt -l
Endpoint                      Query name
----------------------------  ------------
https://mys-lang.org/graphql  <default>
https://mys-lang.org/graphql  time
https://mys-lang.org/graphql  stats

Make arguments variables by pressing v or $ and give them as -v <name>=<value> on the command line:

gqt -v name=time -y
standardLibrary:
  package:
    latestRelease:
      version: 0.20.0
gqt -r -q
query Query($name: String!) {
  standardLibrary {
    package(name: $name) {
      latestRelease {
        version
      }
    }
  }
}

Print the schema:

gqt --print-schema
type Query {
  standardLibrary: StandardLibrary!
  statistics: Statistics!
  activities: [Activity!]!
}

type StandardLibrary {
  package(name: String!): Package!
  packages: [Package!]
  numberOfPackages: Int
  numberOfDownloads: Int
}
...

Known issues

  • There is one query cache per gqt version. Would be nice to keep the cache after upgrading gqt.

  • The query is cleared when reloading the schema.

Ideas

  • Press c for compact view, hiding fields that are not selected.

  • Search:

    Press / to search for visible fields. Press <Up> and <Down> to move to the previous and next search hit. Highlight all hits. Press <Enter> to end the search and move the cursor to the current hit. Press <Esc> to abort the search and restore the cursor to its pre-search position. Show number of hits.

    ╭─ Query
    │ ▼ search
    │   ▶ Book
    │     ■ title
    │   ▶ Author
    │     ■ name
    │ ▶ film
    │ ▶ films
    
    /fil                                                1 of 2 matches
  • Alias?

    • Press a to create an alias.

    • Press d to delete an alias.

    smallPicture and mediumPicture are aliases of picture.

    ╭─ Query
    │ ▶ Book
    │   ▶ picture
    │   ▼ smallPicture: picture
    │     ■ width: 320
    │     ■ height: 240
    │   ▼ mediumPicture: picture
    │     ■ width: 800
    │     ■ height: 600
  • Keep valid parts of any existing query when reloading the schema.

  • Cache across updates.

    • Save introspection response.

    • Save last query.

    • Save cursor and possibly other state.

    -- ~/.cache/gqt/cache/generic/
       +-- <endpoint 1>
           +-- schema.json
           +-- query.graphql
           +-- state.json
           +-- query_names/
               +-- stats/
                   +-- schema.json
                   +-- query.graphql
                   +-- state.json
  • Optionally give schema path on command line. For endpoints that does not support schema introspection.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gqt-0.101.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

gqt-0.101.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file gqt-0.101.0.tar.gz.

File metadata

  • Download URL: gqt-0.101.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for gqt-0.101.0.tar.gz
Algorithm Hash digest
SHA256 22573d5482b396479001ce53dc7f4c38b50abef094dd2f268721da584ffe9daf
MD5 734a89c836eccc2cec278226277d226e
BLAKE2b-256 91380f20a491ea79c69e8f4327c24ab189a7862c23ba6ecfbbb0fba1f798bb46

See more details on using hashes here.

File details

Details for the file gqt-0.101.0-py3-none-any.whl.

File metadata

  • Download URL: gqt-0.101.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for gqt-0.101.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b10a5c702503d10da8f7fc15929540948660199e70ca90cb94d0a46df844c80
MD5 439537b3faa6a39588a0cf1b3340eba8
BLAKE2b-256 f1c6d57fd63b0a4412ef665a8ac6be35e87da7df1345c5e73cdc62f19d279f72

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page