You should use graphql client libraries, such as Apollo GraphQL and URQL.
reference: LogRocket - GraphQL clients for JavaScript and NodeJS
For example, if you use Apollo GraphQL, first you install it with :
npm install @apollo/client graphql
import { gql, useMutation } from '@apollo/client';
// Define mutation
const CREATE_REVEIW = gql`
mutation {
createReveiw(input: { data: {body:“the”,title: “avitest”, rating: 5} }) {
reveiw {
body
title
rating
}
}
}
`;
function MyComponent() {
// Pass mutation to useMutation
const [createReveiwFunction, { data, loading, error }] = useMutation(CREATE_REVEIW);}
