Skip to content

[HYPER-74] fix: use relative paths in GraphiQL to support multiple domains#31

Open
aspiers wants to merge 1 commit intomainfrom
url-fix
Open

[HYPER-74] fix: use relative paths in GraphiQL to support multiple domains#31
aspiers wants to merge 1 commit intomainfrom
url-fix

Conversation

@aspiers
Copy link
Contributor

@aspiers aspiers commented Feb 12, 2026

Summary

  • GraphiQL was hardcoding the GraphQL endpoint URL using EXTERNAL_BASE_URL, which defaulted to http://0.0.0.0:8080 when unset — causing "Failed to fetch" errors in the browser
  • Switched to using location.origin in JavaScript so the URL is derived from the browser's address bar at runtime
  • WebSocket subscription URL similarly derived using location.protocol and location.host

This makes GraphiQL work correctly regardless of which domain it's accessed through (e.g. hi.test.certified.app via Vercel proxy or hyperindex.test.certified.app directly on Railway).

Also set EXTERNAL_BASE_URL=https://hyperindex.test.certified.app on Railway for OAuth and other features that still need a canonical URL.

Without this patch, GraphiQL endpoints were configured with absolute
URLs constructed from ExternalBaseURL. This caused GraphiQL to fail
when the service was accessed through a different domain (e.g., via
proxy, load balancer, or alternate hostname) because it would always
try to connect to the configured base URL rather than the domain the
user was actually using.

This is a problem because it prevents GraphiQL from working in
multi-domain deployments and makes local development harder when
accessing the service through different hostnames.

This patch solves the problem by changing GraphiQLConfig to accept
relative paths (EndpointPath and SubscriptionPath) instead of absolute
URLs. The GraphiQL HTML template now uses JavaScript to dynamically
construct the full URLs from window.location at runtime, ensuring the
page always connects to the correct domain. The WebSocket protocol is
also derived dynamically (ws: for http:, wss: for https:).

Changes:
- Replace Endpoint/SubscriptionEndpoint with EndpointPath/SubscriptionPath
- Use window.location.origin to build full GraphQL URL at runtime
- Derive WebSocket protocol from page protocol dynamically
- Update tests to verify path-based configuration

Co-authored-by: Claude Code <claude-code@noreply.anthropic.com>
@vercel
Copy link

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperindex Ready Ready Preview, Comment Feb 12, 2026 10:38am

Request Review

@railway-app
Copy link

railway-app bot commented Feb 12, 2026

🚅 Environment hyperindex-pr-31 in hypercerts has no services deployed.

4 services not affected by this PR
  • PDS entryway
  • sds-eu-west4
  • pds-eu-west4
  • pds1

@aspiers aspiers requested a review from daviddao February 12, 2026 10:54
@aspiers aspiers changed the title fix: use relative paths in GraphiQL to support multiple domains [HYPER-74] fix: use relative paths in GraphiQL to support multiple domains Feb 12, 2026
@linear
Copy link

linear bot commented Feb 12, 2026

HYPER-74 hyperindex has just broken again

{
  "errors": [
    {
      "message": "Failed to fetch",
      "stack": "TypeError: Failed to fetch\n    at https://unpkg.com/graphiql@3/graphiql.min.js:45:432829\n    at https://unpkg.com/graphiql@3/graphiql.min.js:45:433106\n    at https://unpkg.com/graphiql@3/graphiql.min.js:45:342227\n    at k (https://unpkg.com/graphiql@3/graphiql.min.js:45:342657)\n    at _ (https://unpkg.com/graphiql@3/graphiql.min.js:45:342902)\n    at Id (https://unpkg.com/react-dom@18/umd/react-dom.production.min.js:165:137)\n    at Xb (https://unpkg.com/react-dom@18/umd/react-dom.production.min.js:200:284)\n    at Li (https://unpkg.com/react-dom@18/umd/react-dom.production.min.js:189:119)\n    at db (https://unpkg.com/react-dom@18/umd/react-dom.production.min.js:79:182)\n    at Rk (https://unpkg.com/react-dom@18/umd/react-dom.production.min.js:198:175)"
    }
  ]
}

Copy link
Contributor

@daviddao daviddao left a comment

Choose a reason for hiding this comment

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

Looks great!

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.

2 participants