Skip to content

Rename example functions to use Router callback hook names#15

Open
andywgarcia wants to merge 7 commits intomainfrom
fix/examples-use-router-callbacks
Open

Rename example functions to use Router callback hook names#15
andywgarcia wants to merge 7 commits intomainfrom
fix/examples-use-router-callbacks

Conversation

@andywgarcia
Copy link
Copy Markdown
Contributor

Summary

Addresses PR #14 review feedback noting that client_id.rhai and headers.rhai use arbitrary function names that don't match Router's Rhai hook entry points, making them misleading as copy-paste starting points.

  • client_id.rhai: Renamed fn process_request(request) to fn supergraph_request(request) — this script validates apollographql-client-* headers on the incoming supergraph request, which is exactly what the supergraph_request hook does in Router.
  • headers.rhai: Renamed fn rename_header(request) to fn subgraph_request(request) — this script copies supergraph headers into subgraph request headers, which maps to the subgraph_request hook stage.
  • Updated all corresponding test files to call the new function names.

All 96 tests pass across 18 test suites.

Test plan

  • cargo build --release succeeds
  • All example tests pass (rhai-test from examples/ directory)
  • Verify examples still make sense as documentation for Router Rhai scripting

Made with Cursor

andywgarcia and others added 7 commits March 24, 2026 16:09
- Bumps rhai from 1.17.1 to 1.23.6 to match the version bundled in
  Apollo Router v2.12.0. This eliminates false-negative test failures
  caused by version skew between rhai-test and the Router.
- Adds a "Rhai Version Policy" section to the README documenting the
  expectation that rhai-test tracks the Rhai version in the latest
  stable Router release.
The transitive dependency deno-proc-macro-rules v0.3.2 (via
apollo-router -> router-bridge -> deno_core -> deno_ops) was yanked
from crates.io. Add [patch.crates-io] entries pointing both
deno-proc-macro-rules and deno-proc-macro-rules-macros to the
canonical source at denoland/deno-proc-macro-rules.

All 26 tests pass with this fix.
Replace the andrewmcgivery/router fork (v1.57.1, broken by yanked
deno-proc-macro-rules) with a new fork at apollosolutions/router
based on the official v2.12.0 tag. The new fork applies the same
pattern — exposing rhai plugin internals via _private::rhai.

Changes to rhai-test:
- Point apollo-router dependency to apollosolutions/router
  branch feature/rhaitest-v2.12.0
- Bump http dependency from 0.2 to 1 (matching Router v2.12.0)
- Add parking_lot dependency (v2.12.0 uses parking_lot::Mutex
  instead of std::sync::Mutex for SharedMut)
- Remove [patch.crates-io] workaround (no longer needed)
- Replace register_rhai_interface!/register_rhai_router_interface!
  macro calls with registration::register() (v2.12.0 refactored
  macros into a registration module)
- Update apollo_mocks to use parking_lot::Mutex
- Clean up unused imports
- Updated README to clarify installation instructions, including how to install specific versions and build from source.
- Added new examples demonstrating request and response handling in Rhai scripts, including:
  - `execution_propagation.rhai`: Propagates tenant headers in requests.
  - `router_tracing.rhai`: Injects request IDs for tracing.
  - `subgraph_response_enrichment.rhai`: Tags responses with processing markers.
- Introduced tests for the new examples to ensure functionality and logging behavior.
- Enhanced the `expect` functionality to support HTTP headers in the engine's expector.
- Enhanced installation section to clarify how to install from GitHub Releases, including setting the `VERSION` for specific releases and confirming the CLI is on the `PATH`.
- Added a new section for maintainers detailing the manual release process, including steps for using GitHub Actions to publish releases and update the installer script.
- Included instructions for running tests with a minimal config file example.
client_id.rhai and headers.rhai used arbitrary function names
(process_request, rename_header) that don't match Router's Rhai
hook entry points, making them misleading as examples. Renamed to
supergraph_request and subgraph_request respectively so they
accurately represent how Router would invoke them.

Made-with: Cursor
@andywgarcia andywgarcia requested review from a team as code owners April 2, 2026 19:03
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