use async_graphql::{Context, EmptyMutation, EmptySubscription, ErrorExtensions, Object, Schema}; use std::sync::Arc; use uuid::Uuid; use crate::service::GitService; use crate::share::access::authorize_repo_access; use crate::share::errors::GitError; use super::context::{RepoCtx, map_git}; use super::repo::Repo; pub type GitSchema = Schema; pub struct Query; #[Object] impl Query { async fn api_version(&self) -> &'static str { "1.0.0" } async fn repo( &self, ctx: &Context<'_>, space_name: String, repo_name: String, ) -> Result { let svc = ctx.data_unchecked::>().clone(); let ctx_data = svc .context(space_name.clone(), repo_name.clone()) .await .map_err(map_git)?; if ctx_data.model.is_private { let uid = ctx .data::>() .ok() .and_then(|o| *o) .ok_or_else(|| GitError::Unauthorized.extend())?; authorize_repo_access(&svc, uid, &ctx_data, false, false) .await .map_err(map_git)?; } let baby = svc.baby(&ctx_data); Ok(Repo { inner: RepoCtx { svc, ctx: ctx_data, space_name, repo_name, baby, }, }) } }