1import { gql, useMutation } from '@apollo/client';
2
3const ADD_TODO = gql`
4 mutation AddTodo($type: String!) {
5 addTodo(type: $type) {
6 id
7 type
8 }
9 }
10`;
11
12
13function AddTodo() {
14 let input;
15 const [addTodo, { data }] = useMutation(ADD_TODO);
16
17 return (
18 <div>
19 <form
20 onSubmit={e => {
21 e.preventDefault();
22 addTodo({ variables: { type: input.value } });
23 input.value = '';
24 }}
25 >
26 <input
27 ref={node => {
28 input = node;
29 }}
30 />
31 <button type="submit">Add Todo</button>
32 </form>
33 </div>
34 );
35}