Skip to content

Commit

Permalink
- lint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
laststylebender14 committed Sep 18, 2024
1 parent 308ea9e commit 5f407bc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
24 changes: 24 additions & 0 deletions generated/.tailcallrc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

"""
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": [
Expand Down
6 changes: 6 additions & 0 deletions src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ pub struct Http {
/// syntax is automatically selected as the batching parameter.
pub query: Vec<URLQuery>,

/// 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<String>,
}
Expand Down Expand Up @@ -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<String>,
}
Expand Down
10 changes: 5 additions & 5 deletions src/core/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ pub struct HttpFilter {
}

impl HttpFilter {
pub fn new(on_request: Option<String>, on_response: Option<String>) -> Result<Self, &'static str> {
pub fn new(
on_request: Option<String>,
on_response: Option<String>,
) -> Result<Self, &'static str> {
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 })
}
}
}
2 changes: 1 addition & 1 deletion src/core/worker/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct WorkerRequest(pub reqwest::Request);
#[derive(Debug)]
pub enum Event {
Request(WorkerRequest),
Response(WorkerResponse)
Response(WorkerResponse),
}

#[derive(Debug)]
Expand Down
8 changes: 4 additions & 4 deletions tests/execution/test-on-response-body.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
```

Expand Down

0 comments on commit 5f407bc

Please sign in to comment.