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#"