From 9586a7200b3961910bab08566ac7ad53106a6168 Mon Sep 17 00:00:00 2001 From: Marie Ramlow Date: Fri, 30 Sep 2022 14:12:09 +0000 Subject: [PATCH 1/2] implement dynamic title for graphiql_v2 --- src/http/graphiql_v2_source.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/http/graphiql_v2_source.rs b/src/http/graphiql_v2_source.rs index 3f4cb8b3..2253517b 100644 --- a/src/http/graphiql_v2_source.rs +++ b/src/http/graphiql_v2_source.rs @@ -18,6 +18,7 @@ pub struct GraphiQLSource<'a> { endpoint: &'a str, subscription_endpoint: Option<&'a str>, headers: Option>, + title: Option<&'a str>, } impl<'a> GraphiQLSource<'a> { @@ -53,6 +54,14 @@ impl<'a> GraphiQLSource<'a> { } } + /// Sets the html document title. + pub fn title(self, title: &'a str) -> GraphiQLSource<'a> { + GraphiQLSource { + title: Some(title), + ..self + } + } + /// Returns a GraphiQL (v2) HTML page. pub fn finish(self) -> String { let graphiql_url = format!("'{}'", self.endpoint); @@ -64,6 +73,7 @@ impl<'a> GraphiQLSource<'a> { Some(headers) => serde_json::to_string(&headers).unwrap(), None => "undefined".into(), }; + let graphiql_title = self.title.unwrap_or("GraphiQL IDE"); r#" @@ -74,7 +84,7 @@ impl<'a> GraphiQLSource<'a> { - GraphiQL IDE + %GRAPHIQL_TITLE%