Best way to gather all stars a user has received


#1

I’m trying to sum all the stars a given user has received in his repos.
What’s the fastest way to query this?

Right now I’m querying all the users repos, to access that repos stars so I can add them up.

Is there a way to:

  • Accessing the stars without fetching every repo
    or
  • Sorting repos by their star count so I can get just fetch, say, the top 6 repos.

Cheers :).


#2

I’m afraid not. We must fetch the repo to know if it’s been starred or not.

Yes! We just have to get a little crafty. :grin:

Our early access GraphQL system supports our search syntaxes. You can craft a query that looks like this:

{
  search(type: REPOSITORY, query: "user:gjtorikian sort:stars-desc", first: 6) {
    edges {
      node {
        ... on Repository {
          name
          stargazers {
            totalCount
          }
        }
      }
    }
  }
}

That says: given a user, get me their first six repositories sorted by stars descending; on each ... on Repository fragment, I want the name of the repo, and the total count of stargazers.

Hope this helps!