如何在Github Api的单个网络调用中按名称搜索branch_count和存储库列表?



我试图使用Github Search Api按名称显示存储库列表。我的要求是在搜索栏中显示与用户提供的字符串匹配的名称或描述的所有存储库的列表。我通过使用这个调用'

成功地做到了这一点。

https://api.github.com/search/repositories?q=swiftui&页面= 1,per_page = 10`但我的问题是,它不返回分支计数,这是一个必要的显示。如何在不进行多个网络呼叫的情况下实现此功能?

我尝试了一些使用Rest API的不同方法,但无法找到分支计数的任何解决方案。所以Graphql最终解决了我的问题。

let getReposQuery: String =
"""
query getRepos($searchText: String!) {
search(query: $searchText type: REPOSITORY first: 10) {
nodes {
... on Repository {
name,
description,
createdAt,
refs(first: 100, refPrefix:"refs/heads/") {
totalCount
nodes {
name,
id
}
}
}
}
}
}
""" 
对于这个查询,您需要提供searchText作为变量。

最新更新