简体   繁体   中英

GitHub GraphQL cursor Pagination on first request

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..

If you can remove the ! from $afterCursor: String! , that should work.

The problem of sending null or empty is that is not a valid cursor, so if we make it not required (by removing ! from the parameters), then you don't have to send it at all, and that works for the first time you run the query.`

Something like this:

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
      }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM