Skip to content

Instantly share code, notes, and snippets.

@lagenorhynque
Last active March 18, 2024 20:46
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lagenorhynque/c1419487965c0fa3cf34862852825483 to your computer and use it in GitHub Desktop.
Save lagenorhynque/c1419487965c0fa3cf34862852825483 to your computer and use it in GitHub Desktop.
A minimal GitHub GraphQL API client implemented as a babashka (Clojure) script
#!/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))
@lagenorhynque
Copy link
Author

@lagenorhynque
Copy link
Author

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