【发布时间】:2018-06-15 19:18:10
【问题描述】:
使用user 查询时,GitHub API v4 不显示公司的结果。如果我改用repositoryOwner,它会为用户和公司返回结果。但是user查询可以返回更详细的信息,例如repositoryOwner查询中不包含的传记、网站、位置等。
是否有涵盖所有类型用户的替代选项?
【问题讨论】:
标签: github graphql github-api github-graphql
使用user 查询时,GitHub API v4 不显示公司的结果。如果我改用repositoryOwner,它会为用户和公司返回结果。但是user查询可以返回更详细的信息,例如repositoryOwner查询中不包含的传记、网站、位置等。
是否有涵盖所有类型用户的替代选项?
【问题讨论】:
标签: github graphql github-api github-graphql
您可以分别使用... on User和... on Organization访问RepositoryOwner中的User或Organization接口:
{
repositoryOwner(login: "google") {
... on User {
avatarUrl
bio
}
... on Organization {
name
members {
totalCount
}
}
}
}
如果结果是一个组织,它只会返回您在... on Organization块中指定的字段,如果结果是一个用户,它将返回... on User中指定的字段,在这种情况下google是一个组织:
{
"data": {
"repositoryOwner": {
"name": "Google",
"members": {
"totalCount": 1656
}
}
}
}
【讨论】: