Using mutations on the frontend
As we learned in the previous chapter, mutations in GraphQL are used to change the state of the backend (similar to POST requests in REST). We are now going to implement mutations for signing up and logging in to our app.
Follow these steps:
- Create a new
src/api/graphql/users.jsfile and importgql:import { gql } from '@apollo/client/core/index.js' - Then, define a new
SIGNUP_USERmutation, which takes a username and a password and calls thesignupUsermutation field:export const SIGNUP_USER = gql`   mutation signupUser($username: String!, $password: String!) {     signupUser(username: $username, password: $password) {       username     }   } ` - Edit
src/pages/Signup.jsxand replace the currentuseMutationhook from TanStack React Query with the one from Apollo Client. As we did before foruseQuery, we are also going to rename this hook...