Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use GitHub GraphQL to retrieve all open milestones and all issues (open and closed) for the milestone

I understand that GitHub's GraphQL-based v4 API is much more efficient than the v3 API.

I would like to use the GraphQL API to retrieve, for a given repo:

  1. All of the open milestones.
  2. For each milestone, its title, description, all of its issues (open and closed)
  3. For each issue, its title, description, status, and all messages.

Is there a straightforward way to do this?

like image 493
vy32 Avatar asked Nov 26 '25 05:11

vy32


1 Answers

Yes. It is straightforward to do so . The query looks like :

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

Note:

  • For the repository which the url is https://github.com/gatsbyjs/gatsby , its owner is gatsbyjs and its name is gatsby

  • Go to its API Explorer to try and fine tune the query.Click Ctrl+Space will auto-suggest the available fields that can be retrieved.

  • Do the paginating by yourself to loop through all records by adjusting the starting cursor and the number of records to be returned in first , after.

It gives you the following :

{
  "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
        }
      }
    }
  }
}
like image 166
Ken Chan Avatar answered Nov 27 '25 22:11

Ken Chan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!