You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub API v4:查询全用户类型且获详细信息的替代方案问询

Solution: Use Inline Fragments with the repositoryOwner Query

Absolutely! The key here is leveraging inline fragments with the repositoryOwner interface, which lets you fetch type-specific fields for both individual users and organizational accounts (including companies/enterprises) in a single query.

Since repositoryOwner is an interface implemented by both User and Organization (and EnterpriseAccount for GitHub Enterprise instances), you can conditionally request the detailed fields you need for each type. Here's a practical example query:

query GetOwnerDetails($login: String!) {
  repositoryOwner(login: $login) {
    __typename
    login
    avatarUrl
    # Common fields shared by all repository owners
    ... on User {
      # User-specific detailed fields
      bio
      websiteUrl
      location
      name
      email
    }
    ... on Organization {
      # Organization/company-specific detailed fields
      description
      websiteUrl
      location
      name
      email
    }
    ... on EnterpriseAccount {
      # Optional: For GitHub Enterprise accounts
      description
      websiteUrl
      name
    }
  }
}

How this works:

  • The __typename field tells you whether the result is a User, Organization, or EnterpriseAccount, so you can handle the response appropriately in your code.
  • Shared fields (like login, avatarUrl) are fetched once at the top level.
  • Type-specific fields (like bio for users, description for orgs) are included in their respective inline fragments.

This approach gives you the best of both worlds: you can query any repository owner (regardless of type) and retrieve the detailed profile information that would only be available via the user query for individual accounts.

When processing the response, just check the __typename value to access the correct set of fields. For example, if __typename is User, you'll have access to bio; if it's Organization, you'll use description instead.

内容的提问来源于stack exchange,提问作者user1449456

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:26:16