b90f48e
use axum::Json;
use axum::extract::State;
use axum::response::IntoResponse;
use session_layer::{Session, SessionUser};
use uuid::Uuid;
use crate::errors::ApiError;
use crate::graphql::GitSchema;
use crate::service::GitService;
#[utoipa::path(
post,
path = "/graphql",
tag = "graphql",
description = "执行仓库只读 GraphQL 查询,并解析器内施加仓库读权限。",
request_body = String,
responses(
(status = 200, description = "graphql execution result")
)
)]
pub async fn graphql_post(
State(_service): State<GitService>,
session: Session,
schema: axum::extract::Extension<GitSchema>,
Json(mut request): Json<async_graphql::Request>,
) -> Result<axum::response::Response, ApiError> {
request = request.data::<Option<Uuid>>(session.uid());
let response = schema.execute(request).await;
Ok(Json(response).into_response())
}
#[utoipa::path(
get,
path = "/graphql",
tag = "graphql",
description = "通过固定内省查询探活 GraphQL 服务。",
responses(
(status = 200, description = "graphql execution result")
)
)]
pub async fn graphql_get(
State(_service): State<GitService>,
schema: axum::extract::Extension<GitSchema>,
) -> Result<axum::response::Response, ApiError> {
let request = async_graphql::Request::new("{ __typename }");
let response = schema.execute(request).await;
Ok(Json(response).into_response())
}