Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
noharu36 authored and noharu36 committed Jul 15, 2024
1 parent b171e69 commit 6b8962b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
32 changes: 22 additions & 10 deletions src/handler/test_handler.rs
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 })
}
}
8 changes: 1 addition & 7 deletions src/models/test.rs
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,
}
12 changes: 5 additions & 7 deletions src/usecase/test.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use crate::models;
use crate::models::test::TestObj;

pub fn get_obj() -> models::test::TestObj {
models::test::TestObj {
pub fn get_obj() -> TestObj {
TestObj {
id: "test".to_string(),
name: "test_name".to_string(),
num: 1,
}
}

pub fn create_obj(
models::test::CreateTestObjInput { name, num }: models::test::CreateTestObjInput,
) -> Result<models::test::TestObj, std::io::Error> {
let input = models::test::TestObj {
pub fn create_obj(name: String, num: usize) -> Result<TestObj, std::io::Error> {
let input = TestObj {
id: "test_input".to_string(),
name,
num,
Expand Down

0 comments on commit 6b8962b

Please sign in to comment.