Simple command line to query any GraphQL servers.
- Sample default configuration with GraphQLHub server endpoint
- Supports basic auth, fragments and mutations
$ npm install grql -g
Install a bundled version to $HOME/bin
:
$ npm run installbin
The configuration is stored into $HOME/.grql.yml, including environments settings and named queries.
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
The query content is passed either by command argument :
$ grql query '{ contact { username: "jdoe"} }'
or by stdin :
$ echo '{ contact { username: "jdoe"} }' | grql query
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
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
- 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!