Pagination

Often when querying the Rasayel API, you will want to fetch a list of resources, and iterate through them in digestible chunks. This is where pagination comes in.

Rasayel uses conventional Cursor-Based pagination system for its GraphQL API.

This means that with each query, you can request PageInfo, which will provide you information about the current page and how to retrieve the next page.

Examples

Here is an example where we want to retrieve our AppUsers from the Rasayel API, and information about the page

graphqlquery AppUsers {
  app {
    appUsers(after: null, first: 2) {
      nodes {
        id
      }
      pageInfo {
        hasNextPage
        endCursor
        startCursor
      }
    }
  }
}

This will return an object that contains information about the AppUsers and the page.

json{
  "data": {
    "app": {
      "appUsers": {
        "nodes": [
          {
            "id": 43
          },
          {
            "id": 44
          }
        ],
        "pageInfo": {
          "hasNextPage": true,
          "endCursor": "NDQ",
          "startCursor": "NDM"
        }
      }
    }
  }
}

Notice that the pageInfo in the response contains an endCursor key. This is our pagination cursor. To get the next page of AppUsers, we simply need to include that cursor in our query!

graphqlquery AppUsers {
  app {
    appUsers(after: "NDQ", first: 2) {
      nodes {
        id
      }
      pageInfo {
        hasNextPage
        endCursor
        startCursor
      }
    }
  }
}

The next response contains the next page of users!

json{
  "data": {
    "app": {
      "appUsers": {
        "nodes": [
          {
            "id": 45
          },
          {
            "id": 46
          }
        ],
        "pageInfo": {
          "hasNextPage": true,
          "endCursor": "NDY",
          "startCursor": "NDU"
        }
      }
    }
  }
}

Now that you know how to make a query to our GraphQL API, and how to paginate it, try out our API Playground!