Repository navigation
fix(api): send GraphQL queries authenticated - #163
Open
ainformatico wants to merge 1 commit into
Open
ainformatico wants to merge 1 commit into
ainformatico wants to merge 1 commit into
Conversation
getGraphQLClient passed the API URL (https://api.github.com) as ClientOptions.Host, but go-gh expects a bare hostname. When the configured host doesn't match the request host, go-gh omits the Authorization header (to avoid leaking tokens to arbitrary hosts), so every GraphQL query went out anonymous and hit the 60 req/h rate limit instead of the authenticated 5000/h. This broke --pr mode for anyone relying on gh's hosts.yml auth (no GH_TOKEN/GITHUB_TOKEN in the environment). Fix: strip the URL down to its hostname before passing it to go-gh; scheme-less hosts (e.g. localhost:3000 in tests) pass through unchanged.
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 free
to 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.
Summary
getGraphQLClientnow strips the configured API URL down to its hostname before passing it asClientOptions.Host, so go-gh's host check no longer withholds the Authorization header (full analysis in the issue). Scheme-less hosts (e.g.localhost:3000in tests) pass through unchanged.Found while building on
getGraphQLClientfor a PR file "viewed" state integration; the anonymous queries it produced were a blocker for that work.How Did You Test this Change?
TestGraphQLHost: default API URL, enterprise URL with path, scheme-less host, bare hostname.gh auth loginwithoutGH_TOKENin the environment, thenDEBUG=true LOG_LEVEL=debug diffnav --pr <url>— before: 403 rate-limit indebug.log; after: PR + review comments load over an authenticated query.Images/Videos
n/a
AI disclosure: prepared with AI assistance (OpenCode / GLM) — root-cause analysis and initial patch draft. Reviewed, tested, and understood by the author.