如何使用图形 API 获取具有特定 github 主题的所有存储库

问题描述 投票:0回答:2

我想获取所有存储库,我是特定主题的所有者/贡献者。

我尝试了以下要求。这返回了我作为所有主题的所有者/贡献者的所有存储库。

{
  viewer {
    repositories(first: 100) {
      pageInfo {
        hasPreviousPage
        hasNextPage
        startCursor
        endCursor
      }
      nodes {
        name
        repositoryTopics(first: 10) {
          nodes {
            topic {
              name
            }
          }
          totalCount
        }
      }
    }
  }
}

我也尝试了以下请求。但它返回了我的组织(不仅是我的组织)中具有该特定主题的所有存储库。

{
  search(first: 100, type: REPOSITORY, query: "topic:mytopic org:myorg") {
    pageInfo {
      hasNextPage
      endCursor
      }
    repos: edges {
      repo: node {
        ... on Repository {
          name
          url
          id
        }
      }
    }
  }
}

我只需要我是该特定主题的所有者/贡献者的存储库

api github graphql github-api github-graphql
2个回答
0
投票

在您的第一个查询中,您似乎已经获取了前 100 个主题,而不管它们的实际主题是什么。为了根据主题进行选择,您必须使用变量。此后,使用 useQuery 挂钩并传递您的变量。(您可以创建一个输入字段并将其值与您过滤的变量相关联)。在 apollo 文档中查看更多信息:https://www.apollographql.com/docs/react/data/queries/#caching-query-results


0
投票
{
  search(first: 100, type: REPOSITORY, query: "topic:topic") {
    pageInfo {
      hasNextPage
      endCursor
      }
    repos: edges {
      repo: node {
        ... on Repository {
          name
          url
          id
        }
      }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.