mirror of
https://github.com/rjNemo/react_template
synced 2026-06-06 06:26:41 +00:00
update graphql schema and queries
This commit is contained in:
parent
b72c13100a
commit
c3f0e7c340
3 changed files with 23 additions and 6 deletions
|
|
@ -5,6 +5,10 @@ schema {
|
|||
mutation: Mutations
|
||||
}
|
||||
|
||||
type CloseTodo {
|
||||
todo: TodoType
|
||||
}
|
||||
|
||||
type CreateTodo {
|
||||
todo: TodoType
|
||||
}
|
||||
|
|
@ -14,15 +18,22 @@ type DeleteTodo {
|
|||
}
|
||||
|
||||
type Mutations {
|
||||
closeTodo(todoId: String!): CloseTodo
|
||||
createTodo(title: String = ""): CreateTodo
|
||||
deleteTodo(todoId: String!): DeleteTodo
|
||||
updateTodo(todo: TodoInputType): UpdateTodo
|
||||
}
|
||||
|
||||
type TodoListResponseField {
|
||||
errorMessage: String
|
||||
isSuccess: Boolean
|
||||
todos: [TodoType]
|
||||
}
|
||||
|
||||
"Defines the query and how to interact with"
|
||||
type TodoQuery {
|
||||
getTodo(todoId: String!): TodoResponseField
|
||||
listTodos: [TodoType]
|
||||
listTodos: TodoListResponseField
|
||||
}
|
||||
|
||||
type TodoResponseField {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export const Home: FC = () => {
|
|||
!loading &&
|
||||
!!data && (
|
||||
<>
|
||||
<TodoList todos={data.listTodos} />
|
||||
<TodoList todos={data.listTodos.todos} />
|
||||
<form onSubmit={handleSubmit}>
|
||||
<input type="text" value={todoTitle} onChange={handleChange} />
|
||||
<Button
|
||||
|
|
|
|||
|
|
@ -5,14 +5,20 @@ import Todo from '../models/todo';
|
|||
const LIST_TODOS = gql`
|
||||
query ListAll {
|
||||
listTodos {
|
||||
todoId
|
||||
title
|
||||
isDone
|
||||
... on TodoListResponseField {
|
||||
todos {
|
||||
todoId
|
||||
title
|
||||
isDone
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const useListTodos = () => {
|
||||
const { loading, error, data } = useQuery<{ listTodos: Todo[] }>(LIST_TODOS);
|
||||
const { loading, error, data } = useQuery<{ listTodos: { todos: Todo[] } }>(
|
||||
LIST_TODOS
|
||||
);
|
||||
return { loading, error, data };
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue