Skip to content

Instantly share code, notes, and snippets.

@faresd
Last active June 10, 2020 15:01
Show Gist options
  • Save faresd/64f33dd9e0afb1c92a5da948424a7f9c to your computer and use it in GitHub Desktop.
Save faresd/64f33dd9e0afb1c92a5da948424a7f9c to your computer and use it in GitHub Desktop.
const getAllPages = (allData, endCursor) =>
getPage(endCursor)
.then(response => {
if (response.pageInfo.hasNextPage) {
return getAllPages(response.edges, response.edges.cursor)
.then(nextPage => allData.push(nextPage))
} else {
return allData
}
})
function getPage(cursor) {
return client.query({
query: GETNEXTDATA, variables: { after: cursor },
}).then(response => {
console.log(response)
return response.data.allItems
}).catch(error => {
console.error(error)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment