【问题标题】:Get info about several repositories from Github Graphql API in a single call通过一次调用从 Github Graphql API 获取有关多个存储库的信息
【发布时间】:2020-04-11 02:45:40
【问题描述】:

我正在尝试创建对 Github GraphQL API 的查询,该查询接收存储库列表作为参数,并在单个 API 调用中返回这些存储库的信息,有人知道该怎么做吗?

类似这样的东西(我知道这行不通)

query myOrgRepos($repos: [String!]!) {
  search(query:"""
  repo in $repos
  """, type: REPOSITORY, first: 100) {
      repo: nodes {
          ... on Repository{
              name
              description
              updatedAt
          }
      }
  }

【问题讨论】:

  • 我认为正确的方法是查询:"repo:org/repo1 repo:org/repo2 repo:org/repo3"

标签: github graphql github-graphql


【解决方案1】:

我花了一些时间来理解你的评论,所以我会完整地发布答案。关键是在查询字符串中使用 Github 的高级搜索“语法”,示例见here

以下查询将找到用户“github”的所有存储库以及用户“graphql”的graphql-js存储库:

query {
  search(query: "user:github repo:graphql/graphql-js" type: REPOSITORY first: 10) {
    nodes {
      ... on Repository {
        name
        description
        updatedAt
      }
    }
  }
}

【讨论】:

    【解决方案2】:

    我对您的问题的理解是您想输入“已知”存储库的列表并输出有关它们的信息。在这种情况下,您可以形成以下类型的查询。

    {
      nodes(ids: ["node_id_1", "node_id_2"]) {
        ... on Repository {
          nameWithOwner
          createdAt
        }
      }
    }
    

    这里的ids 是您感兴趣的存储库的node_ids。您可以通过单独的 GraphQL 调用获得这些,如下所示

    {
      repository(owner: "owner", name: "name") {
        id
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-12-11
      • 2020-09-28
      • 2014-09-29
      • 1970-01-01
      • 2019-12-06
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      相关资源
      最近更新 更多