-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
noharu36
authored and
noharu36
committed
Jul 15, 2024
1 parent
b171e69
commit 6b8962b
Showing
3 changed files
with
28 additions
and
24 deletions.
There are no files selected for viewing
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,26 +1,38 @@ | ||
use crate::models; | ||
use crate::models::test::TestObj; | ||
use crate::usecase; | ||
use async_graphql::Object; | ||
use async_graphql::{Error, InputObject, MergedObject, Object, SimpleObject}; | ||
|
||
#[derive(Default)] | ||
pub struct TestQuery; | ||
|
||
#[Object] | ||
impl TestQuery { | ||
async fn get_obj(&self) -> models::test::TestObj { | ||
async fn obj(&self) -> TestObj { | ||
usecase::test::get_obj() | ||
} | ||
} | ||
|
||
#[derive(Default, MergedObject)] | ||
pub struct TestMutation(CreateTestObjMutation); | ||
|
||
#[derive(Default)] | ||
pub struct TestMutation; | ||
pub struct CreateTestObjMutation; | ||
|
||
#[derive(InputObject)] | ||
pub struct CreateTestObjInput { | ||
pub name: String, | ||
pub num: usize, | ||
} | ||
|
||
#[derive(SimpleObject, Debug)] | ||
pub struct CreateTestObjPayload { | ||
pub obj: TestObj, | ||
} | ||
|
||
#[Object] | ||
impl TestMutation { | ||
async fn create_obj( | ||
&self, | ||
input_obj: models::test::CreateTestObjInput, | ||
) -> Result<models::test::TestObj, std::io::Error> { | ||
usecase::test::create_obj(input_obj) | ||
impl CreateTestObjMutation { | ||
async fn create_obj(&self, input: CreateTestObjInput) -> Result<CreateTestObjPayload, Error> { | ||
let obj = usecase::test::create_obj(input.name, input.num)?; | ||
Ok(CreateTestObjPayload { obj }) | ||
} | ||
} |
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,14 +1,8 @@ | ||
use async_graphql::{InputObject, SimpleObject}; | ||
use async_graphql::SimpleObject; | ||
|
||
#[derive(SimpleObject, Debug)] | ||
pub struct TestObj { | ||
pub id: String, | ||
pub name: String, | ||
pub num: usize, | ||
} | ||
|
||
#[derive(InputObject)] | ||
pub struct CreateTestObjInput { | ||
pub name: String, | ||
pub num: usize, | ||
} |
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