Ilja
Ilja

Reputation: 46479

Using apollo and graphql higher order component to paginate data

I have a simple component that fetches book titles

export const books = gql`
  query Query {
    books {
      title
    }
  }
`

export default graphql(books)(BookList)

Api I am using itself doesn't have any sort of pagination mechanism specified, but I am wondering if apollo / graphql provides one out of the box, if it does what is the correct way to paginate data?

Upvotes: 1

Views: 268

Answers (1)

Piyush Bhati
Piyush Bhati

Reputation: 956

You can use skip and last in your query

skip - no of record wants to skip

last - id of last record from previous records

export const books = gql`
  query Query {
    books(skip:10, last: '\\any valid id') {
      title
   }
}

hope this will help

Upvotes: 2

Related Questions