【问题标题】:Use GitHub GraphQL to retrieve all open milestones and all issues (open and closed) for the milestone使用 GitHub GraphQL 检索里程碑的所有打开的里程碑和所有问题(打开和关闭)
【发布时间】:2020-05-30 14:47:56
【问题描述】:

我了解 GitHub 的基于 GraphQL 的 v4 API 比 v3 API 高效得多。

我想使用 GraphQL API 来检索给定的 repo:

  1. 所有打开的里程碑。
  2. 对于每个里程碑,它的标题、描述、所有问题(打开和关闭)
  3. 每个问题的标题、描述、状态和所有消息。

有没有直接的方法来做到这一点?

【问题讨论】:

    标签: graphql github-api


    【解决方案1】:

    是的。这样做很简单。查询看起来像:

    {
      repository(owner: "gatsbyjs", name: "gatsby") {
        description
        url
        milestones(states: [OPEN],first:2) {
          nodes{
            title
            description
            url
            issues(states:[OPEN,CLOSED], first:2){
              nodes{
                title
                state
                url
                comments(first:2){
                  nodes{
                    url
                    body
                    createdAt
                  }
                  pageInfo{
                    hasNextPage
                    endCursor
                  }
                }
              }
              pageInfo{
                 endCursor
                 hasNextPage
              }
            }
          }
          pageInfo{
            endCursor
            hasNextPage
          }
        }
      }
    }
    

    注意:

    • 对于url为https://github.com/gatsbyjs/gatsby的仓库,其所有者为gatsbyjs,名称为gatsby

    • 转到其API Explorer 尝试微调查询。单击Ctrl+Space 将自动建议可以检索的可用字段。

    • 通过调整起始光标和first,after中要返回的记录数,自行分页循环所有记录。

    它为您提供以下内容:

    {
      "data": {
        "repository": {
          "description": "Build blazing fast, modern apps and websites with React",
          "url": "https://github.com/gatsbyjs/gatsby",
          "milestones": {
            "nodes": [
              {
                "title": "Next Major",
                "description": "Issues that will require a breaking change, and which would constitute being done in the next major version of Gatsby.",
                "url": "https://github.com/gatsbyjs/gatsby/milestone/5",
                "issues": {
                  "nodes": [
                    {
                      "title": "Make accessibility warnings errors",
                      "state": "OPEN",
                      "url": "https://github.com/gatsbyjs/gatsby/issues/19945",
                      "comments": {
                        "nodes": [
                          {
                            "url": "https://github.com/gatsbyjs/gatsby/issues/19945#issuecomment-568891716",
                            "body": "Hiya!\n\nThis issue has gone quiet. Spooky quiet. ?\n\nWe get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.\nIf we missed this issue or if you want to keep it open, please reply here. You can also add the label \"not stale\" to keep this issue open!\nAs a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out [gatsby.dev/contribute](https://www.gatsbyjs.org/contributing/how-to-contribute/) for more information about opening PRs, triaging issues, and contributing!\n\nThanks for being a part of the Gatsby community! ??",
                            "createdAt": "2019-12-25T12:02:26Z"
                          },
                          {
                            "url": "https://github.com/gatsbyjs/gatsby/issues/19945#issuecomment-570779866",
                            "body": "Hey again!\n\nIt’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.\nPlease keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m `HUMAN_EMOTION_SORRY`. Please feel free to reopen this issue or create a new one if you need anything else.\nAs a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out [gatsby.dev/contribute](https://www.gatsbyjs.org/contributing/how-to-contribute/) for more information about opening PRs, triaging issues, and contributing!\n\nThanks again for being part of the Gatsby community! ??",
                            "createdAt": "2020-01-04T12:02:28Z"
                          }
                        ],
                        "pageInfo": {
                          "hasNextPage": false,
                          "endCursor": "Y3Vyc29yOnYyOpHOIgVo2g=="
                        }
                      }
                    },
                    {
                      "title": "Configurable output folder",
                      "state": "OPEN",
                      "url": "https://github.com/gatsbyjs/gatsby/issues/1878",
                      "comments": {
                        "nodes": [
                          {
                            "url": "https://github.com/gatsbyjs/gatsby/issues/1878#issuecomment-324062470",
                            "body": "Do you have a specific use case in mind? This has been discussed before but no one has come up with a concrete use case that justified adding a new option.\r\n\r\nEvery option we add to Gatsby makes the project more complex which has all sorts of long-term costs so unless something is really valuable, I'd rather people handle this sort of thing themselves e.g. just copy the files to the output directory you want or create a symlink. This could easily be turned into a plugin that people could install, etc.",
                            "createdAt": "2017-08-22T15:27:41Z"
                          },
                          {
                            "url": "https://github.com/gatsbyjs/gatsby/issues/1878#issuecomment-324074853",
                            "body": "Yes, I have a use-case. I am going to use Gatsby for a documentation part as a part of complex project. All static files (Gatsby output, plus some others) should be placed into one folder `build`, that will be deployed somehow later. In other words, the Gatsby output is only one subfolder in my setup.\r\n\r\nSo far I have worked this around in `postbuild` step, but it looks hacky:\r\n\r\n```\r\n\"build\": \"gatsby build\",\r\n\"postbuild\": \"mv public build/gatsby-subsite\"\r\n```\r\nAdding configurable output folder will reduce this complexity and will help me not to move files around one more time.",
                            "createdAt": "2017-08-22T16:08:21Z"
                          }
                        ],
                        "pageInfo": {
                          "hasNextPage": true,
                          "endCursor": "Y3Vyc29yOnYyOpHOE1D9ZQ=="
                        }
                      }
                    }
                  ],
                  "pageInfo": {
                    "endCursor": "Y3Vyc29yOnYyOpLPgAAAAAAAArvODwULXA==",
                    "hasNextPage": true
                  }
                }
              }
            ],
            "pageInfo": {
              "endCursor": "Y3Vyc29yOnYyOpHOAEEbsw==",
              "hasNextPage": false
            }
          }
        }
      }
    }
    

    【讨论】:

    • 下次查询时如何指定游标?
    • milestones(states: [OPEN],first:2, after:"Y3Vyc29yOnYyOpHOIgVo2g==")
    猜你喜欢
    • 2018-03-11
    • 2013-03-12
    • 1970-01-01
    • 2021-03-09
    • 2018-12-31
    • 1970-01-01
    • 2022-01-19
    • 2012-03-28
    • 1970-01-01
    相关资源
    最近更新 更多