Skip to content

Commit f95d9e0

Browse files
lpcoxCopilot
andcommitted
fix: recognize /api/graphql path in proxy for GHES-style gh CLI
When gh CLI uses GH_HOST for proxy mode, it sends GraphQL requests to /api/graphql (GHES-style) instead of /api/v3/graphql. The proxy only recognized /graphql and /api/v3/graphql, causing the GraphQL POST to fall through to passthrough which forwarded it to https://api.github.com/api/graphql (404) instead of /graphql. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c80f390 commit f95d9e0

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

internal/proxy/graphql.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ func extractOwnerRepo(variables map[string]interface{}, query string) (string, s
170170
}
171171

172172
// IsGraphQLPath returns true if the request path is the GraphQL endpoint.
173+
// Accepts /graphql (after prefix strip), /api/v3/graphql (before strip),
174+
// and /api/graphql (GHES-style path used by gh CLI with GH_HOST).
173175
func IsGraphQLPath(path string) bool {
174176
cleaned := strings.TrimSuffix(path, "/")
175-
return cleaned == "/graphql" || cleaned == "/api/v3/graphql"
177+
return cleaned == "/graphql" || cleaned == "/api/v3/graphql" || cleaned == "/api/graphql"
176178
}

internal/proxy/proxy_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ func TestIsGraphQLPath(t *testing.T) {
492492
assert.True(t, IsGraphQLPath("/graphql/"))
493493
assert.True(t, IsGraphQLPath("/api/v3/graphql"))
494494
assert.True(t, IsGraphQLPath("/api/v3/graphql/"))
495+
assert.True(t, IsGraphQLPath("/api/graphql"))
496+
assert.True(t, IsGraphQLPath("/api/graphql/"))
495497
assert.False(t, IsGraphQLPath("/repos/org/repo"))
496498
assert.False(t, IsGraphQLPath("/user"))
497499
}

0 commit comments

Comments
 (0)