Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit db81824

Browse files
committed
feat(gql): Allow getting group information
1 parent 2aeb22d commit db81824

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

Diff for: src/gql/user.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use async_graphql::{Context, Object, Result, SimpleObject};
1+
use async_graphql::{ComplexObject, Context, Object, Result, SimpleObject};
22
use ecow::EcoString;
33

44
use super::error::Error;
@@ -31,6 +31,7 @@ impl UserQuery {
3131
}
3232

3333
#[derive(Debug, Clone, SimpleObject)]
34+
#[graphql(complex)]
3435
pub struct User {
3536
pub user_id: String,
3637
pub group_id: Option<i64>,
@@ -48,3 +49,40 @@ impl From<db::User> for User {
4849
}
4950
}
5051
}
52+
53+
#[ComplexObject]
54+
impl User {
55+
async fn group<'ctx>(&self, ctx: &Context<'ctx>) -> Result<Option<Group>> {
56+
tracing::debug!("Running GraphQL query 'group'");
57+
58+
let Some(group_id) = self.group_id else {
59+
return Ok(None);
60+
};
61+
62+
let pool = ctx.data::<db::Pool>()?;
63+
let group = db::get_group(pool, group_id).await?;
64+
65+
Ok(Some(group.into()))
66+
}
67+
}
68+
69+
#[derive(SimpleObject)]
70+
pub struct Group {
71+
pub group_id: i64,
72+
pub name: String,
73+
pub description: String,
74+
pub created_at: chrono::DateTime<chrono::Utc>,
75+
pub updated_at: chrono::DateTime<chrono::Utc>,
76+
}
77+
78+
impl From<db::Group> for Group {
79+
fn from(group: db::Group) -> Self {
80+
Self {
81+
group_id: group.group_id,
82+
name: group.name,
83+
description: group.description,
84+
created_at: group.created_at,
85+
updated_at: group.updated_at,
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)