HomeAbout

Cursor Pagination Example

Schema

interface Character { id: ID! name: String! friends: [Character] friendsConnection(first: Int, after: ID): FriendsConnection! appearsIn: [Episode]! } type FriendsConnection { totalCount: Int edges: [FriendsEdge] friends: [Character] pageInfo: PageInfo! } type FriendsEdge { cursor: ID! node: Character } type PageInfo { startCursor: ID endCursor: ID hasNextPage: Boolean! }

Query

query { hero { name friendsConnection(first: 2, after: "Y3Vyc29yMQ==") { totalCount edges { node { name } cursor } pageInfo { endCursor hasNextPage } } } }

Response

{ "data": { "hero": { "name": "R2-D2", "friendsConnection": { "totalCount": 3, "edges": [ { "node": { "name": "Han Solo" }, "cursor": "Y3Vyc29yMg==" }, { "node": { "name": "Leia Organa" }, "cursor": "Y3Vyc29yMw==" } ], "pageInfo": { "endCursor": "Y3Vyc29yMw==", "hasNextPage": false } } } } }
AboutContact