Skip to content

fix(proxy): route /api/graphql to correct upstream for GHE Cloud data residency#6861

Merged
lpcox merged 3 commits into
mainfrom
copilot/fix-difc-proxy-404
Jun 1, 2026
Merged

fix(proxy): route /api/graphql to correct upstream for GHE Cloud data residency#6861
lpcox merged 3 commits into
mainfrom
copilot/fix-difc-proxy-404

Conversation

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

forwardToGitHub() only handled two GraphQL upstream URL cases (github.com → /graphql, GHES → /api/graphql), causing a 404 for GHE Cloud data residency instances (e.g. copilot-api.sj.ghe.com) which have no /api/v3 suffix in githubAPIURL but expect /api/graphql on upstream.

Changes

  • internal/proxy/proxy.go — refine GraphQL routing so /api/graphql is preserved only for GHE Cloud data residency upstreams (copilot-api.*.ghe.com), while dotcom continues to normalize to /graphql:

    • GHES (.../api/v3) → /api/graphql
    • GHEC data residency (copilot-api.*.ghe.com) + inbound /api/graphql/api/graphql
    • otherwise (dotcom/default) → /graphql
    • normalize trailing slash (/api/graphql/) before matching
  • internal/proxy/forward_to_github_test.go — update TestForwardToGitHub_GraphQLPathRouting to:

    • simulate copilot-api.*.ghe.com host routing for data residency behavior
    • assert dotcom /api/graphql and /api/graphql/ normalize to /graphql
    • keep query-string preservation coverage
  • internal/proxy/proxy_test.go, internal/proxy/handler_test.go — restore dotcom expectations so inbound /api/graphql is normalized to /graphql (with query string preserved).

Copilot AI changed the title [WIP] Fix DIFC proxy returning 404 on GraphQL requests fix(proxy): route /api/graphql to correct upstream for GHE Cloud data residency Jun 1, 2026
Copilot finished work on behalf of lpcox June 1, 2026 17:24
Copilot AI requested a review from lpcox June 1, 2026 17:24
@lpcox lpcox marked this pull request as ready for review June 1, 2026 17:30
Copilot AI review requested due to automatic review settings June 1, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the proxy’s GraphQL upstream URL construction to support GHEC data residency API hosts (e.g. copilot-api.<tenant>.ghe.com) that don’t use an /api/v3 API base but still expect GraphQL at /api/graphql.

Changes:

  • Add a new GraphQL URL rewrite branch in forwardToGitHub() to handle /api/graphql on non-/api/v3 API bases.
  • Update/extend unit tests to reflect the new /api/graphql preservation behavior (including query string handling).
Show a summary per file
File Description
internal/proxy/proxy.go Adjusts GraphQL upstream URL rewrite logic to support GHEC data residency routing.
internal/proxy/forward_to_github_test.go Adds test cases for the new /api/graphql behavior.
internal/proxy/proxy_test.go Updates GraphQL rewrite expectations for non-/api/v3 API bases.
internal/proxy/handler_test.go Updates handler forwarding expectations for /api/graphql and query strings.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 4

Comment thread internal/proxy/proxy.go
Comment on lines 361 to +365
pathOnly, query, hasQuery := strings.Cut(path, "?")
if IsGraphQLPath(pathOnly) {
graphqlURL := s.githubAPIURL + "/graphql"
var graphqlURL string
if strings.HasSuffix(s.githubAPIURL, "/api/v3") {
// GHES: strip /api/v3, GraphQL lives at /api/graphql
Comment thread internal/proxy/proxy_test.go Outdated
Comment on lines +917 to +921
{name: "plain graphql endpoint", path: "/graphql", wantPath: "/graphql"},
{name: "ghes api graphql endpoint", path: "/api/graphql", wantPath: "/graphql"},
// /api/graphql is treated as GHE Cloud data residency — path is preserved, not normalised to /graphql.
{name: "ghes api graphql endpoint", path: "/api/graphql", wantPath: "/api/graphql"},
{name: "gh host prefixed graphql endpoint", path: "/api/v3/graphql", wantPath: "/graphql"},
{name: "graphql endpoint with query string", path: "/api/graphql?foo=bar", wantPath: "/graphql", wantQuery: "foo=bar"},
{name: "graphql endpoint with query string", path: "/api/graphql?foo=bar", wantPath: "/api/graphql", wantQuery: "foo=bar"},
Comment thread internal/proxy/handler_test.go Outdated
Comment on lines 238 to 242
// /api/graphql is treated as GHE Cloud data residency — path is preserved, not normalised to /graphql.
{name: "ghes api graphql path", path: "/api/graphql", wantPath: "/api/graphql"},
{name: "ghes api graphql path with query", path: "/api/graphql?foo=bar", wantPath: "/api/graphql?foo=bar"},
{name: "gh host prefixed graphql path", path: "/api/v3/graphql", wantPath: "/graphql"},
{name: "gh host prefixed graphql path with query", path: "/api/v3/graphql?foo=bar", wantPath: "/graphql?foo=bar"},
Comment on lines +188 to +192
{
// GHE Cloud data residency (e.g. copilot-api.sj.ghe.com) has no /api/v3
// suffix but the gh CLI sends GraphQL requests to /api/graphql.
// forwardToGitHub must forward to base/api/graphql, not base/graphql.
name: "GHE Cloud data residency api/graphql path routes to base/api/graphql",
@lpcox

lpcox commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Addressed in f3cf8e9. I tightened GraphQL routing so /api/graphql is preserved only for GHEC data residency hosts (copilot-api.*.ghe.com), restored dotcom normalization to /graphql, handled trailing-slash /api/graphql/, and updated the related proxy tests.

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.

[gateway] DIFC proxy returns 404 on /api/graphql for GHE Cloud data residency

3 participants