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
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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>— mirrorsContext::get.subgraph::Response::set_subgraph_request_id(&mut self, id: SubgraphRequestId)— infallible setter; field remainspub(crate).Two Rhai binding additions in
plugins/rhai/engine/mod.rs:router_context::context_remove— surfaces ascontext.remove(key)in Rhai.set_subgraph_id_response— surfaces asresponse.subgraph_request_id = "..."on subgraph mocks.Why
The mock subgraph
Responseexposed byapollo_mocks::get_subgraph_service_response()has a read-onlysubgraph_request_id, andContexthas no publicremove. This blocks unit testing of Rhai scripts that use the common correlation pattern (stash state keyed onsubgraph_request_idinrequest.context, pull and remove fromresponse.context).Scope and non-scope
request.subgraph_request_id— Router owns that field on the request side.Notes for reviewers
Context::removematchesinsert/upsertserde-failure semantics: iffrom_value::<V>fails on a present key, the originalserde_json_bytes::Valueis re-inserted under the same key before the error is returned, so callers that guess the wrongVdon't silently lose data.DashMap::removeand the re-insert. A concurrent writer whoinserts 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-routercargo test -p apollo-router --lib context::test::test_context_removecargo test -p apollo-router --lib context::test::test_context_remove_type_mismatchcargo test -p apollo-router --lib services::subgraph::tests::test_set_subgraph_request_idcargo test -p apollo-router --lib services::subgraph::tests::test_set_subgraph_request_id_empty_string_allowedcargo test -p apollo-router --libRelated
docs/superpowers/specs/2026-04-17-rhai-test-subgraph-request-id-context-remove-design.md(in productivity-dashboard repo)