Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide a rhai interface to the router service #3234

Merged
merged 29 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1b37293
First compiling version with working requests
garypen Jun 6, 2023
cbaa181
finish implementing router_service rhai support
garypen Jun 7, 2023
650869d
rename the json encoding/decoding functions
garypen Jun 7, 2023
7d0a29b
Merge branch 'dev' into garypen/2278-rhai-router-service
garypen Jun 7, 2023
a0711ae
cargo fmt
garypen Jun 7, 2023
e2b6809
Merge branch 'dev' into garypen/2278-rhai-router-service
garypen Jun 14, 2023
48715f1
add minimal documentation and expect() less
garypen Jun 14, 2023
6dc7ab0
add a changeset
garypen Jun 15, 2023
416e5f3
add documentation for json encoding/decoding to changeset
garypen Jun 15, 2023
615019b
add documentation for json coding functions
garypen Jun 15, 2023
5fa868c
expect less in our bridge to the async world
garypen Jun 15, 2023
2a2a26c
add router_service into all rhai callback test
garypen Jun 15, 2023
b0d46ab
Merge branch 'dev' into garypen/2278-rhai-router-service
garypen Jun 15, 2023
985fa5c
Merge branch 'dev' into garypen/2278-rhai-router-service
garypen Jun 15, 2023
b3b3475
update documentation to include router_service details
garypen Jun 15, 2023
13d3658
code review comments
garypen Jun 21, 2023
d480a3c
Merge branch 'dev' into garypen/2278-rhai-router-service
garypen Jun 21, 2023
9ef2fb3
Merge branch 'dev' into garypen/2278-rhai-router-service
Geal Aug 11, 2023
7cc3889
work on streams of Bytes for router requests
Geal Aug 14, 2023
f52f7a5
lint and fix API
Geal Aug 14, 2023
412e77e
Simplify rhai macros (#3569)
Geal Aug 22, 2023
9cd29ec
Merge branch 'dev' into garypen/2278-rhai-router-service
Geal Aug 22, 2023
84a3e02
deactivate body access
Geal Aug 22, 2023
89ac69a
fix docs
Geal Aug 22, 2023
d9839a6
Merge branch 'dev' into garypen/2278-rhai-router-service
Geal Aug 23, 2023
259f0da
Merge branch 'dev' into garypen/2278-rhai-router-service
Geal Aug 29, 2023
4a0a7f9
Merge branch 'dev' into garypen/2278-rhai-router-service
Geal Aug 30, 2023
4577bfa
Apply suggestions from code review
Geal Sep 5, 2023
46d4370
Merge branch 'dev' into garypen/2278-rhai-router-service
Geal Sep 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .changesets/feat_garypen_2278_rhai_router_service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
### Provide a rhai interface to the router service ([Issue #2278](https://github.com/apollographql/router/issues/2278))

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:

```json
Geal marked this conversation as resolved.
Show resolved Hide resolved
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.
Geal marked this conversation as resolved.
Show resolved Hide resolved

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:

```json
Geal marked this conversation as resolved.
Show resolved Hide resolved
// 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}`);
}
```

This PR also introduces two new Rhai functions:

```json
Geal marked this conversation as resolved.
Show resolved Hide resolved
json_encode(Object)
json_decode(String) -> Object

```
Which will respectively encode a `Rhai` Object or decode a JSON string into a `Rhai` Object. These functions may be helpful when dealing with String bodies which represent encoded JSON objects.

By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/3234
Loading