From 37ad714834c5bd89100571cfea8d70ef9bef2b1f Mon Sep 17 00:00:00 2001 From: laststylebender <43403528+laststylebender14@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:36:45 +0530 Subject: [PATCH] fix: clone value instead taking ownership for dedupe (#3007) --- src/core/app_context.rs | 3 ++- src/core/jit/graphql_executor.rs | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/core/app_context.rs b/src/core/app_context.rs index 5331e3e1d1..1f718e19d7 100644 --- a/src/core/app_context.rs +++ b/src/core/app_context.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use async_graphql::dynamic::{self, DynamicRequest}; use async_graphql_value::ConstValue; +use super::lift::Lift; use crate::core::async_graphql_hyper::OperationId; use crate::core::auth::context::GlobalAuthContext; use crate::core::blueprint::{Blueprint, Definition, SchemaModifiers}; @@ -26,7 +27,7 @@ pub struct AppContext { pub endpoints: EndpointSet, pub auth_ctx: Arc, pub dedupe_handler: Arc>, - pub dedupe_operation_handler: DedupeResult, Error>, + pub dedupe_operation_handler: DedupeResult, Error>, } impl AppContext { diff --git a/src/core/jit/graphql_executor.rs b/src/core/jit/graphql_executor.rs index b344c03f42..3ce3bad8fc 100644 --- a/src/core/jit/graphql_executor.rs +++ b/src/core/jit/graphql_executor.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::future::Future; use std::sync::Arc; -use async_graphql::{Data, Executor, Response, ServerError, Value}; +use async_graphql::{Data, Executor, Response, Value}; use async_graphql_value::{ConstValue, Extensions}; use futures_util::stream::BoxStream; @@ -11,6 +11,7 @@ use crate::core::async_graphql_hyper::OperationId; use crate::core::http::RequestContext; use crate::core::jit; use crate::core::jit::ConstValueExecutor; +use crate::core::lift::{CanLift, Lift}; use crate::core::merge_right::MergeRight; #[derive(Clone)] @@ -64,14 +65,23 @@ impl JITExecutor { .dedupe(&self.operation_id, || { Box::pin(async move { let resp = self.exec(exec, jit_request).await; - Ok(Arc::new(resp)) + Ok(resp.lift()) }) }) .await; - let val = out.unwrap_or_default(); - Arc::into_inner(val).unwrap_or_else(|| { - Response::from_errors(vec![ServerError::new("Deduplication failed", None)]) - }) + + out.map(|response| response.take()).unwrap_or_default() + } +} + +impl Clone for Lift { + fn clone(&self) -> Self { + let mut res = async_graphql::Response::new(self.data.clone()) + .cache_control(self.cache_control) + .http_headers(self.http_headers.clone()); + res.errors = self.errors.clone(); + res.extensions = self.extensions.clone(); + res.into() } }