Skip to content

refac(internal/github): single graphql query to fetch all SSH keys at once - #723

Open
gnarlex wants to merge 2 commits into
mainfrom
bootstrap-ssh-graphql
Open

refac(internal/github): single graphql query to fetch all SSH keys at once#723
gnarlex wants to merge 2 commits into
mainfrom
bootstrap-ssh-graphql

Conversation

@gnarlex

@gnarlex gnarlex commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

We are making 1 list request to get all members of a team, and 1 get request for each member's ssh key. For large team's, this results in a lot of requests being made, which may quickly contribute to hitting GitHub API rate limits,

Make a single GraphQL query to get all keys at once.

@gnarlex gnarlex self-assigned this Aug 21, 2026

@OliverTrautvetter OliverTrautvetter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general, some small stuff

Comment on lines +99 to +118
return nil, err
}

team := resp.Data.Organization.Team
for _, node := range team.Members.Nodes {
keys := make([]string, 0, len(node.PublicKeys.Nodes))
for _, k := range node.PublicKeys.Nodes {
keys = append(keys, k.Key)
}
members = append(members, TeamMemberKeys{Login: node.Login, Keys: keys})
}

if !team.Members.PageInfo.HasNextPage {
break
}
cursor := team.Members.PageInfo.EndCursor
after = &cursor
}

return members, nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this silently succeed with 0 keys if the team/org is misconfigured? Before it was a hard 404 error, now it would be (nil, nil)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

404 is not what I would expect from a list members endpoint. If the team/org exists, but has no members, it should return an empty list (nil or empty slice usually have the same behavior, but can return an empty slice if that's preferred) and not return an error. If the caller considers the empty list an error, it's the caller's responsibility to flag this to their user (via error or warning log).

Or am I missing an unhandled error somewhere?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that, I just wanted to know if that was an intentional change

Comment on lines +98 to +100
if err != nil {
return nil, err
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drops previously fetched members. We could return the partial results if an error happens.

If partial results are usable?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning a partial result risks giving a false sense of "it worked". Returning all or nothing is IMHO safer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine for me

Comment thread internal/github/github_client.go Outdated
pageInfo { hasNextPage endCursor }
nodes {
login
publicKeys(first: 20) { nodes { key } }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently only the first 20. We should at least log that it is truncated and keys not just vanish silently

Comment thread internal/github/github_client.go
Comment thread internal/github/github_client.go
@gnarlex
gnarlex force-pushed the bootstrap-ssh-graphql branch from c159061 to 6d58245 Compare August 21, 2026 15:15

@OliverTrautvetter OliverTrautvetter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants