Skip to content

Commit

Permalink
Revert "feat: limit functions exposed in indexing status API"
Browse files Browse the repository at this point in the history
This reverts commit 50fb34e.
Need to add a fix for only limit query fields at the root
  • Loading branch information
hopeyen committed Sep 28, 2023
1 parent 50fb34e commit 56d2fe1
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 140 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ faux = { version = "0.1.10", optional = true }
keccak-hash = "0.10.0"
lazy_static = "1.4.0"
log = "0.4.20"
regex = "1.7.1"
reqwest = "0.11.20"
secp256k1 = { version = "0.27.0", features = ["recovery"] }
serde = { version = "1.0.188", features = ["derive"] }
Expand Down
93 changes: 0 additions & 93 deletions common/src/graphql.rs

This file was deleted.

1 change: 0 additions & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

pub mod allocations;
pub mod attestations;
pub mod graphql;
pub mod network_subgraph;
pub mod signature_verification;
pub mod types;
Expand Down
1 change: 0 additions & 1 deletion service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ ethereum-types = "0.14.1"
sqlx = { version = "0.7.1", features = ["postgres", "runtime-tokio", "bigdecimal", "rust_decimal", "time"] }
alloy-primitives = { version = "0.3.3", features = ["serde"] }
alloy-sol-types = "0.3.2"
lazy_static = "1.4.0"

[dev-dependencies]
faux = "0.1.10"
Expand Down
4 changes: 0 additions & 4 deletions service/src/query_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ pub enum QueryError {
IndexingError,
#[error("Bad or invalid entity data found in the subgraph: {}", .0.to_string())]
BadData(anyhow::Error),
#[error("Invalid GraphQL query string: {0}")]
InvalidFormat(String),
#[error("Cannot query field: {:#?}", .0)]
UnsupportedFields(Vec<String>),
#[error("Unknown error: {0}")]
Other(anyhow::Error),
}
Expand Down
42 changes: 4 additions & 38 deletions service/src/server/routes/status.rs
Original file line number Diff line number Diff line change
@@ -1,64 +1,30 @@
// Copyright 2023-, GraphOps and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

use std::collections::HashSet;

use axum::{
http::{Request, StatusCode},
response::IntoResponse,
Extension, Json,
};

use hyper::body::Bytes;

use reqwest::{header, Client};

use crate::server::ServerOptions;
use indexer_common::graphql::filter_supported_fields;

use super::bad_request_response;

lazy_static::lazy_static! {
static ref SUPPORTED_ROOT_FIELDS: HashSet<&'static str> =
vec![
"indexingStatuses",
"publicProofsOfIndexing",
"entityChangesInBlock",
"blockData",
"cachedEthereumCalls",
"subgraphFeatures",
"apiVersions",
].into_iter().collect();
}

// Custom middleware function to process the request before reaching the main handler
pub async fn status_queries(
Extension(server): Extension<ServerOptions>,
req: Request<axum::body::Body>,
) -> impl IntoResponse {
let body_bytes = hyper::body::to_bytes(req.into_body()).await.unwrap();
// Read the requested query string
let query_string = match String::from_utf8(body_bytes.to_vec()) {
Ok(s) => s,
Err(e) => return bad_request_response(&e.to_string()),
};

// filter supported root fields
let query_string = match filter_supported_fields(&query_string, &SUPPORTED_ROOT_FIELDS) {
Ok(query) => query,
Err(unsupported_fields) => {
return (
StatusCode::BAD_REQUEST,
format!("Cannot query field: {:#?}", unsupported_fields),
)
.into_response();
}
};

let req_body = req.into_body();
// TODO: Extract the incoming GraphQL operation and filter root fields
// Pass the modified operation to the actual endpoint

let request = Client::new()
.post(&server.graph_node_status_endpoint)
.body(Bytes::from(query_string))
.body(req_body)
.header(header::CONTENT_TYPE, "application/json");

let response: reqwest::Response = match request.send().await {
Expand Down

0 comments on commit 56d2fe1

Please sign in to comment.