Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

Nested pagination to get teams and the team members details

I want to get all the teams of an organization and members of those teams and iam trying to call the below query recursively by using nested pagination like below. But not sure how can i pass the multple team member endCursors at a time.  Is this a correct approach at all ?

 

{
viewer {
login
organization(login: $orgName) {
name
teams(first:5, after: $team_endCursor) {
totalCount
pageInfo {
hasNextPage
endCursor
}
teamDetails: nodes {
name
members(first:5,  after: $member_endCursor) {
totalCount
memberDetails: nodes {
login
name
}
pageInfo {
hasNextPage
endCursor
}
}
childTeams(first: 10) {
nodes {
name
}
}
}
}

}
}
}

1 Reply
Highlighted
Community Manager
Message 2 of 2

Re: Nested pagination to get teams and the team members details

You could do something like you're describing like this:

 

query($orgName: String!, $teamCursor: String, $memberCursor: String) {
  viewer {
    login
    organization(login: $orgName) {
      name
      teams(first: 100, after: $teamCursor) {
        totalCount
        pageInfo {
          hasNextPage
          endCursor
        }
        teamDetails: nodes {
          name
          members(first: 100, after: $memberCursor) {
            totalCount
            memberDetails: nodes {
              login
              name
            }
            pageInfo {
              hasNextPage
              endCursor
            }
          }
          childTeams(first: 10) {
            nodes {
              name
            }
          }
        }
      }
    }
  }
}

And supply it with variables like:

 

{
  "orgName": "whatever-org-name",
  "teamCursor": null,
  "memberCursor": null
}

But then if any one of those teams' member lists were longer than 100, you would have to supply a memberCursor value to the second iteration of the query. When you did this, 99% of the data in the second result would be identical to the first result. So at that point, it may just be easier to get the list of teams and their child teams in one query, then go back and get the teams' memberships in another?

 

Let us know if you have more questions.