Use GraphQL to query GitHub metadata
mkitzmann opened this issue · comments
As discussed here https://lemmy.world/post/3622280
Using the Github GraphQL API would allow to query all the needed data for 100 repos with one request. This would make it possible to stay below the rate limit without using a timeout. (More info on the GraphQL ratelimits)
An example of how this could look can be found here: https://github.com/mkitzmann/awwesome/blob/main/src/lib/query.ts
The (POST) request to https://api.github.com/graphql looks something like this:
{
search(
type: REPOSITORY
query: "repo:electerious/Ackee repo:aptabase/aptabase"
first: 100
) {
repos: edges {
repo: node {
... on Repository {
url
name
owner {
avatarUrl
}
descriptionHTML
stargazerCount
defaultBranchRef {
target {
... on Commit {
july: history(since: "2023-07-01T00:00:00", until: "2023-07-31T00:00:00") {
totalCount
}
}
}
}
}
}
}
}
}
It can be tested inside the GitHub GraphQL explorer: https://docs.github.com/en/graphql/overview/explorer
Interesting, thank you. I will look into this for the next release.
For reference, the above query yields the following reply:
{
"data": {
"search": {
"repos": [
{
"repo": {
"url": "https://github.com/electerious/Ackee",
"name": "Ackee",
"owner": {
"avatarUrl": "https://avatars.githubusercontent.com/u/499088?v=4"
},
"descriptionHTML": "<div>Self-hosted, Node.js based analytics tool for those who care about privacy.</div>",
"stargazerCount": 3914,
"defaultBranchRef": {
"target": {
"july": {
"totalCount": 0
}
}
}
}
},
{
"repo": {
"url": "https://github.com/aptabase/aptabase",
"name": "aptabase",
"owner": {
"avatarUrl": "https://avatars.githubusercontent.com/u/126899775?v=4"
},
"descriptionHTML": "<div>✨ Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps</div>",
"stargazerCount": 227,
"defaultBranchRef": {
"target": {
"july": {
"totalCount": 89
}
}
}
}
}
]
}
}
}