#![cfg(feature = "graphiql")]
#![cfg_attr(docsrs, doc(cfg(feature = "graphiql")))]
use http::HeaderValue;
use http::header;
use crate::body::TakoBody;
use crate::responder::Responder;
use crate::types::Response;
pub struct GraphiQL(pub(crate) String);
impl Responder for GraphiQL {
fn into_response(self) -> Response {
let mut res = Response::new(TakoBody::from(self.0));
res.headers_mut().insert(
header::CONTENT_TYPE,
HeaderValue::from_static("text/html; charset=utf-8"),
);
res
}
}
pub fn graphiql(endpoint: &str, subscription_endpoint: Option<&str>) -> GraphiQL {
let mut builder = async_graphql::http::GraphiQLSource::build().endpoint(endpoint);
if let Some(ws) = subscription_endpoint {
builder = builder.subscription_endpoint(ws);
}
GraphiQL(builder.finish())
}