Add graphql field get_user_id
Given a username it will give you this user's ID
This commit is contained in:
parent
1ea3e5260c
commit
b46715650b
@ -373,6 +373,16 @@ impl Query {
|
|||||||
|
|
||||||
#[graphql_object(context = Context)]
|
#[graphql_object(context = Context)]
|
||||||
impl Query {
|
impl Query {
|
||||||
|
async fn get_user_id(context: &Context, username: String) -> FieldResult<ID> {
|
||||||
|
sqlx::query(format!(
|
||||||
|
r#"SELECT id FROM users WHERE user_name="{}""#,
|
||||||
|
username
|
||||||
|
).as_str()).fetch_one(&context.db).await?
|
||||||
|
.try_get::<String, _>("id")
|
||||||
|
.map(ID::new)
|
||||||
|
.map_err(FieldError::from)
|
||||||
|
}
|
||||||
|
|
||||||
async fn users(context: &Context) -> FieldResult<Vec<User>> {
|
async fn users(context: &Context) -> FieldResult<Vec<User>> {
|
||||||
Self::users_sqlx_result(context).await.map_err(FieldError::from)
|
Self::users_sqlx_result(context).await.map_err(FieldError::from)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user