25 lines
611 B
Rust
25 lines
611 B
Rust
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
|
|
use axum::{
|
|
extract::Extension,
|
|
http::StatusCode,
|
|
response::{Html, IntoResponse},
|
|
};
|
|
|
|
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
|
|
use graphql::ComoSchema;
|
|
|
|
pub mod graphql;
|
|
|
|
pub async fn graphql_handler(
|
|
schema: Extension<ComoSchema>,
|
|
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("/graphql")))
|
|
}
|