grql
v0.3.5
Published
GraphQL client command line
Downloads
7
Readme
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
$ npm install grql -g
Install a bundled version to $HOME/bin
:
$ npm run installbin
Configuration
The configuration is stored into $HOME/.grql.yml, including environments settings and named queries.
Usage
Show help :
$ grql --help
Example of query : get a Giffy image from GraphQLHub
$ grql query '{ giphy { random(tag:"superbike") { url } } }'
Result :
{
"giphy": {
"random": {
"url": "http://giphy.com/gifs/rhmit-xKi2gX2tY7h3q"
}
}
}
Use YAML output format :
$ grql query '{ giphy { random(tag:"superbike") { url } } }' -y
Result :
giphy:
random:
url: http://giphy.com/gifs/gtr-UUWYxAvgO60X6
Show configured environments :
$ grql -e
environnements :
[ ] graphqlhub
[o] myenv
[ ] anotherenv
Specify your own graphql server :
$ grql --baseurl https://mysupergraphql.server/graphql query "{ myquery(foo: "bar") }"
Save own graphql server to a named configuration :
$ grql --baseurl https://mysupergraphql.server/graphql \
--conf mysuperserver --save \
query '{ myquery(foo: "bar") }'
Save a query :
$ grql --alias myquery query '{ myquery(foo: "bar") }' --save
Next, to replay the query :
$ grql --alias myquery query
Query
The query content is passed either by command argument :
$ grql query '{ contact { username: "jdoe"} }'
or by stdin :
$ echo '{ contact { username: "jdoe"} }' | grql query
Fragments
Save a new fragment :
$ cat << EOM | grql fragment gifInfo -s
fragment on GiphyGIFData {
id
url
images {
original {
url
}
}
}
EOM
Use it in a query :
$ grql query '{ giphy { random(tag:"superbike") { ...${gifInfo} } } }' -y
Mutations
Change my details with my contacts graphql server :
$ cat << EOM | grql -e contacts mutate
{
patchMe(input: {firstName: "John", lastName: "Doe"}) {
id
firstName
lastName
email
username
}
}
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!