Skip to content

fix: route app.graph + .ctx.graph to sovereign endpoints via cloud.graphScope#538

Merged
corinagum merged 4 commits intomainfrom
cg/graph-cloud-baseurl
Apr 27, 2026
Merged

fix: route app.graph + .ctx.graph to sovereign endpoints via cloud.graphScope#538
corinagum merged 4 commits intomainfrom
cg/graph-cloud-baseurl

Conversation

@corinagum
Copy link
Copy Markdown
Collaborator

  • app.graph was routing all Microsoft Graph calls to the public-cloud endpoint (https://graph.microsoft.com) regardless of the sovereign cloud configured on the app. Sovereign customers (GCCH, DoD, China) would be unable to use

  • app.graph - calls would hit the wrong cloud and fail. This PR fixes that by deriving the Graph base URL from the cloud's graphScope and plumbing it through GraphClient.

  • Public cloud (default): graphScope = "https://graph.microsoft.com/.default" → derived base URL = https://graph.microsoft.com = previous hardcoded default. Zero behavior change.

  • Sovereign clouds: behavior changes from broken (silently public) to correct (per-cloud). This is the fix.

Copilot AI review requested due to automatic review settings April 22, 2026 21:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes sovereign cloud support for Microsoft Graph by ensuring app.graph can target the correct Graph cloud endpoint instead of always using https://graph.microsoft.com.

Changes:

  • Extend @microsoft/teams.graph Client to accept an explicit Graph service root (baseUrlRoot) when cloning from an existing HTTP client.
  • Derive Graph base URL from the configured cloud’s graphScope in App and pass it into GraphClient.
  • Add unit tests covering the new positional baseUrlRoot behavior in the Graph client constructor.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/graph/src/index.ts Adds positional baseUrlRoot support and updates base URL selection logic.
packages/graph/src/index.spec.ts Adds tests validating sovereign base URL routing via the new constructor parameter.
packages/apps/src/app.ts Derives Graph base URL from cloud.graphScope and wires it into this.graph.
package-lock.json Lockfile updates (workspace dependency metadata refresh).

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

Comment thread packages/apps/src/app.ts Outdated
Comment thread packages/graph/src/index.ts Outdated
Comment thread packages/apps/src/app.ts Outdated
Comment thread packages/apps/src/app.ts
corinagum added a commit that referenced this pull request Apr 22, 2026
…loud.graphScope

Address Copilot review feedback on #538:

- graph: simplify baseUrlRoot resolution to `baseUrlRoot ?? options?.baseUrlRoot ?? default`;
  restores honoring options.baseUrlRoot on the http.Client branch (subtle backward-compat fix).
- apps: store derived graphBaseUrl as a readonly App field; thread it into userGraph and
  appGraph instantiations in app.process.ts so per-activity Graph clients also route
  sovereign-correctly. Log a warning when a non-empty graphScope doesn't parse as a URL.
- tests: add App-level tests (PUBLIC / US_GOV / US_GOV_DOD / CHINA / non-URL scope) verifying
  graphBaseUrl derivation; add graph tests for positional-vs-options precedence and the
  attached-baseUrlRoot-on-http.Client backward-compat path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread packages/graph/src/index.ts Outdated
@corinagum corinagum changed the title fix: route app.graph to sovereign endpoints via cloud.graphScope fix: route app.graph + .ctx.graph to sovereign endpoints via cloud.graphScope Apr 23, 2026
corinagum and others added 4 commits April 24, 2026 16:33
…loud.graphScope

Address Copilot review feedback on #538:

- graph: simplify baseUrlRoot resolution to `baseUrlRoot ?? options?.baseUrlRoot ?? default`;
  restores honoring options.baseUrlRoot on the http.Client branch (subtle backward-compat fix).
- apps: store derived graphBaseUrl as a readonly App field; thread it into userGraph and
  appGraph instantiations in app.process.ts so per-activity Graph clients also route
  sovereign-correctly. Log a warning when a non-empty graphScope doesn't parse as a URL.
- tests: add App-level tests (PUBLIC / US_GOV / US_GOV_DOD / CHINA / non-URL scope) verifying
  graphBaseUrl derivation; add graph tests for positional-vs-options precedence and the
  attached-baseUrlRoot-on-http.Client backward-compat path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Missed in the previous commit: the onTokenExchange and onVerifyState
handlers construct ctx.userGraph independently of app.process.ts. Both
now receive this.graphBaseUrl so sovereign cloud OAuth flows route to
the correct Graph endpoint.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.


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

Comment thread packages/apps/src/app.ts
@corinagum corinagum merged commit 407b167 into main Apr 27, 2026
11 checks passed
@corinagum corinagum deleted the cg/graph-cloud-baseurl branch April 27, 2026 17:32
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.

3 participants