Skip to content

Commit e58482a

Browse files
committed
refactor: use subgraph client as state
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 2fc04f7 commit e58482a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

crates/service/src/routes/static_subgraph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use axum::{body::Bytes, response::IntoResponse, Extension, Json};
4+
use axum::{body::Bytes, extract::State, response::IntoResponse, Json};
55
use reqwest::StatusCode;
66
use serde_json::json;
77
use tracing::warn;
@@ -10,7 +10,7 @@ use indexer_common::SubgraphClient;
1010

1111
#[autometrics::autometrics]
1212
pub async fn static_subgraph_request_handler(
13-
Extension(subgraph_client): Extension<&'static SubgraphClient>,
13+
State(subgraph_client): State<&'static SubgraphClient>,
1414
body: Bytes,
1515
) -> Result<impl IntoResponse, StaticSubgraphError> {
1616
let response = subgraph_client.query_raw(body).await?;

crates/service/src/service/indexer_service.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use alloy::dyn_abi::Eip712Domain;
55
use anyhow;
66
use axum::extract::MatchedPath;
77
use axum::extract::Request as ExtractRequest;
8+
use axum::handler::Handler;
89
use axum::http::{Method, Request};
910
use axum::{
1011
async_trait,
@@ -414,7 +415,7 @@ impl IndexerService {
414415
"/network",
415416
post(static_subgraph_request_handler)
416417
.route_layer(auth_layer)
417-
.route_layer(Extension(network_subgraph))
418+
.with_state(network_subgraph)
418419
.route_layer(static_subgraph_rate_limiter.clone()),
419420
);
420421
} else {
@@ -428,14 +429,13 @@ impl IndexerService {
428429

429430
let auth_layer = ValidateRequestHeaderLayer::bearer(free_auth_token);
430431

431-
misc_routes = misc_routes
432-
.route(
433-
"/escrow",
434-
post(static_subgraph_request_handler)
435-
.route_layer(auth_layer)
436-
.route_layer(Extension(escrow_subgraph)),
437-
)
438-
.route_layer(static_subgraph_rate_limiter);
432+
misc_routes = misc_routes.route(
433+
"/escrow",
434+
post(static_subgraph_request_handler)
435+
.route_layer(auth_layer)
436+
.with_state(escrow_subgraph)
437+
.route_layer(static_subgraph_rate_limiter),
438+
)
439439
} else {
440440
warn!("`serve_escrow_subgraph` is enabled but no `serve_auth_token` provided. Disabling it.");
441441
}

0 commit comments

Comments
 (0)