Github API - Find number of followers for all my followers

github, github-api

Solution

You can use GraphQL API v4 to do that, the following will retrieve the 100 first followers with their respective followers count :

{
  user(login: "bertrandmartel") {
    followers(first: 100) {
      totalCount
      edges {
        node {
          login
          followers(first: 0) {
            totalCount
          }
        }
        cursor
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

You will then need to go through pagination with the `cursor` value specifying `after: "END_CURSOR_VALUE"` if `hasNextPage` is `true`.

Problem

I'm able to find the number of followers for a particular user but I wondered how best to go about finding the number of followers each follower has. I could of course loop through each follower and then total up the follower count but this will be "expensive" and start pushing me towards the API rate limiting. Does anyone know of a better way to approach something like this?

Original source