user1449456
user1449456

Reputation: 642

GitHub v4 API query for both organizations and users

GitHub API v4 does not show the results for companies when user query is used. If I use repositoryOwner instead, it returns results for both users and companies. However, user query can return more detailed information such as biography, website, location etc. which is not included in repositoryOwner query.

Is there an alternative option covering all type of users?

Upvotes: 3

Views: 817

Answers (1)

Bertrand Martel
Bertrand Martel

Reputation: 45483

You can access the User or Organization interface in RepositoryOwner using respectively ... on User & ... on Organization :

{
  repositoryOwner(login: "google") {
    ... on User {
      avatarUrl
      bio
    }
    ... on Organization {
      name
      members {
        totalCount
      }
    }
  }
}

Try it in the explorer

If the result is an organization it will only returns the fields you specifed in ... on Organization block, if the result is a user it will return the fields specified in ... on User, in this case as google is an organization :

{
  "data": {
    "repositoryOwner": {
      "name": "Google",
      "members": {
        "totalCount": 1656
      }
    }
  }
}

Upvotes: 6

Related Questions