Renamed id to username for better dx

This commit is contained in:
Dreaded_X 2025-03-19 02:49:05 +01:00
parent f3010febdc
commit fac8e44b24
Signed by: Dreaded_X
GPG Key ID: FA5F485356B0D2D4
6 changed files with 25 additions and 25 deletions

View File

@ -3,13 +3,13 @@ pub(crate) mod schema {}
#[derive(cynic::QueryVariables, Debug)]
pub struct DeleteUserVariables<'a> {
pub id: &'a str,
pub username: &'a str,
}
#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "DeleteUserVariables")]
pub struct DeleteUser {
#[arguments(userId: $id)]
#[arguments(userId: $username)]
pub delete_user: Success,
}
@ -20,38 +20,38 @@ pub struct Success {
#[derive(cynic::QueryVariables, Debug)]
pub struct CreateUserVariables<'a> {
pub id: &'a str,
pub username: &'a str,
}
#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "CreateUserVariables")]
pub struct CreateUser {
#[arguments(user: { email: $id, id: $id })]
#[arguments(user: { email: $username, id: $username })]
pub create_user: User,
}
#[derive(cynic::QueryVariables, Debug)]
pub struct AddUserToGroupVariables<'a> {
pub group: i32,
pub id: &'a str,
pub username: &'a str,
}
#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "AddUserToGroupVariables")]
pub struct AddUserToGroup {
#[arguments(groupId: $group, userId: $id)]
#[arguments(groupId: $group, userId: $username)]
pub add_user_to_group: Success,
}
#[derive(cynic::QueryVariables, Debug)]
pub struct GetUserVariables<'a> {
pub id: &'a str,
pub username: &'a str,
}
#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Query", variables = "GetUserVariables")]
pub struct GetUser {
#[arguments(userId: $id)]
#[arguments(userId: $username)]
pub user: User,
}
@ -74,14 +74,14 @@ mod tests {
#[test]
fn delete_user_gql_output() {
let operation = DeleteUser::build(DeleteUserVariables { id: "user" });
let operation = DeleteUser::build(DeleteUserVariables { username: "user" });
insta::assert_snapshot!(operation.query);
}
#[test]
fn create_user_gql_output() {
let operation = CreateUser::build(CreateUserVariables { id: "user" });
let operation = CreateUser::build(CreateUserVariables { username: "user" });
insta::assert_snapshot!(operation.query);
}
@ -89,7 +89,7 @@ mod tests {
#[test]
fn add_user_to_group_gql_output() {
let operation = AddUserToGroup::build(AddUserToGroupVariables {
id: "user",
username: "user",
group: 3,
});
@ -98,7 +98,7 @@ mod tests {
#[test]
fn get_user_gql_output() {
let operation = GetUser::build(GetUserVariables { id: "user" });
let operation = GetUser::build(GetUserVariables { username: "user" });
insta::assert_snapshot!(operation.query);
}

View File

@ -1,9 +1,9 @@
---
source: src/lib.rs
source: queries/src/lib.rs
expression: operation.query
---
mutation AddUserToGroup($group: Int!, $id: String!) {
addUserToGroup(groupId: $group, userId: $id) {
mutation AddUserToGroup($group: Int!, $username: String!) {
addUserToGroup(groupId: $group, userId: $username) {
ok
}
}

View File

@ -2,8 +2,8 @@
source: queries/src/lib.rs
expression: operation.query
---
mutation CreateUser($id: String!) {
createUser(user: {email: $id, id: $id}) {
mutation CreateUser($username: String!) {
createUser(user: {email: $username, id: $username}) {
id
groups {
id

View File

@ -1,9 +1,9 @@
---
source: src/lib.rs
source: queries/src/lib.rs
expression: operation.query
---
mutation DeleteUser($id: String!) {
deleteUser(userId: $id) {
mutation DeleteUser($username: String!) {
deleteUser(userId: $username) {
ok
}
}

View File

@ -2,8 +2,8 @@
source: queries/src/lib.rs
expression: operation.query
---
query GetUser($id: String!) {
user(userId: $id) {
query GetUser($username: String!) {
user(userId: $username) {
id
groups {
id

View File

@ -101,7 +101,7 @@ pub struct LldapClient {
impl LldapClient {
pub async fn get_user(&self, username: &str) -> Result<User> {
let operation = GetUser::build(GetUserVariables { id: username });
let operation = GetUser::build(GetUserVariables { username });
let response = self
.client
.post(format!("{}/api/graphql", self.url))
@ -112,7 +112,7 @@ impl LldapClient {
}
pub async fn create_user(&self, username: &str) -> Result<User> {
let operation = CreateUser::build(CreateUserVariables { id: username });
let operation = CreateUser::build(CreateUserVariables { username });
let response = self
.client
@ -124,7 +124,7 @@ impl LldapClient {
}
pub async fn delete_user(&self, username: &str) -> Result<()> {
let operation = DeleteUser::build(DeleteUserVariables { id: username });
let operation = DeleteUser::build(DeleteUserVariables { username });
let response = self
.client