Skip to content

fix(api): send GraphQL queries authenticated - #163

Open
ainformatico wants to merge 1 commit into
dlvhdr:mainfrom
ainformatico:fix/graphql-auth
Open

ainformatico wants to merge 1 commit into
dlvhdr:mainfrom
ainformatico:fix/graphql-auth

Conversation

@ainformatico

Copy link
Copy Markdown

Summary

getGraphQLClient now strips the configured API URL down to its hostname before passing it as ClientOptions.Host, so go-gh's host check no longer withholds the Authorization header (full analysis in the issue). Scheme-less hosts (e.g. localhost:3000 in tests) pass through unchanged.

Found while building on getGraphQLClient for a PR file "viewed" state integration; the anonymous queries it produced were a blocker for that work.

How Did You Test this Change?

  • New unit test TestGraphQLHost: default API URL, enterprise URL with path, scheme-less host, bare hostname.
  • Live: gh auth login without GH_TOKEN in the environment, then DEBUG=true LOG_LEVEL=debug diffnav --pr <url> — before: 403 rate-limit in debug.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.

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.
Sign up for free to 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.

[BUG] --pr mode sends GraphQL requests unauthenticated (403 rate limit) with hosts.yml auth

1 participant