Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide a rhai interface to the router service (#3234)
Adds `Rhai` support for the `router_service`. It is now possible to interact with requests and responses at the `router_service` level from `Rhai`. The functionality is very similar to that provided for interacting with existing services, for example `supergraph_service`. For instance, you may map requests and responses as follows: ``` fn router_service(service) { const request_callback = Fn("process_request"); service.map_request(request_callback); const response_callback = Fn("process_response"); service.map_response(response_callback); } ``` The main difference from existing services is that the router_service is dealing with HTTP Bodies, not well formatted GraphQL objects. This means that the `Request.body` or `Response.body` is not a well structured object that you may interact with, but is simply a String. This makes it more complex to deal with Request and Response bodies with the tradeoff being that a script author has more power and can perform tasks which are just not possible within the confines of a well-formed GraphQL object. This simple example, simply logs the bodies: ``` // Generate a log for each request at this stage fn process_request(request) { print(`body: ${request.body}`); } // Generate a log for each response at this stage fn process_response(response) { print(`body: ${response.body}`); } ``` Fixes #2278 --------- Co-authored-by: Geoffroy Couprie <[email protected]> Co-authored-by: Bryn Cooke <[email protected]>
- Loading branch information