apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
791 stars 261 forks source link

define request and response body access at the router service level for rhai #3642

Open Geal opened 1 year ago

Geal commented 1 year ago

in https://github.com/apollographql/router/pull/3234 we provided a way to access Router service level requests and responses. At this step, the body is a stream of byte chunks, with no real guarantee about the format:

Due to these issues, we do not give access to the body, until we can provide a good API to manipulate it

garypen commented 9 months ago

Rhai has a first class type for representing bytes: https://rhai.rs/book/ref/blobs.html

We could leverage this to think about a progressive representation such that:

First

We could provide a basic interface which provides a rhai callback function a Blob each time it is received in the router.

At this time, anyone wanting to manipulate this data from a Rhai script would be restricted to the features provided by the Blob.

Second

We could provide some utility functions which provide some common functionality for manipulating Blobs. e.g.: try to convert to JSON, try to convert to multipart, etc...

Some questions/observations:

It feels like this might be a good approach for at least starting to explore the problem.