1#![cfg(feature = "graphiql")]
6#![cfg_attr(docsrs, doc(cfg(feature = "graphiql")))]
7
8use http::HeaderValue;
9use http::header;
10
11use crate::body::TakoBody;
12use crate::responder::Responder;
13use crate::types::Response;
14
15pub struct GraphiQL(pub(crate) String);
17
18impl Responder for GraphiQL {
19 fn into_response(self) -> Response {
20 let mut res = Response::new(TakoBody::from(self.0));
21 res.headers_mut().insert(
22 header::CONTENT_TYPE,
23 HeaderValue::from_static("text/html; charset=utf-8"),
24 );
25 res
26 }
27}
28
29pub fn graphiql(endpoint: &str, subscription_endpoint: Option<&str>) -> GraphiQL {
34 let mut builder = async_graphql::http::GraphiQLSource::build().endpoint(endpoint);
35 if let Some(ws) = subscription_endpoint {
36 builder = builder.subscription_endpoint(ws);
37 }
38 GraphiQL(builder.finish())
39}