From 636f864e9730b8a47d8bcf78ff9a29f095845bcb Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 20 Dec 2024 13:24:48 +0700 Subject: [PATCH 1/2] refactor(torii-gql): get rid of world indexing error --- crates/torii/graphql/src/server.rs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/crates/torii/graphql/src/server.rs b/crates/torii/graphql/src/server.rs index 750aed70c0..72bf195526 100644 --- a/crates/torii/graphql/src/server.rs +++ b/crates/torii/graphql/src/server.rs @@ -19,10 +19,7 @@ pub async fn new( pool: &Pool, ) -> (SocketAddr, impl Future + 'static) { let schema = build_schema(pool).await.unwrap(); - let mut conn = pool.acquire().await.unwrap(); - let num_models = count_rows(&mut conn, MODEL_TABLE, &None, &None).await.unwrap(); - - let routes = graphql_filter(schema, num_models == 0); + let routes = graphql_filter(schema); warp::serve(routes).bind_with_graceful_shutdown(([127, 0, 0, 1], 0), async move { shutdown_rx.recv().await.ok(); }) @@ -30,14 +27,9 @@ pub async fn new( fn graphql_filter( schema: Schema, - is_empty: bool, ) -> impl Filter + Clone { let graphql_post = async_graphql_warp::graphql(schema.clone()).and_then( move |(schema, request): (Schema, Request)| async move { - if is_empty { - return Ok::<_, Rejection>(empty_response()); - } - // Execute query let response = schema.execute(request).await; // Return result @@ -57,12 +49,3 @@ fn graphql_filter( graphql_subscription(schema).or(graphql_post).or(playground_filter) } - -fn empty_response() -> warp::reply::Json { - let empty_response = json!({ - "errors": [{ - "message": "World does not have any indexed data yet." - }] - }); - warp::reply::json(&empty_response) -} From 593a4166b9dfa134b727058c2d4e9cc48dedf951 Mon Sep 17 00:00:00 2001 From: glihm Date: Sat, 21 Dec 2024 10:54:13 -0600 Subject: [PATCH 2/2] fix: fmt and clippy --- crates/torii/graphql/src/server.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/torii/graphql/src/server.rs b/crates/torii/graphql/src/server.rs index 72bf195526..eae85ba949 100644 --- a/crates/torii/graphql/src/server.rs +++ b/crates/torii/graphql/src/server.rs @@ -5,14 +5,11 @@ use async_graphql::dynamic::Schema; use async_graphql::http::GraphiQLSource; use async_graphql::Request; use async_graphql_warp::graphql_subscription; -use serde_json::json; use sqlx::{Pool, Sqlite}; use tokio::sync::broadcast::Receiver; use warp::{Filter, Rejection, Reply}; use super::schema::build_schema; -use crate::constants::MODEL_TABLE; -use crate::query::data::count_rows; pub async fn new( mut shutdown_rx: Receiver<()>, @@ -25,9 +22,7 @@ pub async fn new( }) } -fn graphql_filter( - schema: Schema, -) -> impl Filter + Clone { +fn graphql_filter(schema: Schema) -> impl Filter + Clone { let graphql_post = async_graphql_warp::graphql(schema.clone()).and_then( move |(schema, request): (Schema, Request)| async move { // Execute query