Renamed id to username for better dx
This commit is contained in:
parent
f3010febdc
commit
fac8e44b24
|
@ -3,13 +3,13 @@ pub(crate) mod schema {}
|
||||||
|
|
||||||
#[derive(cynic::QueryVariables, Debug)]
|
#[derive(cynic::QueryVariables, Debug)]
|
||||||
pub struct DeleteUserVariables<'a> {
|
pub struct DeleteUserVariables<'a> {
|
||||||
pub id: &'a str,
|
pub username: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
#[cynic(graphql_type = "Mutation", variables = "DeleteUserVariables")]
|
#[cynic(graphql_type = "Mutation", variables = "DeleteUserVariables")]
|
||||||
pub struct DeleteUser {
|
pub struct DeleteUser {
|
||||||
#[arguments(userId: $id)]
|
#[arguments(userId: $username)]
|
||||||
pub delete_user: Success,
|
pub delete_user: Success,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,38 +20,38 @@ pub struct Success {
|
||||||
|
|
||||||
#[derive(cynic::QueryVariables, Debug)]
|
#[derive(cynic::QueryVariables, Debug)]
|
||||||
pub struct CreateUserVariables<'a> {
|
pub struct CreateUserVariables<'a> {
|
||||||
pub id: &'a str,
|
pub username: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
#[cynic(graphql_type = "Mutation", variables = "CreateUserVariables")]
|
#[cynic(graphql_type = "Mutation", variables = "CreateUserVariables")]
|
||||||
pub struct CreateUser {
|
pub struct CreateUser {
|
||||||
#[arguments(user: { email: $id, id: $id })]
|
#[arguments(user: { email: $username, id: $username })]
|
||||||
pub create_user: User,
|
pub create_user: User,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryVariables, Debug)]
|
#[derive(cynic::QueryVariables, Debug)]
|
||||||
pub struct AddUserToGroupVariables<'a> {
|
pub struct AddUserToGroupVariables<'a> {
|
||||||
pub group: i32,
|
pub group: i32,
|
||||||
pub id: &'a str,
|
pub username: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
#[cynic(graphql_type = "Mutation", variables = "AddUserToGroupVariables")]
|
#[cynic(graphql_type = "Mutation", variables = "AddUserToGroupVariables")]
|
||||||
pub struct AddUserToGroup {
|
pub struct AddUserToGroup {
|
||||||
#[arguments(groupId: $group, userId: $id)]
|
#[arguments(groupId: $group, userId: $username)]
|
||||||
pub add_user_to_group: Success,
|
pub add_user_to_group: Success,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryVariables, Debug)]
|
#[derive(cynic::QueryVariables, Debug)]
|
||||||
pub struct GetUserVariables<'a> {
|
pub struct GetUserVariables<'a> {
|
||||||
pub id: &'a str,
|
pub username: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
#[cynic(graphql_type = "Query", variables = "GetUserVariables")]
|
#[cynic(graphql_type = "Query", variables = "GetUserVariables")]
|
||||||
pub struct GetUser {
|
pub struct GetUser {
|
||||||
#[arguments(userId: $id)]
|
#[arguments(userId: $username)]
|
||||||
pub user: User,
|
pub user: User,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,14 +74,14 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn delete_user_gql_output() {
|
fn delete_user_gql_output() {
|
||||||
let operation = DeleteUser::build(DeleteUserVariables { id: "user" });
|
let operation = DeleteUser::build(DeleteUserVariables { username: "user" });
|
||||||
|
|
||||||
insta::assert_snapshot!(operation.query);
|
insta::assert_snapshot!(operation.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_user_gql_output() {
|
fn create_user_gql_output() {
|
||||||
let operation = CreateUser::build(CreateUserVariables { id: "user" });
|
let operation = CreateUser::build(CreateUserVariables { username: "user" });
|
||||||
|
|
||||||
insta::assert_snapshot!(operation.query);
|
insta::assert_snapshot!(operation.query);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn add_user_to_group_gql_output() {
|
fn add_user_to_group_gql_output() {
|
||||||
let operation = AddUserToGroup::build(AddUserToGroupVariables {
|
let operation = AddUserToGroup::build(AddUserToGroupVariables {
|
||||||
id: "user",
|
username: "user",
|
||||||
group: 3,
|
group: 3,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_user_gql_output() {
|
fn get_user_gql_output() {
|
||||||
let operation = GetUser::build(GetUserVariables { id: "user" });
|
let operation = GetUser::build(GetUserVariables { username: "user" });
|
||||||
|
|
||||||
insta::assert_snapshot!(operation.query);
|
insta::assert_snapshot!(operation.query);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: src/lib.rs
|
source: queries/src/lib.rs
|
||||||
expression: operation.query
|
expression: operation.query
|
||||||
---
|
---
|
||||||
mutation AddUserToGroup($group: Int!, $id: String!) {
|
mutation AddUserToGroup($group: Int!, $username: String!) {
|
||||||
addUserToGroup(groupId: $group, userId: $id) {
|
addUserToGroup(groupId: $group, userId: $username) {
|
||||||
ok
|
ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
source: queries/src/lib.rs
|
source: queries/src/lib.rs
|
||||||
expression: operation.query
|
expression: operation.query
|
||||||
---
|
---
|
||||||
mutation CreateUser($id: String!) {
|
mutation CreateUser($username: String!) {
|
||||||
createUser(user: {email: $id, id: $id}) {
|
createUser(user: {email: $username, id: $username}) {
|
||||||
id
|
id
|
||||||
groups {
|
groups {
|
||||||
id
|
id
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: src/lib.rs
|
source: queries/src/lib.rs
|
||||||
expression: operation.query
|
expression: operation.query
|
||||||
---
|
---
|
||||||
mutation DeleteUser($id: String!) {
|
mutation DeleteUser($username: String!) {
|
||||||
deleteUser(userId: $id) {
|
deleteUser(userId: $username) {
|
||||||
ok
|
ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
source: queries/src/lib.rs
|
source: queries/src/lib.rs
|
||||||
expression: operation.query
|
expression: operation.query
|
||||||
---
|
---
|
||||||
query GetUser($id: String!) {
|
query GetUser($username: String!) {
|
||||||
user(userId: $id) {
|
user(userId: $username) {
|
||||||
id
|
id
|
||||||
groups {
|
groups {
|
||||||
id
|
id
|
||||||
|
|
|
@ -101,7 +101,7 @@ pub struct LldapClient {
|
||||||
|
|
||||||
impl LldapClient {
|
impl LldapClient {
|
||||||
pub async fn get_user(&self, username: &str) -> Result<User> {
|
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
|
let response = self
|
||||||
.client
|
.client
|
||||||
.post(format!("{}/api/graphql", self.url))
|
.post(format!("{}/api/graphql", self.url))
|
||||||
|
@ -112,7 +112,7 @@ impl LldapClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_user(&self, username: &str) -> Result<User> {
|
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
|
let response = self
|
||||||
.client
|
.client
|
||||||
|
@ -124,7 +124,7 @@ impl LldapClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_user(&self, username: &str) -> Result<()> {
|
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
|
let response = self
|
||||||
.client
|
.client
|
||||||
|
|
Loading…
Reference in New Issue
Block a user