Skip to content

Commit

Permalink
fix: use request from gateway instead of serde req (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
gusinacio authored Nov 6, 2024
1 parent 450ee8d commit fdeda9f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion common/src/indexer_service/http/indexer_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub trait IndexerServiceImpl {
&self,
manifest_id: DeploymentId,
request: Request,
) -> Result<(Request, Self::Response), Self::Error>;
) -> Result<Self::Response, Self::Error>;
}

#[derive(Debug, Error)]
Expand Down
25 changes: 10 additions & 15 deletions common/src/indexer_service/http/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::sync::Arc;

use axum::{
body::Bytes,
extract::{Path, State},
http::HeaderMap,
response::IntoResponse,
Expand Down Expand Up @@ -54,7 +53,7 @@ pub async fn request_handler<I>(
typed_header: TypedHeader<TapReceipt>,
state: State<Arc<IndexerServiceState<I>>>,
headers: HeaderMap,
body: Bytes,
body: String,
) -> Result<impl IntoResponse, IndexerServiceError<I::Error>>
where
I: IndexerServiceImpl + Sync + Send + 'static,
Expand All @@ -73,21 +72,15 @@ async fn _request_handler<I>(
TypedHeader(receipt): TypedHeader<TapReceipt>,
State(state): State<Arc<IndexerServiceState<I>>>,
headers: HeaderMap,
body: Bytes,
req: String,
) -> Result<impl IntoResponse, IndexerServiceError<I::Error>>
where
I: IndexerServiceImpl + Sync + Send + 'static,
{
trace!("Handling request for deployment `{manifest_id}`");

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct QueryBody {
pub query: String,
pub variables: Option<Box<RawValue>>,
}

let request: QueryBody =
serde_json::from_slice(&body).map_err(|e| IndexerServiceError::InvalidRequest(e.into()))?;
serde_json::from_str(&req).map_err(|e| IndexerServiceError::InvalidRequest(e.into()))?;

let Some(receipt) = receipt.into_signed_receipt() else {
// Serve free query, NO METRICS
Expand All @@ -112,7 +105,6 @@ where
.process_request(manifest_id, request)
.await
.map_err(IndexerServiceError::ProcessingError)?
.1
.finalize(AttestationOutput::Attestable);
return Ok((StatusCode::OK, response));
};
Expand Down Expand Up @@ -179,15 +171,12 @@ where
.cloned()
.ok_or_else(|| (IndexerServiceError::NoSignerForAllocation(allocation_id)))?;

let (request, response) = state
let response = state
.service_impl
.process_request(manifest_id, request)
.await
.map_err(IndexerServiceError::ProcessingError)?;

let req = serde_json::to_string(&request)
.map_err(|_| IndexerServiceError::FailedToSignAttestation)?;

let res = response
.as_str()
.map_err(|_| IndexerServiceError::FailedToSignAttestation)?;
Expand All @@ -202,3 +191,9 @@ where

Ok((StatusCode::OK, response))
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct QueryBody {
pub query: String,
pub variables: Option<Box<RawValue>>,
}
4 changes: 2 additions & 2 deletions service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl IndexerServiceImpl for SubgraphService {
&self,
deployment: DeploymentId,
request: Request,
) -> Result<(Request, Self::Response), Self::Error> {
) -> Result<Self::Response, Self::Error> {
let deployment_url = self
.state
.graph_node_query_base_url
Expand Down Expand Up @@ -118,7 +118,7 @@ impl IndexerServiceImpl for SubgraphService {
.await
.map_err(SubgraphServiceError::QueryForwardingError)?;

Ok((request, SubgraphServiceResponse::new(body, attestable)))
Ok(SubgraphServiceResponse::new(body, attestable))
}
}

Expand Down

0 comments on commit fdeda9f

Please sign in to comment.