Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(torii-gql): get rid of world indexing error #2827

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions crates/torii/graphql/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,17 @@
pool: &Pool<Sqlite>,
) -> (SocketAddr, impl Future<Output = ()> + '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);

Check warning on line 22 in crates/torii/graphql/src/server.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/graphql/src/server.rs#L22

Added line #L22 was not covered by tests
warp::serve(routes).bind_with_graceful_shutdown(([127, 0, 0, 1], 0), async move {
shutdown_rx.recv().await.ok();
})
}

fn graphql_filter(
schema: Schema,
is_empty: bool,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + 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
Expand All @@ -57,12 +49,3 @@

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)
}
Loading