Answers for "watchquery"

0

watchquery

Copy
// type for a returning Todo from ADD_TODO mutation
+ interface Todo {
+   id: number;
+   title: string;
+   created_at: Date;
+   is_completed: boolean;
+ }
+
+ // type for the full result of ADD_TODO mutation
+ interface InsertTodoResult {
+   insert_todos: {
+     affected_rows: number;
+     returning: Todo[];
+   };
+ }
...

export class TodoInput {
    @Input() isPublic: any = false;
  + todoInput: any= '';
  + loading = true;

  + constructor(private apollo: Apollo) {}

    addTodo(e) {
      e.preventDefault();
  +    this.apollo.mutate<InsertTodoResult>({
  +      mutation: ADD_TODO,
  +      variables: {
  +        todo: this.todoInput,
  +        isPublic: this.isPublic
  +      },
  +    }).subscribe(({ data }) => {
  +      this.loading = false;
  +      this.todoInput = '';
  +    },(error) => {
  +      console.log('there was an error sending the query', error);
  +    });
    }
}
Posted by: Guest on March-18-2022

Browse Popular Code Answers by Language