Last active
March 14, 2025 15:08
-
-
Save lagenorhynque/c1419487965c0fa3cf34862852825483 to your computer and use it in GitHub Desktop.
A minimal GitHub GraphQL API client implemented as a babashka (Clojure) script
This file contains hidden or 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
#!/usr/bin/env bb | |
(ns github-graphql-api-client | |
(:require | |
[babashka.curl :as curl] | |
[cheshire.core :as cheshire] | |
[clojure.pprint :refer [pprint]])) | |
(def auth-token (System/getenv "AUTH_TOKEN")) | |
(def graphql-query | |
" | |
query ($query: String!, $last: Int) { | |
search(type: ISSUE, query: $query, last: $last) { | |
nodes { | |
... on Issue { | |
title | |
url | |
repository { | |
name | |
} | |
labels(first: 10) { | |
nodes { | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
") | |
(defn run-query [query variables] | |
(-> (curl/post "https://api.github.com/graphql" | |
{:headers {"Content-Type" "application/json" | |
"Accept" "application/json" | |
"Authorization" (str "bearer " auth-token)} | |
:body (cheshire/generate-string {:query query | |
:variables variables})}) | |
:body | |
(cheshire/parse-string true))) | |
(defn -main [] | |
(pprint | |
(run-query graphql-query | |
{:query "org:my-org is:issue is:open label:\"docs\" sort:updated" | |
:last 100}))) | |
(when (= *file* (System/getProperty "babashka.file")) | |
(-main)) |
Author
lagenorhynque
commented
Jan 18, 2021
- babashka
- babashka.curl
- Cheshire
How to run
$ chmod +x github_graphql_api_client.clj
$ AUTH_TOKEN=<your GitHub API token> ./github_graphql_api_client.clj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment