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>
This commit is contained in:
Alexander van Ratingen 2021-02-04 03:17:19 +01:00 committed by GitHub
parent 3b6c3f9c0f
commit 52483718ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View file

@ -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>")]

View file

@ -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,
))
}