GraphQl Pagination


#1

Hi I am using Apollo android to get a list of repositories with a keyword from the Github GraphQl

I have to add cursor based pagination as well.

This is the .graphql file

  query Search($query: String!,$afterCursor: String!){
  search(query:$query, after:$afterCursor,type: REPOSITORY, first: 50) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          id
          name
          description
          forkCount
          owner{
            login
            id
            avatarUrl
          }
        }
      }
      cursor
    }
    pageInfo {
        endCursor
        hasNextPage
      }
  }
}

What will be the value for the afterCursor variable when the request is sent for the first time

I tried null but the response failed

and I tried empty string as well

Thanks in advanceā€¦


#2

Use the endCursor field of your query as the next cursor. Note that you should only really do this if hasNextPage is true (though I suspect that endCursor will be null in that case).


#3

Here is our paginagion code for one query