diff --git a/generated/.tailcallrc.graphql b/generated/.tailcallrc.graphql index d41a58121e1..1aab62f488e 100644 --- a/generated/.tailcallrc.graphql +++ b/generated/.tailcallrc.graphql @@ -120,6 +120,12 @@ directive @grpc( This refers to the gRPC method you're going to call. For instance `GetAllNews`. """ method: String! + """ + Specifies a JavaScript function to be executed after receiving the response body. + This function can modify or transform the response body before it's sent back to + the client. + """ + onResponseBody: String ) on FIELD_DEFINITION """ @@ -173,6 +179,12 @@ directive @http( """ onRequest: String """ + Specifies a JavaScript function to be executed after receiving the response body. + This function can modify or transform the response body before it's sent back to + the client. + """ + onResponseBody: String + """ Schema of the output of the API call. It is automatically inferred in most cases. """ output: Schema @@ -774,6 +786,12 @@ input Grpc { This refers to the gRPC method you're going to call. For instance `GetAllNews`. """ method: String! + """ + Specifies a JavaScript function to be executed after receiving the response body. + This function can modify or transform the response body before it's sent back to + the client. + """ + onResponseBody: String } """ @@ -827,6 +845,12 @@ input Http { """ onRequest: String """ + Specifies a JavaScript function to be executed after receiving the response body. + This function can modify or transform the response body before it's sent back to + the client. + """ + onResponseBody: String + """ Schema of the output of the API call. It is automatically inferred in most cases. """ output: Schema diff --git a/generated/.tailcallrc.schema.json b/generated/.tailcallrc.schema.json index 654c30eedf8..ff35972bd94 100644 --- a/generated/.tailcallrc.schema.json +++ b/generated/.tailcallrc.schema.json @@ -589,6 +589,13 @@ "method": { "description": "This refers to the gRPC method you're going to call. For instance `GetAllNews`.", "type": "string" + }, + "onResponseBody": { + "description": "Specifies a JavaScript function to be executed after receiving the response body. This function can modify or transform the response body before it's sent back to the client.", + "type": [ + "string", + "null" + ] } }, "additionalProperties": false @@ -710,6 +717,13 @@ "null" ] }, + "onResponseBody": { + "description": "Specifies a JavaScript function to be executed after receiving the response body. This function can modify or transform the response body before it's sent back to the client.", + "type": [ + "string", + "null" + ] + }, "output": { "description": "Schema of the output of the API call. It is automatically inferred in most cases.", "anyOf": [ diff --git a/src/core/config/config.rs b/src/core/config/config.rs index 77ff4880f8b..a3182f8fc1a 100644 --- a/src/core/config/config.rs +++ b/src/core/config/config.rs @@ -525,6 +525,9 @@ pub struct Http { /// syntax is automatically selected as the batching parameter. pub query: Vec, + /// Specifies a JavaScript function to be executed after receiving the + /// response body. This function can modify or transform the response + /// body before it's sent back to the client. #[serde(rename = "onResponseBody", default, skip_serializing_if = "is_default")] pub on_response_body: Option, } @@ -616,6 +619,9 @@ pub struct Grpc { /// `GetAllNews`. pub method: String, + /// Specifies a JavaScript function to be executed after receiving the + /// response body. This function can modify or transform the response + /// body before it's sent back to the client. #[serde(rename = "onResponseBody", default, skip_serializing_if = "is_default")] pub on_response_body: Option, } diff --git a/src/core/http/mod.rs b/src/core/http/mod.rs index 57966912100..9149f1d7c14 100644 --- a/src/core/http/mod.rs +++ b/src/core/http/mod.rs @@ -33,14 +33,14 @@ pub struct HttpFilter { } impl HttpFilter { - pub fn new(on_request: Option, on_response: Option) -> Result { + pub fn new( + on_request: Option, + on_response: Option, + ) -> Result { if on_request.is_none() && on_response.is_none() { Err("At least one of on_request or on_response must be present") } else { - Ok(HttpFilter { - on_request, - on_response, - }) + Ok(HttpFilter { on_request, on_response }) } } } diff --git a/src/core/worker/worker.rs b/src/core/worker/worker.rs index faba8808e6c..4e6ef46dded 100644 --- a/src/core/worker/worker.rs +++ b/src/core/worker/worker.rs @@ -37,7 +37,7 @@ pub struct WorkerRequest(pub reqwest::Request); #[derive(Debug)] pub enum Event { Request(WorkerRequest), - Response(WorkerResponse) + Response(WorkerResponse), } #[derive(Debug)] diff --git a/tests/execution/test-on-response-body.md b/tests/execution/test-on-response-body.md index ebd433d82ff..cd938851509 100644 --- a/tests/execution/test-on-response-body.md +++ b/tests/execution/test-on-response-body.md @@ -2,10 +2,10 @@ ```js @file:test.js function onResponse({response}) { - let body = JSON.parse(response.body); - body.name = body.name + " - Changed by JS"; - response.body = JSON.stringify(body); - return {response}; + let body = JSON.parse(response.body) + body.name = body.name + " - Changed by JS" + response.body = JSON.stringify(body) + return {response} } ```