import { gql } from '@apollo/client';
import { useQuery } from '@apollo/client/react';

type Book = {
  id: string;
  title: string;
  isbn: string;
};

const booksQuery = gql`
  query {
    book {
      id
      title
      isbn
    }
  }
`;

const List: React.FC = () => {
  const { data } = useQuery<{ book: Book[] }>(booksQuery);

  return (
    <table>
      <thead>
        <tr>
          <th>Titel</th>
          <th>ISBN</th>
        </tr>
      </thead>
      <tbody>
        {data?.book.map((book) => (
          <tr key={book.id}>
            <td>{book.title}</td>
            <td>{book.isbn}</td>
          </tr>
        ))}
      </tbody>
    </table>
  );
};

export default List;
