Graph QL pull requests end point query fails with after/before arguments

community-help
announcements

#1

Hello,

I had fetched the id of the pull request using RAST API endpoint and tried fetching the pull request data after the id using below

query {
  repository(owner: "XXX", name: "XXX") {
    pullRequests( last:25, baseRefName: "10.19" ,after:"310590" ) {
      edges {
        node {
          title
          url
          author{
            login
          }
          state
          createdAt
          
          labels(first: 10) {
            edges {
              node {
                name
              }
            }
          }
          comments(first: 3) {
            edges {
              node {
                body
                author{
                  login
                }
              }
            }
          }
        }
      }
    }
  }
}

But I keep getting the error below . I am sure there are a number of pull requests created after this id and was not sure why the data is not being returned.Can some one provide any insights ?

{
  "data": {
    "repository": {
      "pullRequests": {
        "edges": null
      }
    }
  },
  "errors": [
    {
      "message": "`310590` does not appear to be a valid cursor.",
      "type": "INVALID_CURSOR_ARGUMENTS",
      "path": [
        "repository",
        "pullRequests",
        "edges"
      ],
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ]
    }
  ]
}

#2

:wave: Hi @gskumar0320,

The after and before arguments are designed to take in a cursor, which is generated (and only accessible from) the GraphQL API. I’ve modified your query to request a cursor as well:

query {
  repository(owner: "rails", name: "rails") {
    pullRequests(last:25) {
      edges {
        cursor
        node {
          title
          url
          author{
            login
          }
          state
          createdAt
          
          labels(first: 10) {
            edges {
              node {
                name
              }
            }
          }
          comments(first: 3) {
            edges {
              node {
                body
                author{
                  login
                }
              }
            }
          }
        }
      }
    }
  }
}

In this example, each of the edges that are returned, also return a cursor. If I were to take the last cursor of my results, and pass that in as the before argument, I’d get the next set of results in the collection:

query {
  repository(owner: "rails", name: "rails") {
    pullRequests(last:25, before:"Y3Vyc29yOnYyOpHOCRTx9g==") {
      edges {
        cursor
        node {
          title
          url
          author{
            login
          }
          state
          createdAt
          
          labels(first: 10) {
            edges {
              node {
                name
              }
            }
          }
          comments(first: 3) {
            edges {
              node {
                body
                author{
                  login
                }
              }
            }
          }
        }
      }
    }
  }
}

Does this help?