Fix GetTeams pagination: workspaces with >50 teams silently lose teams beyond page 1 - #72
Open
TheRealAlexV wants to merge 1 commit into
Open
Fix GetTeams pagination: workspaces with >50 teams silently lose teams beyond page 1#72TheRealAlexV wants to merge 1 commit into
TheRealAlexV wants to merge 1 commit into
Conversation
…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
This file contains hidden or 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
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GetTeams()inpkg/linear/teams/client.goissues an unpaginatedteams { 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)andresolver.go'sResolveTeam()both callGetTeams()internally, this doesn't just truncateteams listoutput — it breaks team resolution by key/name for any team outside the first page.--team <key>andteams 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 }) toGetTeams(), looping until all pages are fetched. This follows the exact same pattern already used byListUsersWithPaginationelsewhere 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
hasNextPageis 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 {...} }), andprojects/client.go's list methods accept a caller-suppliedfirstbut 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 ./...andgo build -o linear-patched ./cmd/linearboth succeedgo vet ./...is cleango 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 cursorTestGetTeams_SinglePage: asserts the single-page case still makes exactly 1 request (no behavior change for the common case)main: one pre-existing, unrelated test failure inpkg/linear/client_test.go(TestNewClientWithTokenPath_ReturnsNilWhenNoToken) reproduces identically on both branches — it's environment-based (aLINEAR_API_KEY-like var present in the test environment), not a regression from this change.