This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-05
Channels
- # 100-days-of-code (13)
- # announcements (3)
- # beginners (120)
- # boot (17)
- # calva (19)
- # cider (27)
- # cljdoc (3)
- # cljs-dev (1)
- # clojure (138)
- # clojure-dev (5)
- # clojure-italy (5)
- # clojure-nl (20)
- # clojure-russia (3)
- # clojure-spec (14)
- # clojure-uk (119)
- # clojurescript (45)
- # core-async (2)
- # datomic (23)
- # editors (28)
- # emacs (35)
- # figwheel (2)
- # fulcro (26)
- # graphql (2)
- # hyperfiddle (11)
- # jobs (4)
- # luminus (5)
- # mount (2)
- # off-topic (52)
- # onyx (39)
- # reagent (86)
- # ring-swagger (2)
- # spacemacs (20)
- # tools-deps (9)
- # yada (4)
Hi, total GraphQL noob here. I'm thinking about replacing one of our GitHub REST API calls with GraphQL API call - basically fetching all branches for all user's repos (including all repos from all his organizations) The query could be something like this this (combined from https://platform.github.community/t/fetch-all-repos-that-are-accessible-to-a-user/1316 and https://platform.github.community/t/branches-on-repository/1766) *
{
viewer {
repositories(first: 100, after: "Y3Vyc29yOnYyOpHOABHBcQ==",affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER]) {
totalCount
pageInfo {
endCursor
hasNextPage
}
edges {
node {
name
owner {
login
}
refs(first: 100, refPrefix: "refs/heads/") {
totalCount
pageInfo {
endCursor
hasNextPage
}
edges {
node {
name
}
}
}
}
}
}
}
}
Is there any handy library I can use? Or just clj-http and POST request?
Note that I need to fetch all pages - at least for repositories but ideally for branches too.
Some lib with out-of-the-box support for paging would be useful.I actually realized that what I need is to fetch branches for all repositories in a given list. I'm currently using sth. like this:
(def repo-branches-query "
repo_name%s: repository(owner: \"%s\", name: \"%s\") {
owner {
login
}
name
defaultBranchRef {
name
}
refs(first: 100, refPrefix: \"refs/heads/\", orderBy: {field: ALPHABETICAL, direction: ASC}) {
edges {
node {
name
}
}
}
}")
(defn- repos-branches-query
"Compose a GraphQL query for fetching all branches for all given repos at once.
If any repository contains more than 100 branches then we need to use pagination
or ignore remaining branches."
[repos]
(let [partial-queries
(for [[{:keys [owner-login name]} idx]
(map vector repos (range))]
(format repo-branches-query
idx
owner-login name))]
(str
"{"
(clojure.string/join "\n" partial-queries)
"}")))