Using the createBook Mutation
Explore how to integrate the createBook mutation in a React application using Apollo Client. Understand generating types with GraphQL Code Generator, importing mutation hooks, and executing mutations to add new data through a form.
We'll cover the following...
We'll cover the following...
Generating types
To add the createBook mutation to our form, we import the gql function and use it at the top of our components/books/CreateForm.tsx file.
import { gql } from "@apollo/client";const createBookQuery = gql`mutation createBook($title: String!) {createBook(title: $title) {idtitle}}`;
Importing the gql function and using it in components/books/CreateForm.tsx
Once this has been added, we can run the GraphQL Code Generator to regenerate our GraphQL types. The following ...