Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 2

graphql cursor pagination; cursor changing on new entries

Solved! Go to Solution.

The cursor I get back appears not to be persistent; the entry a given cursor refers to is always the first entry.  If the list updates, the same cursor will refer to a new entry.  This makes it impossible to fetch new entries based on cursor; and if the list updates while I'm paging through it, this could cause me to miss items (even if I wanted to pull the full list every time, which I most emphatically do not :)

I've got a query like:

{
  organization(login: "myorg") {
    auditLog(first: 10) {
      totalCount
      pageInfo {
        endCursor
        startCursor
        hasNextPage
      }
      edges {
        cursor
        node {

and I get a result like

{
  "data": {
    "organization": {
      "auditLog": {
        "totalCount": 281,
        "pageInfo": {
          "endCursor": "Y3Vyc29yOjEw",
          "startCursor": "Y3Vyc29yOjE=",
          "hasNextPage": true
        },
        "edges": [
          {
            "cursor": "Y3Vyc29yOjE=",
            "node": {
"__typename": "RepoDestroyAuditEntry",

If I then create a new repo, to generate an audit entry, and re-run the query:

{
  "data": {
    "organization": {
      "auditLog": {
        "totalCount": 282,
        "pageInfo": {
          "endCursor": "Y3Vyc29yOjEw",
          "startCursor": "Y3Vyc29yOjE=",
          "hasNextPage": true
        },
        "edges": [
          {
            "cursor": "Y3Vyc29yOjE=",
            "node": {
              "__typename": "RepoCreateAuditEntry",
              "action": "repo.create",

Note that I get the same cursor range (....E= to ...Ew) but they refer to a different set of entries.  It's as if the cursors are just indices into the list, and as new entries are added to the front of the list, the cursors change.  The first entry is always `Y3Vyc29yOjE=`

1 Reply
Solution
Copilot Lvl 2
Message 2 of 2

Re: graphql cursor pagination; cursor changing on new entries

I think I've figured this out myself; if I add an orderBy to my request, I can sort them ascending by date and it solves this issue:

   auditLog(first: 10, orderBy: {field: CREATED_AT, direction: ASC}) {