Enfrenté el error grapql 400 cuando intento dejar un comentario en el sitio web de mi blog. Estoy usando graph cms, graphql y next.js. No se que debo hacer para solucionarlo. Por favor, ayúdame a corregir este error.
export const submitComment = async (obj) => { const result = await fetch('/api/comments', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(obj), }); return result.json(); }; import { GraphQLClient, gql } from 'graphql-request'; const graphqlAPI = process.env.NEXT_PUBLIC_GRAPHCMS_ENDPOINT; /** ************************************************************* * Any file inside the folder pages/api is mapped to /api/* and * * will be treated as an API endpoint instead of a page. * *************************************************************** */ // export a default function for API route to work export default async function asynchandler(req, res) { const graphQLClient = new GraphQLClient((graphqlAPI), { headers: { authorization: `Bearer ${process.env.GRAPHCMS_TOKEN}`, }, }); const query = gql` mutation CreateComment($name: String!, $email: String!, $comment: String!, $slug: String!) { createComment(data: {name: $name, email: $email, comment: $comment, post: {connect: {slug: $slug}}}) { id } } `; const result = await graphQLClient.request(query, { name: req.body.name, email: req.body.email, comment: req.body.comment, slug: req.body.slug, }); return res.status(200).send(result); }