import { gql, useQuery } from '@apollo/client'; interface PostQuery { posts: { id: string title: string author?: { id: string firstName: string lastName: string } }[] } const postsQueryDocument = gql` query Posts { posts { id title author { id firstName lastName } } } ` const Posts = () => { const { data } = useQuery<PostQuery>(postsQueryDocument); // ... }
![GraphQL Code Generator 導入する](https://cdn-ak-scissors.b.st-hatena.com/image/square/c6f031b0ed20839cb00217fddf39571d7be23631/height=288;version=1;width=512/https%3A%2F%2Fzenn-dev.github.io%2Fdefault-avatars%2Fdark%2Fn.png)