Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query all languages from GitHubs graphql

I am trying to query GitHub for information about repositories using their v4 graphql. One of the things I want to query is the breakdown of all the languages used in the repo. Or if possible, the breakdown of the languages across all of a user's repos. I have tried the following snippet, but it returns null, where as primary language returns the primary language

languages: {
  edges: {
    node: {
      name
    }
  }
}

The only thing I can find relating to languages is the primary language. But I would like to show stats for a user and the all languages they use either in a single repo or across off their repos.

like image 867
Int'l Man Of Coding Mystery Avatar asked Dec 14 '22 09:12

Int'l Man Of Coding Mystery


1 Answers

You are missing the slicing field, here you can put first: 100 to get the first 100 languages for the repository:

{
  user(login: "torvalds") {
    repositories(first: 100) {
      nodes {
        primaryLanguage {
          name
        }
        languages(first: 100) {
          nodes {
            name
          }
        }
      }
    }
  }
}

If you want to have stats per language (eg if you want to know which is the second, third language etc...) I'm affraid this is not currently possible with the graphql API but using the List Languages API Rest for instance https://api.github.com/repos/torvalds/linux/languages

like image 152
Bertrand Martel Avatar answered Jan 28 '23 16:01

Bertrand Martel