Created
October 2, 2018 19:34
-
-
Save wchargin/630e03e66fa084b7b2297189615326d1 to your computer and use it in GitHub Desktop.
ghquery: hit GitHub's GraphQL API from shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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