【问题标题】:How to get all comments along with issues with github graphql如何获取所有评论以及 github graphql 的问题
【发布时间】:2021-05-07 08:00:55
【问题描述】:

我正在尝试这个get github issues by their ids through graphql endpoints

并尝试了这段代码

{
  repository(name: "reponame", owner: "ownername") {
    issue1: issue(number: 2) {
      title
      createdAt
    }
    issue2: issue(number: 3) {
      title
      createdAt
    }
    issue3: issue(number: 10) {
      title
      createdAt
    }
  }
}

有了这个,我可以取回标题,但我也试图获得该问题的所有 cmets。我尝试在上面的代码中添加comments,但没有成功。

我只想修改上面的代码。

提前致谢!

【问题讨论】:

    标签: github graphql github-api github-graphql


    【解决方案1】:

    使用 GraphQL,您必须选择所需的每个标量字段。到目前为止,您已经选择了Issue.titleIssue.createdAt 的标量字段。然而,注释不是“标量值”——它们是对象——所以要从它们中得到任何东西,你必须深入到对象中直到标量值。

    此外,评论是paginated connection,因此您还必须定义要返回的数量并深入连接以到达“节点”,这是您真正想要的对象:

    query {
      repository(name:"reponame", owner: "ownername") {
        issue(number: 2) {
          title
          createdAt
          # first 10 results
          comments(first: 10) {
            # edges.node is where the actual `Comment` object is
            edges {
              node {
                author {
                  avatarUrl
                }
                body
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-11
      • 1970-01-01
      • 2018-09-16
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 2013-11-26
      相关资源
      最近更新 更多