apollographql / router

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

Allow `router_service` Rhai interface to run before any other plugins #3923

Open lleadbet opened 1 year ago

lleadbet commented 1 year ago

Describe the solution you'd like

The current ordering behavior is not documented, but it appears the JWT plugin happens prior to the router_service Rhai stage, which is preventing some use-cases with using that plugin.

As an example, should I need to support multiple headers, I would ideally be able to do:

fn router_service(service){
    service.map_request(|request|{
        if request.headers.contains("authz") {
            request.headers["authorization"] = request.headers["authz"];
        }
    })
}

However this isn't respected, as JWT validation comes prior to Rhai. Ideally Rhai should come near the top of the ordering, only behind custom Rust plugins.

Describe alternatives you've considered

A coprocessor, which feels heavy for this type of work that Rhai is well-suited for.

Additional context

Other use-cases:

garypen commented 1 year ago

The ordering of plugins is documented here: https://www.apollographql.com/docs/router/customizations/native#request-and-response-lifecycle

It states that Rhai scripts should execute before any other plugins in any particular stage. If that isn't the case, there may be a bug.

lleadbet commented 10 months ago

Following up, this was discussed in Slack.