mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
if no plugins make middleware no-op (#948)
<!-- The PR description should answer 2 important questions: --> ### What <!-- What is this PR trying to accomplish (and why, if it's not obvious)? --> <!-- Consider: do we need to add a changelog entry? --> <!-- Does this PR introduce new validation that might break old builds? --> <!-- Consider: do we need to put new checks behind a flag? --> Just an improvement to the middleware plugin ### How <!-- How is it trying to accomplish it (what are the implementation steps)? --> We now take a nonempty list of plugins. This ensures that we only do things if we have plugins. V3_GIT_ORIGIN_REV_ID: c8fb548f763cdefe3526c67d7c801104ad5c527a
This commit is contained in:
parent
2c94e0b1dd
commit
8233d6caa3
2
v3/Cargo.lock
generated
2
v3/Cargo.lock
generated
@ -1729,6 +1729,7 @@ dependencies = [
|
||||
"json_value_merge",
|
||||
"lang-graphql",
|
||||
"metadata-resolve",
|
||||
"nonempty",
|
||||
"open-dds",
|
||||
"opendds-derive",
|
||||
"pre-execution-plugin",
|
||||
@ -3615,6 +3616,7 @@ dependencies = [
|
||||
"axum",
|
||||
"hasura-authn-core",
|
||||
"lang-graphql",
|
||||
"nonempty",
|
||||
"open-dds",
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
@ -40,6 +40,7 @@ axum = { workspace = true }
|
||||
base64 = { workspace = true }
|
||||
clap = { workspace = true, features = ["derive", "env"] }
|
||||
json_value_merge = { workspace = true }
|
||||
nonempty = { workspace = true }
|
||||
reqwest = { workspace = true, features = ["json", "multipart"] }
|
||||
schemars = { workspace = true, features = ["smol_str"] }
|
||||
serde = { workspace = true }
|
||||
|
@ -656,29 +656,34 @@ async fn handle_explain_request(
|
||||
response
|
||||
}
|
||||
|
||||
async fn pre_execution_plugins_middleware<'a, B>(
|
||||
async fn pre_execution_plugins_middleware<'a>(
|
||||
State(engine_state): State<Arc<EngineState>>,
|
||||
Extension(session): Extension<Session>,
|
||||
headers_map: HeaderMap,
|
||||
request: Request<B>,
|
||||
request: Request<axum::body::Body>,
|
||||
next: Next<axum::body::Body>,
|
||||
) -> axum::response::Result<axum::response::Response>
|
||||
where
|
||||
B: HttpBody,
|
||||
B::Error: Display,
|
||||
{
|
||||
let (request, response) = pre_execution_plugins_handler(
|
||||
&engine_state.pre_parse_plugins,
|
||||
&engine_state.http_context.client,
|
||||
session,
|
||||
request,
|
||||
headers_map,
|
||||
)
|
||||
.await?;
|
||||
) -> axum::response::Result<axum::response::Response> {
|
||||
// Check if the pre_execution_plugins_config is empty
|
||||
match nonempty::NonEmpty::from_slice(&engine_state.pre_parse_plugins) {
|
||||
None => {
|
||||
// If empty, do nothing and pass the request to the next middleware
|
||||
Ok(next.run(request).await)
|
||||
}
|
||||
Some(pre_parse_plugins) => {
|
||||
let (request, response) = pre_execution_plugins_handler(
|
||||
&pre_parse_plugins,
|
||||
&engine_state.http_context.client,
|
||||
session,
|
||||
request,
|
||||
headers_map,
|
||||
)
|
||||
.await?;
|
||||
|
||||
match response {
|
||||
Some(response) => Ok(response),
|
||||
None => Ok(next.run(request).await),
|
||||
match response {
|
||||
Some(response) => Ok(response),
|
||||
None => Ok(next.run(request).await),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ tracing-util = { path = "../../utils/tracing-util" }
|
||||
open-dds = { path = "../../open-dds" }
|
||||
|
||||
axum = { workspace = true }
|
||||
nonempty = { workspace = true }
|
||||
reqwest = { workspace = true, features = ["json"] }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
@ -212,7 +212,7 @@ pub async fn execute_plugin(
|
||||
}
|
||||
|
||||
pub async fn pre_execution_plugins_handler<'a, B>(
|
||||
pre_execution_plugins_config: &Vec<LifecyclePluginHookPreParse>,
|
||||
pre_execution_plugins_config: &nonempty::NonEmpty<LifecyclePluginHookPreParse>,
|
||||
http_client: &reqwest::Client,
|
||||
session: Session,
|
||||
request: Request<B>,
|
||||
|
Loading…
Reference in New Issue
Block a user