Fetching recently updated Pull Requests


#1

How can I order the nodes I get back in the order of updatedAt? Or filter through nodes using the query so I only get those nodes that have recently been updated. I don’t want to repeatedly paginate from the start and go through every node to see if it was updated since I last fetched it.


#2

Hi @amnrahman,

One approach would be something like this:

query($owner:String!,$name:String!,$cursor:String) {
  repository(owner:$owner,name:$name) {
    pullRequests(first:10,after:$cursor,orderBy:{field:UPDATED_AT,direction:ASC}) {
      edges {
        cursor
        node {
          title
          updatedAt
        }
      }
    }
  }
}

The variable inputs may look something like:

{
  "owner": "rails",
  "name": "rails",
  "cursor": null
}

As you paginate forward, you would take the cursor result from the pullRequests connection and pass it as the variable in subsequent requests. As you reach the end of the collection of pull requests, you would want to persist the last cursor you have, and then the next time that you make the query, start from that cursor; effectively saying “give me all the most recent pull requests since the last time I ran this query”.

I hope this helps, and feel free to follow up here.
Brooks


#3

This looks great! Exactly what I needed! Will give it a shot. Thanks, Brooks!


#4

There is a deprecation notice on updatedAt fields have an impact on this, will there be an equivalent replacement to enable users to continue ordering by and filtering out results based on when the pull requests were updated (any field)?


#5

Hey @cymox! We’ve just posted an announcement about these fields, let me know if you still have any questions or concerns :slight_smile:


#6

Thank you so much @d12! :smile: