mirror of
https://github.com/rjNemo/react_template
synced 2026-06-06 07:36:42 +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
|
mutation: Mutations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CloseTodo {
|
||||||
|
todo: TodoType
|
||||||
|
}
|
||||||
|
|
||||||
type CreateTodo {
|
type CreateTodo {
|
||||||
todo: TodoType
|
todo: TodoType
|
||||||
}
|
}
|
||||||
|
|
@ -14,15 +18,22 @@ type DeleteTodo {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutations {
|
type Mutations {
|
||||||
|
closeTodo(todoId: String!): CloseTodo
|
||||||
createTodo(title: String = ""): CreateTodo
|
createTodo(title: String = ""): CreateTodo
|
||||||
deleteTodo(todoId: String!): DeleteTodo
|
deleteTodo(todoId: String!): DeleteTodo
|
||||||
updateTodo(todo: TodoInputType): UpdateTodo
|
updateTodo(todo: TodoInputType): UpdateTodo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TodoListResponseField {
|
||||||
|
errorMessage: String
|
||||||
|
isSuccess: Boolean
|
||||||
|
todos: [TodoType]
|
||||||
|
}
|
||||||
|
|
||||||
"Defines the query and how to interact with"
|
"Defines the query and how to interact with"
|
||||||
type TodoQuery {
|
type TodoQuery {
|
||||||
getTodo(todoId: String!): TodoResponseField
|
getTodo(todoId: String!): TodoResponseField
|
||||||
listTodos: [TodoType]
|
listTodos: TodoListResponseField
|
||||||
}
|
}
|
||||||
|
|
||||||
type TodoResponseField {
|
type TodoResponseField {
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export const Home: FC = () => {
|
||||||
!loading &&
|
!loading &&
|
||||||
!!data && (
|
!!data && (
|
||||||
<>
|
<>
|
||||||
<TodoList todos={data.listTodos} />
|
<TodoList todos={data.listTodos.todos} />
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<input type="text" value={todoTitle} onChange={handleChange} />
|
<input type="text" value={todoTitle} onChange={handleChange} />
|
||||||
<Button
|
<Button
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,20 @@ import Todo from '../models/todo';
|
||||||
const LIST_TODOS = gql`
|
const LIST_TODOS = gql`
|
||||||
query ListAll {
|
query ListAll {
|
||||||
listTodos {
|
listTodos {
|
||||||
todoId
|
... on TodoListResponseField {
|
||||||
title
|
todos {
|
||||||
isDone
|
todoId
|
||||||
|
title
|
||||||
|
isDone
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const useListTodos = () => {
|
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 };
|
return { loading, error, data };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue