top 10 javascript/opensource repositories ranked by star #24415
-
I would like to get the top 10 javascript/opensource repositories ranked by star (and some related informations) using GitHub GraphQL Api in a python project. I have this query so far:
The problem is that it does not always return the same result: it will return 10 random repositories ordered by starcount at each query rather than the absolute top 10. And on top of that I’d like to get the ones that are open source. I use the query
to get a list of licences but I don’t know if this is an exhaustive list (seems like it’s missing some licenses like MIT). According to the doc it is "Return a list of known open source licenses." How to get an exhaustive lists of the licences and add it to my main query above to make my research more precise? I can’t seem to find clear answers as the documentation about the GraphQl api for GitHub is scarce and quite vague. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
The search connection in GraphQL uses the same syntax as the search box on github.com. This means that if you can get the results you want on github.com, you can get the same results in GraphQL. The reason why it returns random results is that you didn’t sort by the number of stars. Your query asked for random JavaScript repositories. In order to sort by the number of stars, you would need to execute:
Please keep in mind that the number of stars on repos can change significantly and regularly for a number of reasons, so a given search is only a moment-in-time result. With regard to licenses, the query:
returned the following for me:
So MIT is in the list. I’m not sure what you mean by “exhaustive list of licenses”, these are the ones that GitHub recognizes currently. I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Hi, Thanks you for the answer unfortunately it doesn’t work as when I run it it doesn’t return the freecodecamp repo which should be number 1. On top of it it return a different result each time.
The right query result should be using stars:>1600 (the number is arbitrary but relevant in my case).
The support told me that it’s a timeout problem, which is why the reuslts are inconsistent. The only way to prevent that and have consistent results is to narrow down the number of stars. I got my licences confused sorry, I think that’s it. One more question: given that search first is limited to 100, what if I want the top 1000? Thanks you :slight_smile: |
Beta Was this translation helpful? Give feedback.
-
> One more question: given that search first is limited to 100, what if I want the top 1000? That requires the use of pagination. See this other topic for a good example of how to make it work. I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
It works perfeclty using pagination thanks you. I divided my searach in 20 queries that will return 50 repositories each time and get feed the next cursor at each run.
|
Beta Was this translation helpful? Give feedback.
> One more question: given that search first is limited to 100, what if I want the top 1000?
That requires the use of pagination. See this other topic for a good example of how to make it work.
I hope that helps!