From c2730d9824b2ecbf1ed5d93d5ea9222292ebe42a Mon Sep 17 00:00:00 2001 From: glihm Date: Wed, 20 Nov 2024 17:45:54 -0600 Subject: [PATCH 1/4] fix: avoid absolute path for URLs --- crates/torii/graphql/src/server.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/torii/graphql/src/server.rs b/crates/torii/graphql/src/server.rs index d89e91dee7..d992f67df9 100644 --- a/crates/torii/graphql/src/server.rs +++ b/crates/torii/graphql/src/server.rs @@ -50,7 +50,7 @@ fn graphql_filter( let subscription_endpoint = if let Some(external_url) = external_url { let mut websocket_url = external_url.clone(); - websocket_url.set_path("/graphql/ws"); + websocket_url.set_path("graphql/ws"); let websocket_scheme = match websocket_url.scheme() { "http" => "ws", @@ -61,13 +61,13 @@ fn graphql_filter( let _ = websocket_url.set_scheme(websocket_scheme); websocket_url.to_string() } else { - "/graphql/ws".to_string() + "graphql/ws".to_string() }; let playground_filter = warp::path("graphql").map(move || { warp::reply::html( GraphiQLSource::build() - .endpoint("/graphql") + .endpoint("graphql") .subscription_endpoint(subscription_endpoint.as_str()) .finish(), ) From dbb517af04dbf6e20c6b1c52b777b1544c6b6d92 Mon Sep 17 00:00:00 2001 From: glihm Date: Wed, 20 Nov 2024 18:23:35 -0600 Subject: [PATCH 2/4] fix: attempt to fix using relative URL --- crates/torii/graphql/src/server.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/torii/graphql/src/server.rs b/crates/torii/graphql/src/server.rs index d992f67df9..7998d8370d 100644 --- a/crates/torii/graphql/src/server.rs +++ b/crates/torii/graphql/src/server.rs @@ -48,7 +48,7 @@ fn graphql_filter( }, ); - let subscription_endpoint = if let Some(external_url) = external_url { + let subscription_endpoint = if let Some(external_url) = external_url.clone() { let mut websocket_url = external_url.clone(); websocket_url.set_path("graphql/ws"); @@ -64,10 +64,18 @@ fn graphql_filter( "graphql/ws".to_string() }; + let graphql_endpoint = if let Some(external_url) = external_url { + let mut graphql_url = external_url.clone(); + graphql_url.set_path(&format!("{}/graphql", graphql_url.path().trim_end_matches('/'))); + graphql_url.path().to_string() + } else { + "graphql".to_string() + }; + let playground_filter = warp::path("graphql").map(move || { warp::reply::html( GraphiQLSource::build() - .endpoint("graphql") + .endpoint(&graphql_endpoint) .subscription_endpoint(subscription_endpoint.as_str()) .finish(), ) From ea63e39c8d92928f39b452a8a3af2082685db5f6 Mon Sep 17 00:00:00 2001 From: glihm Date: Wed, 20 Nov 2024 20:01:27 -0600 Subject: [PATCH 3/4] fix: merge external url logic for subscription and endpoint --- crates/torii/graphql/src/server.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/crates/torii/graphql/src/server.rs b/crates/torii/graphql/src/server.rs index 7998d8370d..1cb5959c0f 100644 --- a/crates/torii/graphql/src/server.rs +++ b/crates/torii/graphql/src/server.rs @@ -48,35 +48,25 @@ fn graphql_filter( }, ); - let subscription_endpoint = if let Some(external_url) = external_url.clone() { - let mut websocket_url = external_url.clone(); - websocket_url.set_path("graphql/ws"); - - let websocket_scheme = match websocket_url.scheme() { - "http" => "ws", - "https" => "wss", - _ => panic!("Invalid URL scheme"), // URL validated on input so this never hits - }; + let (graphql_endpoint, subscription_endpoint) = if let Some(external_url) = external_url { + let mut graphql_url = external_url.clone(); + graphql_url.set_path("graphql"); - let _ = websocket_url.set_scheme(websocket_scheme); - websocket_url.to_string() - } else { - "graphql/ws".to_string() - }; + let mut websocket_url = external_url; + websocket_url.set_path("graphql/ws"); + let _ = + websocket_url.set_scheme(if websocket_url.scheme() == "https" { "wss" } else { "ws" }); - let graphql_endpoint = if let Some(external_url) = external_url { - let mut graphql_url = external_url.clone(); - graphql_url.set_path(&format!("{}/graphql", graphql_url.path().trim_end_matches('/'))); - graphql_url.path().to_string() + (graphql_url.path().to_string(), websocket_url.to_string()) } else { - "graphql".to_string() + ("graphql".to_string(), "graphql/ws".to_string()) }; let playground_filter = warp::path("graphql").map(move || { warp::reply::html( GraphiQLSource::build() .endpoint(&graphql_endpoint) - .subscription_endpoint(subscription_endpoint.as_str()) + .subscription_endpoint(&subscription_endpoint) .finish(), ) }); From 7be2959bc100aeab49c4a3707cf4386debb3b924 Mon Sep 17 00:00:00 2001 From: glihm Date: Wed, 20 Nov 2024 20:17:23 -0600 Subject: [PATCH 4/4] fix: ensure panic if the scheme is invalid --- crates/torii/graphql/src/server.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/torii/graphql/src/server.rs b/crates/torii/graphql/src/server.rs index 1cb5959c0f..6121f492fe 100644 --- a/crates/torii/graphql/src/server.rs +++ b/crates/torii/graphql/src/server.rs @@ -49,13 +49,16 @@ fn graphql_filter( ); let (graphql_endpoint, subscription_endpoint) = if let Some(external_url) = external_url { - let mut graphql_url = external_url.clone(); + let mut graphql_url = external_url; graphql_url.set_path("graphql"); - let mut websocket_url = external_url; - websocket_url.set_path("graphql/ws"); - let _ = - websocket_url.set_scheme(if websocket_url.scheme() == "https" { "wss" } else { "ws" }); + let mut websocket_url = graphql_url.clone(); + websocket_url.set_path("ws"); + let _ = websocket_url.set_scheme(match websocket_url.scheme() { + "https" => "wss", + "http" => "ws", + _ => panic!("Invalid URL scheme - must be http or https"), + }); (graphql_url.path().to_string(), websocket_url.to_string()) } else {