Route /api/graphql by X-GitLab-Organization-ID header

What does this MR do and why?

Adds path-based routing for the /api/graphql endpoint, keyed on the X-GitLab-Organization-ID request header.

The GraphQL endpoint is a single path with no routing key in the URL, but the organization can be delivered in the X-GitLab-Organization-ID header:

https://docs.gitlab.com/development/organization/#rest-api-and-graphql-requests

Screenshot_2026-08-27_at_4.36.38_PM

This mirrors the existing header-claim precedent for the Jira Forge integration (X-Gitlab-Jira-Cloud-Id).

How it works:

  • A request to /api/graphql with X-GitLab-Organization-ID: <id> is parsed into an organization_id claim and classified to the owning cell via Topology Service.
  • If the header is absent, its value isn't a valid integer, or the claim can't be resolved, the handler falls back to the JSON rule engine (session/token routing). This makes the change purely additive — existing GraphQL traffic is unaffected.

The organization_id claim, its parser, and Topology Service support already exist (same claim used by the OAuth-callback query-param route), so no new plumbing was needed. The route entry sits above the /api/* glob so it isn't swallowed.

Changes:

  • src/routes.ts — new header-claim route for /api/graphql in backlog, above /api/*.
  • test/handlers/claim_path_handler.spec.ts — new cases for the header-present (happy path) and header-absent (fallback) scenarios. Also fixes the local mockClassify helper to serialize BigInt claims with replaceBigInt, matching the wire format the client produces (the existing header test only used a string cloud_id, so it never exercised this).
  • test/routes/routes.spec.ts + snapshot — hand-authored assertion pinning /api/graphql to its own template so a reorder letting /api/* swallow it fails loudly; snapshot updated accordingly.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

gitlab-com/gl-infra/tenant-scale/cells-infrastructure#10 (closed)

How to set up and validate locally

  1. Check out this branch and run the test suite: npm test (340 tests, all passing).
  2. Verify that gdk/gitlab-topology-service is running on port 9096
  3. Run the router locally with:
npx wrangler dev -e dev \
  --var "GITLAB_RULES_CONFIG:session_prefix" \
  --var "GITLAB_PROXY_HOST:gdk.test:3000" \
  --var "GITLAB_TOPOLOGY_SERVICE_URL:http://gdk.test:9096" \
  --var "GITLAB_PATH_BASED_ROUTING_MODE:full" \
  --port 8799
  1. Tail gdk/gitlab-topology-service with gdk tail gitlab-topology-service
  2. Send a GraphQL request with the org header and verify Topology Service got a Classify request with claim_type "organization_id" and claim_value "12345":
curl -i -X POST http://localhost:8799/api/graphql -H 'X-GitLab-Organization-ID: 12345' -H 'Content-Type: application/json' -d '{"query":"{__typename}"}'
  1. Send the same request without the header and confirm it falls back to session/token routing (unchanged behavior).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Sangwoo Han

Merge request reports

Loading
Loading