...

/

Using the createBook Mutation

Using the createBook Mutation

Learn to use types generated by using GraphQL Code Generator with mutations in a React application to update data on a GraphQL server.

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) {
id
title
}
}
`;
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 ...