Last active
June 10, 2020 15:01
-
-
Save faresd/64f33dd9e0afb1c92a5da948424a7f9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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