如何使用GraphQL获取GitHub分支名称

时间:2018-06-13 02:16:52

标签: branch graphql github-api github-graphql

使用GitHub GraphQL API(v.4)我想获得给定存储库中存在的所有分支名称。

我的尝试

{
  repository(name: "my-repository", owner: "my-account") {
    ... on Ref {
      name
    }
  }
}

返回错误:

{'data': None, 'errors': [{'message': "Fragment on Ref can't be spread inside Repository", 'locations': [{'line': 4, 'column': 13}]}]}

1 个答案:

答案 0 :(得分:4)

以下是如何从回购中检索10个分支:

{
  repository(name: "git-point", owner: "gitpoint") {
    refs(first: 10, , refPrefix:"refs/heads/") {
      nodes {
        name
      }
    }
  }
}

PS:在处理Union类型时通常使用spread(例如,像IssueTimeline,它由不同类型的对象组成,因此您可以在特定对象类型上进行传播以查询特定字段。