-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): introduce "UserRegister" for client (#206)
- Loading branch information
1 parent
1d7f8c4
commit f8541bf
Showing
9 changed files
with
132 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
mod modules; | ||
|
||
pub use modules::*; | ||
|
||
use auth::AuthClient; | ||
|
||
pub struct Client { | ||
pub auth: AuthClient, | ||
} | ||
|
||
impl Default for Client { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl Client { | ||
pub fn new() -> Self { | ||
Self { | ||
auth: AuthClient::new(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
pub mod token_create; | ||
pub mod user_register; | ||
|
||
use reqwest::Client; | ||
|
||
pub struct AuthClient { | ||
client: Client, | ||
} | ||
|
||
impl Default for AuthClient { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl AuthClient { | ||
pub fn new() -> Self { | ||
Self { | ||
client: Client::new(), | ||
} | ||
} | ||
|
||
pub async fn token_create(&self, email: String, password: String) -> token_create::TokenCreate { | ||
token_create::token_create(&self.client, email, password).await | ||
} | ||
|
||
pub async fn user_register( | ||
&self, | ||
input: user_register::UserRegisterInput, | ||
) -> user_register::UserRegister { | ||
user_register::user_register(&self.client, input).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
crates/client/src/modules/auth/user_register/UserRegister.gql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
mutation UserRegister($input: UserRegisterInput!) { | ||
userRegister(input: $input) { | ||
user { | ||
id | ||
name | ||
surname | ||
username | ||
createdAt | ||
updatedAt | ||
} | ||
error { | ||
code | ||
message | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use graphql_client::reqwest::post_graphql; | ||
use graphql_client::GraphQLQuery; | ||
use pxid::Pxid; | ||
use reqwest::Client; | ||
|
||
use townhall::user::model::Email; | ||
use user_register::{UserRegisterUserRegisterError, UserRegisterUserRegisterUser}; | ||
|
||
pub use crate::auth::user_register::user_register::UserRegisterInput; | ||
|
||
use crate::DateTime; | ||
|
||
#[derive(GraphQLQuery)] | ||
#[graphql( | ||
response_derives = "Debug", | ||
schema_path = "schema.json", | ||
query_path = "src/modules/auth/user_register/UserRegister.gql" | ||
)] | ||
pub struct UserRegister { | ||
pub user: Option<UserRegisterUserRegisterUser>, | ||
pub error: Option<UserRegisterUserRegisterError>, | ||
} | ||
|
||
pub async fn user_register(client: &Client, input: UserRegisterInput) -> UserRegister { | ||
let variables = user_register::Variables { input }; | ||
let res = post_graphql::<UserRegister, _>(client, "http://127.0.0.1:7878/graphql", variables) | ||
.await | ||
.unwrap(); | ||
let data = res.data.unwrap().user_register; | ||
|
||
UserRegister { | ||
user: data.user, | ||
error: data.error, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
pub mod auth; | ||
|
||
pub(crate) type DateTime = chrono::DateTime<chrono::Utc>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters