Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub GraphQL cursor Pagination on first request #338

Open
ktikku opened this issue Apr 5, 2022 · 1 comment
Open

GitHub GraphQL cursor Pagination on first request #338

ktikku opened this issue Apr 5, 2022 · 1 comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@ktikku
Copy link

ktikku commented Apr 5, 2022

Hey Team,

I'm trying to paginate through all repos in my organization.
I've kept nextCursor as optional.
What will be the value for the afterCursor variable when the request is sent for the first time
I tried null but the response failed, and I tried empty string as well.

Thanks in advance!

 const response = await graphql({
        query: `query repositories ($owner: String!, $nextCursor: String) {
          organization(login:$owner) {
            repositories(first: 100, after: $nextCursor) {
              nodes {
                name
                id
                vulnerabilityAlerts {
                  totalCount
                }
              }
              pageInfo {
                startCursor
                hasNextPage
                endCursor
              }
            }
          }
        }`,
        owner: "my-org",
        nextCursor: nextCursor,
        headers: {
          authorization: `token ${token}`,
        },
      });
      repositories.push(response.data.organization.repositories.nodes);
      nextCursor = response.data.organization.repositories.pageInfo.endCursor
      hasNextPage = response.data.organization.repositories.pageInfo.hasNextPage
@ktikku ktikku changed the title Optional Parameters GitHub GraphQL cursor Pagination on first request Apr 5, 2022
@nickfloyd nickfloyd added the Type: Support Any questions, information, or general needs around the SDK or GitHub APIs label Jun 30, 2022
@tony
Copy link

tony commented Oct 12, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
None yet
Development

No branches or pull requests

3 participants