• Stars
    star
    119
  • Rank 288,662 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Very simple CLI for many GraphQL schemas in the cloud. Provides autocompletion for GraphQL queries

GraphQL CLI

About

Without going too much into details, I was lately working on some integration of one of our GraphQL projects and had to write a simple internal tooling script for some simple tasks.

Now, I love curl as much as a next guy, it is my first goto tool when I need to do some debugging with anything related to REST/GraphQL/HTTP(S) in general but stil, writing

$ curl -X POST -g -H "Authorization: bearer ${GITHUB_TOKEN}" -H "Content-Type: application/json" https://api.github.com/graphql -d '{"query": "query {viewer {issues(first: 1) {nodes{title}}}}"}

is a bit of a mouthful. Especially those brackets, I actually made a typo with backets while writing this example.

So my first though was, well I'll just write a simple CLI for that project, but with GraphQL and it's introspection, you can quite easily make an "one shoe fits all" kind of tool. And that's what this project tries to be.

Now, this project is very much WIP. Any and all contributions are welcome as long as a contributor remembers one thing, the aim of this tool is not to be a robust and flexible GraphQL client that creats specialized and optimized GraphQL queries. Nor is it a tool meant to help with writing/deployment/whatnot of GraphQL schema for project. It's goal is to make a simple and convenient CLI for most schemas that already exist somewhere upstream. It's meant to be used mostly while scripting and debugging. So usage>performance.

It's quite small (~3000 lines) and comes with (almost finished) completion to boot.

sample

Requirements

Build

  • Go version 1.11 or higher

Installation

Latest release

$ sudo curl https://raw.githubusercontent.com/slothking-online/gql/master/getgql | sudo sh

From source

go get -u github.com/slothking-online/gql

Without root

$ curl https://raw.githubusercontent.com/slothking-online/gql/master/getgql | PREFIX=$HOME/bin sh

License

MIT

How It Works

The main idea is that there's "main" path to the field along which the tool is build the query. That is a bit against GraphQL ideology, as it limits the user's flexibility. Making it harder/more costly to get more complex data, but again, this tool is meant to be mostly developer tool for stuff like simple scripting,debugging and experimenting. That's why I decided it's better to just stick to simplicity rather than robustness and flexibility.

Most of functionality is self documenting (if possible pulling docs from schema). If there were no errors, unrelated to GraphQL, the data field of response will be written as JSON to stdout, while errors field to stderr.

For example

$ gql query --endpoint https://countries.trevorblades.com/ --help

will return

<snip>

Usage:
  gql query [flags]
  gql query [command]

Available Commands:
  continent   continent(code: String): Continent
  continents  continents: Continent
  countries   countries: Country
  country     country(code: String): Country
  language    language(code: String): Language
  languages   languages: Language

Flags:
      --endpoint string      graphql endpoint
      --fields stringArray   additional fields to resolve aside from the next one in resolve path
      --format string        go template response formatting
      --header Header        set header to be passed in a http request, can be set multiple times (default {})
  -h, --help                 help for query
      --max-depth int        resolve this field up to max-depth
      --no-cache             do not cache schema introspection result

Use "gql query [command] --help" for more information about a command.

So if we want to pull currency in country, for example in united states, we would do something like this:

$ gql query --endpoint https://countries.trevorblades.com/ country --arg-code US currency

which would give us

{
    "country": {
        "currency": "USD,USN,USS"
    }
}

This is not exactly useful in scriptting, as parsing json in bash is not exactly fun (unless you're using jq, but that's another dependency to install). We can refine it using Go Templates

gql query --endpoint https://countries.trevorblades.com/ country --arg-code US currency --format '{{.country.currency}}'

and then we get

USD,USN,USS

Docs

WIP

Contribute

  1. Fork this repo
  2. Create your feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

TODO

  • Tests for all of commands
  • --fields option on each node in path to include additional fields in response
  • Missing GraphQL features such as depracation and subscription (using websockets)
  • Some serious refactoring on cmd package with goal of embedding the command in custom tools.
  • Documentation for subscription and mutation
  • Cache improvements, right now it's just a simple serialized json
  • Completion improvements (right now completion, won't event hint query,mutation and subscription until endpoint path is provided)
  • ZSH completion
  • Profiles, typing --endpoint with url each time is annoying

More Repositories

1

graphql-editor

๐Ÿ“บ Visual Editor & GraphQL IDE.
TypeScript
5,934
star
2

graphql-zeus

GraphQL client and GraphQL code generator with GraphQL autocomplete library generation โšกโšกโšก for browser,nodejs and react native ( apollo compatible )
TypeScript
1,885
star
3

diagram

โ˜Š Tool for making node graphs. Inspired by dependency graph. Used mainly for automation services ๐Ÿ“ˆ
TypeScript
542
star
4

graphql-editor-cli

๐Ÿ˜ฑ GraphQL Editor Official CLI - Generate and maintain GraphQL Backend and GraphQL Server
TypeScript
76
star
5

graphql-backend-template-dgraph

Dgraph GraphQL Editor template for backend using very fast dgraph golang database server under the hood
46
star
6

ts-api-faker

Micro api faker written in TypeScript which returns faked data from JSON queries
TypeScript
45
star
7

graphql-ssg

GraphQL data based Static Site Generator.
TypeScript
30
star
8

stucco

FaaS like GraphQL runtime
Go
28
star
9

stucco-js

GraphQL server. JavaScript runtime for stucco - GraphQL backend
TypeScript
26
star
10

transform-graphql

โš™๏ธ Transformer function to transform GraphQL Directives. Create model CRUD directive for example
TypeScript
24
star
11

graphql-js-tree

Simpler structure for GraphQL AST
TypeScript
18
star
12

graphql-blog

Official GraphQLBlog repository. Add your blog posts as pull request!
JavaScript
12
star
13

sloth

Slothking.online CLI for file generation and live replace
JavaScript
11
star
14

.graph

World is moving towards graph sourced systems. This is a .graph format for storing data structure without types.
7
star
15

zeit-aurora-integration

Integration of zeit now with AWS Aurora - Easy serverless SQL database
TypeScript
6
star
16

graphql-react-admin

Admin components for GraphQL schemas
TypeScript
5
star
17

graphql-form

GraphQL Form. Driver driven forms in react
TypeScript
3
star
18

landing-page

HTML
3
star
19

hydra-ide

React wrapped monaco editor used in all graphql editor repositories
TypeScript
2
star
20

gei-users

GraphQL Editor integration for stucco. Allows basic username/password authentication flow
TypeScript
2
star
21

node

Nodejs server for slothking
TypeScript
2
star
22

graphql-docs-dryad

TypeScript
2
star
23

vs-code-theme

GraphQL Editor Vscode Dark Theme
2
star
24

graphql-editor-integrations

Backend integrations for GraphQL Editor CLI and Stucco infrastructure
TypeScript
2
star
25

graphql-dryad

GraphQL JAMstack rendering engine
TypeScript
2
star
26

i-graphql

GraphQL Friendly ORM for MongoDB and GraphQL Zeus - right now in alpha stage
TypeScript
2
star
27

graphql-guide

GraphQL Editor
1
star
28

state

State manager for typescript frontend & slothking
TypeScript
1
star
29

jobscontroller

A very simple controller to launch one off jobs in kubernetes cluster
Go
1
star
30

backend-nodets-boilerplate

Boilerplate for use with sloth CLI and node server.
JavaScript
1
star