List of repositories in graph vs Rest api fetch different results


#1

When I try to fetch a list of repositories of a user in graphql and rest api I get different results. For example, when I extract a list of repositories of user “torvalds” in graphql I get a list of 32 repositories.

When I do it in rest API I get a list of 6 repositories.

and when I look at GitHub webpage I get a list of 6 repositories extracted from rest api.

Not sure what is wrong in that.

Can anyone guide me?


#2

Hey @vinodahujauno,

You’re seeing this difference because this GraphQL field defaults to also including repositories the user has collaborated on. For more fine-grained control over returned resources, you can provide an affiliations argument to the repositories connection.

{
  user(login:"torvalds"){
    repositories(first: 100, affiliations: [OWNER]){
      totalCount
      nodes{
        nameWithOwner
      }
    }
  }
}
{
  "data": {
    "user": {
      "repositories": {
        "totalCount": 6
      }
    }
  }
}

#3

Thanks. This was helpful.