From f7cf27cc6b6e1208df1a42c579a2ba8f8e0c983b Mon Sep 17 00:00:00 2001 From: Matthew Kuo Date: Sun, 12 Apr 2020 14:58:40 -0500 Subject: [PATCH 1/2] Add subscriptions support on GraphiQL Addresses #501 BREAKING CHANGE: `juniper::http::graphiql::graphiql_source` now requires a second parameter BREAKING CHANGE: `juniper_hyper::graphiql` now requires a second parameter BREAKING CHANGE: `juniper_iron::GraphiQLHandler::new` now requires a second parameter BREAKING CHANGE: `juniper_rocket::graphiql_source` now requires a second parameter BREAKING CHANGE: `juniper_warp::graphiql_filter` now requires a second parameter --- juniper/CHANGELOG.md | 3 ++ juniper/src/http/graphiql.rs | 35 ++++++++++++++++++++++-- juniper_hyper/CHANGELOG.md | 4 +++ juniper_hyper/examples/hyper_server.rs | 2 +- juniper_hyper/src/lib.rs | 10 +++++-- juniper_iron/CHANGELOG.md | 4 +++ juniper_iron/examples/iron_server.rs | 2 +- juniper_iron/src/lib.rs | 9 ++++-- juniper_rocket/CHANGELOG.md | 4 +++ juniper_rocket/examples/rocket_server.rs | 2 +- juniper_rocket/src/lib.rs | 6 +++- juniper_rocket_async/src/lib.rs | 1 + juniper_warp/CHANGELOG.md | 1 + juniper_warp/examples/warp_server.rs | 2 +- juniper_warp/src/lib.rs | 35 +++++++++++++++++++----- 15 files changed, 101 insertions(+), 19 deletions(-) diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 6f5afa1fe..80a88f3f0 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -18,11 +18,14 @@ See [#419](https://github.com/graphql-rust/juniper/pull/419). - `SchemaType` is now public - This is helpful when using `context.getSchema()` inside of your field resolvers +- Support subscriptions in GraphiQL + See [#569](https://github.com/graphql-rust/juniper/pull/569). ## Breaking Changes - `juniper::graphiql` has moved to `juniper::http::graphiql` + - `juniper::http::graphiql::graphiql_source` now requies a second parameter for subscriptions - remove old `graphql_object!` macro, rename `object` proc macro to `graphql_object` diff --git a/juniper/src/http/graphiql.rs b/juniper/src/http/graphiql.rs index f79d091e7..d1cd12cec 100644 --- a/juniper/src/http/graphiql.rs +++ b/juniper/src/http/graphiql.rs @@ -1,7 +1,23 @@ //! Utility module to generate a GraphiQL interface /// Generate the HTML source to show a GraphiQL interface -pub fn graphiql_source(graphql_endpoint_url: &str) -> String { +/// +/// The subscriptions endpoint URL can optionally be provided. For example: +/// +/// ``` +/// # use juniper::http::graphiql::graphiql_source; +/// let graphiql = graphiql_source("/graphql", Some("ws://localhost:8080/subscriptions")); +/// ``` +pub fn graphiql_source( + graphql_endpoint_url: &str, + subscriptions_endpoint_url: Option<&str>, +) -> String { + let subscriptions_endpoint = if let Some(sub_url) = subscriptions_endpoint_url { + sub_url + } else { + "" + }; + let stylesheet_source = r#"