Cannot get issue comments by specifying a comment's global ld


#1

I would like to get issue comments using GraphQL API, but I have no idea what I have to provide for a comment’s global ID.

For example, when you want to some comments in a issue, API says you can specify a global ID for after and before arguments:

after: String
Returns the elements in the list that come after the specified global ID.

before: String
Returns the elements in the list that come before the specified global ID.

I tried to give it a id shown in id in a comment, but it failed with the following error:

...
      "message": "`MDEyOklzc3VlQ29tbWVudDE3NDgyNTg1Nw==` does not appear to be a valid cursor.",
      "type": "INVALID_CURSOR_ARGUMENTS",
...

The query I executed is:

{
  repository(owner: "5t111111", name: "middleman-blog-drops-template") {
    issue(number: 1) {
      comments(after: "MDEyOklzc3VlQ29tbWVudDE3NDgyNTg1Nw==", first: 3) {
        edges {
          node {
            id
            databaseId
          }
        }
      }
    }
  }
}


The above id MDEyOklzc3VlQ29tbWVudDE3NDgyNTg1Nw== is actually shown in the result of the following query:

{
  repository(owner: "5t111111", name: "middleman-blog-drops-template") {
    issue(number: 1) {
      comments(first: 3) {
        edges {
          node {
            id
            databaseId
          }
        }
      }
    }
  }
}

This returns:

{
  "data": {
    "repository": {
      "issue": {
        "comments": {
          "edges": [
            {
              "node": {
                "id": "MDEyOklzc3VlQ29tbWVudDE3NDQzMzYxMw==",
                "databaseId": 174433613
              }
            },
            {
              "node": {
                "id": "MDEyOklzc3VlQ29tbWVudDE3NDgyNTg1Nw==",
                "databaseId": 174825857
              }
            },
            {
              "node": {
                "id": "MDEyOklzc3VlQ29tbWVudDE3NDg4NTMzNA==",
                "databaseId": 174885334
              }
            }
          ]
        }
      }
    }
  }
}

The second comment’s id is what I provide to after argument.

I also tried with databaseId, but the result was the same.

Please let me know how to get specific comments by id, thanks!


#2

Hey @5t111111

It looks like you’ve actually found a bit of a documentation error here! before and after use cursors for pagination, not global IDs.

The cursors you’ll use for pagination don’t exist on the node, you’ll need to grab them off of the edge from your connection. A query like this should work:

{
  repository(owner: "5t111111", name: "middleman-blog-drops-template") {
    issue(number: 1) {
      comments(first: 3) {
        edges {
          cursor
          node {
            id
          }
        }
      }
    }
  }
}

The cursors you get back can be used with before or after.

We’ll try to fix up that documentation issues ASAP, thanks for pointing that out :slight_smile:

Let me know if you have any issues with using cursors for pagination!


#3

ah I didn’t come to realize that it is the documentation error. I’ll try pagination, thanks!