Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GraphQL to query GitHub metadata #118

Open
mkitzmann opened this issue Aug 24, 2023 · 1 comment
Open

Use GraphQL to query GitHub metadata #118

mkitzmann opened this issue Aug 24, 2023 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@mkitzmann
Copy link

mkitzmann commented Aug 24, 2023

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

@nodiscc
Copy link
Owner

nodiscc commented Aug 24, 2023

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
                }
              }
            }
          }
        }
      ]
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants