Skip to content

Fix GetTeams pagination: workspaces with >50 teams silently lose teams beyond page 1 - #72

Open
TheRealAlexV wants to merge 1 commit into
joa23:mainfrom
TheRealAlexV:fix/teams-pagination-issue-71
Open

Fix GetTeams pagination: workspaces with >50 teams silently lose teams beyond page 1#72
TheRealAlexV wants to merge 1 commit into
joa23:mainfrom
TheRealAlexV:fix/teams-pagination-issue-71

Conversation

@TheRealAlexV

Copy link
Copy Markdown

Problem

GetTeams() in pkg/linear/teams/client.go issues an unpaginated teams { nodes {...} } GraphQL query. Linear's API returns its default connection page size (50) for unpaginated queries, so workspaces with more than 50 teams silently lose everything past page 1.

Since GetTeam(keyOrName) and resolver.go's ResolveTeam() both call GetTeams() internally, this doesn't just truncate teams list output — it breaks team resolution by key/name for any team outside the first page. --team <key> and teams get <key-or-id> fail with "team not found" even when passed a team's exact, correct UUID, if that team happens to be outside the first 50 returned.

Closes#71.

Fix

Adds cursor-based pagination (first/after + pageInfo { hasNextPage endCursor }) to GetTeams(), looping until all pages are fetched. This follows the exact same pattern already used by ListUsersWithPagination elsewhere in the same file, so it's consistent with the codebase's existing conventions rather than introducing a new one.

No codegen/genqlient involved — this is a hand-written GraphQL query, so the query string itself is edited directly.

Single-page workspaces (the common case) are unaffected: exactly one request is still made, since the loop exits immediately when hasNextPage is false.

Scope

Only GetTeams() is fixed here, since that's what #71 reports. ListLabels(teamID) in the same file has an identical unpaginated-connection pattern (team.labels { nodes {...} }), and projects/client.go's list methods accept a caller-supplied first but don't loop pages either — both are the same class of bug but are left out of scope for this PR to keep the change minimal and reviewable. Happy to follow up with a separate PR for those if useful.

Testing

  • go build ./... and go build -o linear-patched ./cmd/linear both succeed
  • go vet ./... is clean
  • go test ./pkg/linear/teams/... passes, including two new regression tests:
    • TestGetTeams_PaginatesAcrossMultiplePages: mocks a 2-page response, asserts all teams across both pages are returned, exactly 2 HTTP calls are made, and the second request carries the correct cursor
    • TestGetTeams_SinglePage: asserts the single-page case still makes exactly 1 request (no behavior change for the common case)
  • Compared against unmodified main: one pre-existing, unrelated test failure in pkg/linear/client_test.go (TestNewClientWithTokenPath_ReturnsNilWhenNoToken) reproduces identically on both branches — it's environment-based (a LINEAR_API_KEY-like var present in the test environment), not a regression from this change.

…s beyond page 1
Adds cursor-based pagination (first/after + pageInfo.hasNextPage/endCursor)
to the GetTeams GraphQL query, following the same pattern already used by
ListUsersWithPagination in the same file. Without this, teams list, teams
get <key>, and --team <key> resolution all silently fail for any team
outside the first 50 returned by Linear's default connection page size.
Includes regression tests verifying multi-page pagination and that
single-page workspaces still make exactly one request.
Fixesjoa23#71
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

teams list / team resolution hard-caps at 50, no pagination — teams beyond page 1 are completely unreachable

1 participant

@TheRealAlexV