Skip to content

Commit

Permalink
Add wait method and delay between pagination requests
Browse files Browse the repository at this point in the history
  • Loading branch information
thedave42 committed Apr 4, 2024
1 parent 8b0f7a8 commit 84e22e5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const options = {
continueOnError: false
};

// Create a method that waits for a specified number of milliseconds
const wait = (ms) => {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};

let { graphql } = require('@octokit/graphql')
graphql = graphql.defaults({
Expand All @@ -38,7 +44,7 @@ const findDeps = async (org, repo) => {
`query ($org: String! $repo: String! $cursor: String){
repository(owner: $org name: $repo) {
name
dependencyGraphManifests(first: 100 after: $cursor) {
dependencyGraphManifests(first: 20 after: $cursor) {
pageInfo {
hasNextPage
endCursor
Expand Down Expand Up @@ -131,6 +137,8 @@ const findDeps = async (org, repo) => {
}

if (hasNextPage) {
// Wait for 500ms before requesting the next page
await wait(500)
console.log('nextpage');
pagination = getDepsResult.repository.dependencyGraphManifests.pageInfo.endCursor;
}
Expand Down

0 comments on commit 84e22e5

Please sign in to comment.