#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(any(doc, test), doc = include_str!("../README.md"))]
#![cfg_attr(not(any(doc, test)), doc = env!("CARGO_PKG_NAME"))]
#![cfg_attr(
test,
expect(unused_crate_dependencies, reason = "examples and integration tests")
)]
mod for_minimal_versions_check_only {
use bytes as _;
}
pub mod extract;
pub mod response;
#[cfg(feature = "subscriptions")]
pub mod subscriptions;
use std::future;
use axum::{extract::Extension, response::Html};
use juniper_graphql_ws::Schema;
use self::{extract::JuniperRequest, response::JuniperResponse};
#[cfg(feature = "subscriptions")]
#[doc(inline)]
pub use self::subscriptions::{graphql_transport_ws, graphql_ws, ws};
pub async fn graphql<S>(
Extension(schema): Extension<S>,
JuniperRequest(req): JuniperRequest<S::ScalarValue>,
) -> JuniperResponse<S::ScalarValue>
where
S: Schema, S::Context: Default,
{
JuniperResponse(
req.execute(schema.root_node(), &S::Context::default())
.await,
)
}
pub fn graphiql<'a, T: Into<Option<&'a str>>>(
graphql_endpoint_url: &str,
subscriptions_endpoint_url: T,
) -> impl FnOnce() -> future::Ready<Html<String>> + Clone + Send + use<T> {
let html = Html(juniper::http::graphiql::graphiql_source(
graphql_endpoint_url,
subscriptions_endpoint_url.into(),
));
|| future::ready(html)
}
pub fn playground<'a, T: Into<Option<&'a str>>>(
graphql_endpoint_url: &str,
subscriptions_endpoint_url: T,
) -> impl FnOnce() -> future::Ready<Html<String>> + Clone + Send + use<T> {
let html = Html(juniper::http::playground::playground_source(
graphql_endpoint_url,
subscriptions_endpoint_url.into(),
));
|| future::ready(html)
}