Skip to content
Clone
56417bd
41 lines 1001 B Rust
use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema};
use std::sync::Arc;
use crate::service::GitService;
use super::context::{RepoCtx, map_git};
use super::repo::Repo;
pub type GitSchema = Schema<Query, EmptyMutation, EmptySubscription>;
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<Repo, async_graphql::Error> {
let svc = ctx.data_unchecked::<Arc<GitService>>().clone();
let ctx_data = svc
.context(space_name.clone(), repo_name.clone())
.await
.map_err(map_git)?;
let baby = svc.baby(&ctx_data);
Ok(Repo {
inner: RepoCtx {
svc,
ctx: ctx_data,
space_name,
repo_name,
baby,
},
})
}
}