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, session: Session, schema: axum::extract::Extension, Json(mut request): Json, ) -> Result { request = request.data::>(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, schema: axum::extract::Extension, ) -> Result { let request = async_graphql::Request::new("{ __typename }"); let response = schema.execute(request).await; Ok(Json(response).into_response()) }