Skip to content

Commit

Permalink
fix(torii): graphql playground URL (#2707)
Browse files Browse the repository at this point in the history
* fix: avoid absolute path for URLs

* fix: attempt to fix using relative URL

* fix: merge external url logic for subscription and endpoint

* fix: ensure panic if the scheme is invalid
  • Loading branch information
glihm authored Nov 21, 2024
1 parent f44886d commit 374461d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions crates/torii/graphql/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,28 @@ 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");
let (graphql_endpoint, subscription_endpoint) = if let Some(external_url) = external_url {
let mut graphql_url = external_url;
graphql_url.set_path("graphql");

let websocket_scheme = match websocket_url.scheme() {
"http" => "ws",
let mut websocket_url = graphql_url.clone();
websocket_url.set_path("ws");
let _ = websocket_url.set_scheme(match websocket_url.scheme() {
"https" => "wss",
_ => panic!("Invalid URL scheme"), // URL validated on input so this never hits
};
"http" => "ws",
_ => panic!("Invalid URL scheme - must be http or https"),
});

let _ = websocket_url.set_scheme(websocket_scheme);
websocket_url.to_string()
(graphql_url.path().to_string(), websocket_url.to_string())
} else {
"/graphql/ws".to_string()
("graphql".to_string(), "graphql/ws".to_string())
};

let playground_filter = warp::path("graphql").map(move || {
warp::reply::html(
GraphiQLSource::build()
.endpoint("/graphql")
.subscription_endpoint(subscription_endpoint.as_str())
.endpoint(&graphql_endpoint)
.subscription_endpoint(&subscription_endpoint)
.finish(),
)
});
Expand Down

0 comments on commit 374461d

Please sign in to comment.