簡體   English   中英

如何獲取所有評論以及 github graphql 的問題

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

我正在嘗試通過 graphql 端點通過他們的 id 獲取 github 問題

並嘗試了這段代碼

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

有了這個,我可以取回標題,但我也試圖獲得該問題的所有評論。 我嘗試在上面的代碼中添加comments ,但沒有奏效。

我只想修改上面的代碼。

提前致謝!

使用 GraphQL,您必須 select 您想要的每個標量字段。 到目前為止,您已經選擇了Issue.titleIssue.createdAt的標量字段。 然而,注釋不是“標量值”——它們是對象——所以要從它們中得到任何東西,你必須深入到對象中直到標量值。

此外, 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