Skip to content

feat: expose writable subgraph_request_id and Context::remove for rhai-test (AS-389)#1

Open
andywgarcia wants to merge 12 commits intofeature/rhaitest-v2.12.0from
as-389/writable-subgraph-request-id-and-context-remove
Open

feat: expose writable subgraph_request_id and Context::remove for rhai-test (AS-389)#1
andywgarcia wants to merge 12 commits intofeature/rhaitest-v2.12.0from
as-389/writable-subgraph-request-id-and-context-remove

Conversation

@andywgarcia
Copy link
Copy Markdown
Collaborator

Summary

Additive, test-enabling patches to the rhai-test fork line. Unblocks AS-389, requested by Indeed via TSH-22538.

Two Rust additions:

  • Context::remove<K, V>(&self, key: K) -> Result<Option<V>, BoxError> — mirrors Context::get.
  • subgraph::Response::set_subgraph_request_id(&mut self, id: SubgraphRequestId) — infallible setter; field remains pub(crate).

Two Rhai binding additions in plugins/rhai/engine/mod.rs:

  • router_context::context_remove — surfaces as context.remove(key) in Rhai.
  • set_subgraph_id_response — surfaces as response.subgraph_request_id = "..." on subgraph mocks.

Why

The mock subgraph Response exposed by apollo_mocks::get_subgraph_service_response() has a read-only subgraph_request_id, and Context has no public remove. This blocks unit testing of Rhai scripts that use the common correlation pattern (stash state keyed on subgraph_request_id in request.context, pull and remove from response.context).

Scope and non-scope

  • No production routing behavior change.
  • No changes to constructors, builders, field visibility, or any production call site.
  • No setter for request.subgraph_request_id — Router owns that field on the request side.

Notes for reviewers

  • Context::remove matches insert / upsert serde-failure semantics: if from_value::<V> fails on a present key, the original serde_json_bytes::Value is re-inserted under the same key before the error is returned, so callers that guess the wrong V don't silently lose data.
  • That restore path has a brief non-atomicity window between the DashMap::remove and the re-insert. A concurrent writer who inserts a newer value under the same key during that window will have their write overwritten by our restore. Acceptable for this test-oriented fork; flagging for awareness if any of this ever heads upstream.

Test plan

  • cargo build -p apollo-router
  • cargo test -p apollo-router --lib context::test::test_context_remove
  • cargo test -p apollo-router --lib context::test::test_context_remove_type_mismatch
  • cargo test -p apollo-router --lib services::subgraph::tests::test_set_subgraph_request_id
  • cargo test -p apollo-router --lib services::subgraph::tests::test_set_subgraph_request_id_empty_string_allowed
  • Full lib suite passes: cargo test -p apollo-router --lib

Related

  • AS-389
  • TSH-22538
  • Design: docs/superpowers/specs/2026-04-17-rhai-test-subgraph-request-id-context-remove-design.md (in productivity-dashboard repo)

andywgarcia and others added 11 commits April 17, 2026 11:23
- Drop overclaimed concurrency comment; describe behavior like insert/upsert
- Preserve entry on serde deserialize failure (re-insert original JSON value)
- Strengthen type-mismatch test to assert entry preservation
The type lives at crate::services::subgraph::SubgraphRequestId,
not crate::services::SubgraphRequestId. Compiler caught it in CI.
Disable built-in caching for Rust toolchain setup.
Added a step to install system dependencies for the workflow.
@andywgarcia andywgarcia self-assigned this Apr 17, 2026
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.

1 participant