项目作者: openhoat

项目描述 :
Simple command line to query any GraphQL servers
高级语言: JavaScript
项目地址: git://github.com/openhoat/grql.git
创建时间: 2017-05-26T09:51:15Z
项目社区:https://github.com/openhoat/grql

开源协议:MIT License

下载


NPM version
Build Status
Coverage Status
npm

GraphQL client command line

Simple command line to query any GraphQL servers.

  • Sample default configuration with GraphQLHub server endpoint
  • Supports basic auth, fragments and mutations

Installation

  1. $ npm install grql -g

Install a bundled version to $HOME/bin :

  1. $ npm run installbin

Configuration

The configuration is stored into $HOME/.grql.yml, including environments settings and named queries.

Usage

Show help :

  1. $ grql --help

Example of query : get a Giffy image from GraphQLHub

  1. $ grql query '{ giphy { random(tag:"superbike") { url } } }'

Result :

  1. {
  2. "giphy": {
  3. "random": {
  4. "url": "http://giphy.com/gifs/rhmit-xKi2gX2tY7h3q"
  5. }
  6. }
  7. }

Use YAML output format :

  1. $ grql query '{ giphy { random(tag:"superbike") { url } } }' -y

Result :

  1. giphy:
  2. random:
  3. url: http://giphy.com/gifs/gtr-UUWYxAvgO60X6

Show configured environments :

  1. $ grql -e
  2. environnements :
  3. [ ] graphqlhub
  4. [o] myenv
  5. [ ] anotherenv

Specify your own graphql server :

  1. $ grql --baseurl https://mysupergraphql.server/graphql query "{ myquery(foo: "bar") }"

Save own graphql server to a named configuration :

  1. $ grql --baseurl https://mysupergraphql.server/graphql \
  2. --conf mysuperserver --save \
  3. query '{ myquery(foo: "bar") }'

Save a query :

  1. $ grql --alias myquery query '{ myquery(foo: "bar") }' --save

Next, to replay the query :

  1. $ grql --alias myquery query

Query

The query content is passed either by command argument :

  1. $ grql query '{ contact { username: "jdoe"} }'

or by stdin :

  1. $ echo '{ contact { username: "jdoe"} }' | grql query

Fragments

Save a new fragment :

  1. $ cat << EOM | grql fragment gifInfo -s
  2. fragment on GiphyGIFData {
  3. id
  4. url
  5. images {
  6. original {
  7. url
  8. }
  9. }
  10. }
  11. EOM

Use it in a query :

  1. $ grql query '{ giphy { random(tag:"superbike") { ...${gifInfo} } } }' -y

Mutations

Change my details with my contacts graphql server :

  1. $ cat << EOM | grql -e contacts mutate
  2. {
  3. patchMe(input: {firstName: "John", lastName: "Doe"}) {
  4. id
  5. firstName
  6. lastName
  7. email
  8. username
  9. }
  10. }
  11. EOM

Switches

  • verbose : show more details
  • dryrun : does not finally execute the query
  • env : show current environment or select the specified environment
  • nocolor : disable color mode
  • alias : select an alias to save or play
  • save : save options to current environment
  • yaml : enable YAML output format
  • var : inject a variable (format key=value)

Enjoy!