import type { Nullable, WPComment } from '../../../types'; import { fetchGraphQL, getGraphQLUrl } from '../../../utils/helpers'; export type CreateCommentPayload = { clientMutationId: Nullable; success: boolean; comment: Nullable>; }; export type CreateCommentResponse = { createComment: CreateCommentPayload; }; export const createCommentMutation = `mutation CreateComment($input: CreateCommentInput!) { createComment(input: $input) { clientMutationId comment { approved } success } }`; export type CreateCommentInput = { author: string; authorEmail: string; authorUrl: string; clientMutationId: string; commentOn: number; content: string; parent?: number; }; /** * Create a new comment using GraphQL API. * * @param {CreateCommentInput} input - The comment data. * @returns {Promise} The created comment. */ export const createComment = async ( input: CreateCommentInput ): Promise => { const response = await fetchGraphQL({ query: createCommentMutation, url: getGraphQLUrl(), variables: { input }, }); return response.createComment; };