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