Skip to content

Instantly share code, notes, and snippets.

@wchargin
Created October 2, 2018 19:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wchargin/630e03e66fa084b7b2297189615326d1 to your computer and use it in GitHub Desktop.
Save wchargin/630e03e66fa084b7b2297189615326d1 to your computer and use it in GitHub Desktop.
ghquery: hit GitHub's GraphQL API from shell
# ghquery: hit GitHub's GraphQL API
# Set the GITHUB_TOKEN environment variable.
ghquery() {
if [ "$#" -gt 1 ]; then
printf >&2 'ghquery: bad invocation\n'
printf >&2 'usage: ghquery [GRAPHQL_COMMAND]\n'
printf >&2 'if no args provided, command will be read from stdin\n'
return 1
fi
case "$#" in
0) cat ;;
1) printf '%s' "$1" ;;
esac |
jq -csR '{query: ., variables: {}}' |
curl 'https://api.github.com/graphql' -X POST \
-H "Authorization: bearer ${GITHUB_TOKEN}" \
-d @-
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment