como/como_gql/src/lib.rs

38 lines
714 B
Rust
Raw Normal View History

2022-10-04 11:06:48 +02:00
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use axum::{
extract::Extension,
2022-10-04 11:07:14 +02:00
http::{StatusCode},
2022-10-04 11:06:48 +02:00
response::{Html, IntoResponse},
};
2022-10-04 11:07:14 +02:00
2022-10-04 11:06:48 +02:00
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
};
use axum_sessions::{
2022-10-04 11:07:14 +02:00
extractors::{ReadableSession},
2022-10-04 11:06:48 +02:00
};
use graphql::CibusSchema;
2022-10-04 11:07:14 +02:00
2022-10-04 11:06:48 +02:00
pub mod graphql;
pub async fn graphql_handler(
schema: Extension<CibusSchema>,
2022-10-04 11:07:14 +02:00
_session: ReadableSession,
2022-10-04 11:06:48 +02:00
req: GraphQLRequest,
) -> Result<GraphQLResponse, StatusCode> {
let req = req.into_inner();
Ok(schema.execute(req).await.into())
}
pub async fn graphql_playground() -> impl IntoResponse {
Html(playground_source(GraphQLPlaygroundConfig::new("/")))
}