From b46715650bbc7298d4860052d0663da9aa730cea Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Sun, 17 Oct 2021 16:28:50 +0000 Subject: [PATCH] Add graphql field `get_user_id` Given a username it will give you this user's ID --- src/graphql.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/graphql.rs b/src/graphql.rs index 76ae1cb..b462261 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -373,6 +373,16 @@ impl Query { #[graphql_object(context = Context)] impl Query { + async fn get_user_id(context: &Context, username: String) -> FieldResult { + sqlx::query(format!( + r#"SELECT id FROM users WHERE user_name="{}""#, + username + ).as_str()).fetch_one(&context.db).await? + .try_get::("id") + .map(ID::new) + .map_err(FieldError::from) + } + async fn users(context: &Context) -> FieldResult> { Self::users_sqlx_result(context).await.map_err(FieldError::from) }