简体   繁体   English

如何获取所有评论以及 github graphql 的问题

[英]How to get all comments along with issues with github graphql

I'am trying this get github issues by their ids through graphql endpoints我正在尝试通过 graphql 端点通过他们的 id 获取 github 问题

And tried this code并尝试了这段代码

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

With this, I am able to get back the title, but I am also trying to get all of the comments of the issue.有了这个,我可以取回标题,但我也试图获得该问题的所有评论。 I tried adding comments to the above code, but it didn't work.我尝试在上面的代码中添加comments ,但没有奏效。

I want to modify the above code only.我只想修改上面的代码。

Thanks in advance!提前致谢!

With GraphQL, you have to select every scalar field that you want.使用 GraphQL,您必须 select 您想要的每个标量字段。 So far, you have selected the scalar fields of Issue.title and Issue.createdAt .到目前为止,您已经选择了Issue.titleIssue.createdAt的标量字段。 Comments, however, are not "scalar values" -- they're objects -- so to get anything out of them, you have to request deeply into the objects all the way to the scalar values.然而,注释不是“标量值”——它们是对象——所以要从它们中得到任何东西,你必须深入到对象中直到标量值。

Additionally, Comments are a paginated connection , so you also have to define how many you want back and go deep into the connection to get to the "node", which is the object you actually want:此外, Comments 是一个 分页连接,因此您还必须定义要返回的数量和 go 深入连接以到达“节点”,即您真正想要的 object:

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
          }
        }
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM