From 52483718ed51b050df517aac26bb868eaf1932b7 Mon Sep 17 00:00:00 2001 From: Alexander van Ratingen <470642+alvra@users.noreply.github.com> Date: Thu, 4 Feb 2021 03:17:19 +0100 Subject: [PATCH] Support subscriptions for GraphiQL and Playground. (#859) * Support subscriptions for GraphiQL and Playground. Add support for subscriptions for GraphiQL and Playground in `juniper_rocket_async`. * Update example. Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com> --- juniper_rocket_async/examples/rocket_server.rs | 2 +- juniper_rocket_async/src/lib.rs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/juniper_rocket_async/examples/rocket_server.rs b/juniper_rocket_async/examples/rocket_server.rs index def21f33..f8a1ca0d 100644 --- a/juniper_rocket_async/examples/rocket_server.rs +++ b/juniper_rocket_async/examples/rocket_server.rs @@ -8,7 +8,7 @@ type Schema = RootNode<'static, Query, EmptyMutation<Database>, EmptySubscriptio #[rocket::get("/")] fn graphiql() -> content::Html<String> { - juniper_rocket_async::graphiql_source("/graphql") + juniper_rocket_async::graphiql_source("/graphql", None) } #[rocket::get("/graphql?<request>")] diff --git a/juniper_rocket_async/src/lib.rs b/juniper_rocket_async/src/lib.rs index 7dd5853a..347369a5 100644 --- a/juniper_rocket_async/src/lib.rs +++ b/juniper_rocket_async/src/lib.rs @@ -69,18 +69,24 @@ where pub struct GraphQLResponse(pub Status, pub String); /// Generate an HTML page containing GraphiQL -pub fn graphiql_source(graphql_endpoint_url: &str) -> content::Html<String> { +pub fn graphiql_source( + graphql_endpoint_url: &str, + subscriptions_endpoint_url: Option<&str>, +) -> content::Html<String> { content::Html(juniper::http::graphiql::graphiql_source( graphql_endpoint_url, - None, + subscriptions_endpoint_url, )) } /// Generate an HTML page containing GraphQL Playground -pub fn playground_source(graphql_endpoint_url: &str) -> content::Html<String> { +pub fn playground_source( + graphql_endpoint_url: &str, + subscriptions_endpoint_url: Option<&str>, +) -> content::Html<String> { content::Html(juniper::http::playground::playground_source( graphql_endpoint_url, - None, + subscriptions_endpoint_url, )) }