aboutsummaryrefslogtreecommitdiffstats
path: root/src/services/graphql/contact.ts
blob: de078b92530a6e1dc5e2b8a1a0d3eb5760e73a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { SendMailInput } from '@ts/types/graphql/mutations';
import { fetchAPI } from './api';
import { sendMailMutation } from './contact.mutation';

export type SentEmail = {
  clientMutationId: string;
  message: string;
  origin: string;
  replyTo: string;
  sent: boolean;
};

/**
 * Send an email using GraphQL API.
 *
 * @param {SendMailInput} data - The mail data.
 * @returns {Promise<SentEmail>} The mutation response.
 */
export const sendMail = async (data: SendMailInput): Promise<SentEmail> => {
  const response = await fetchAPI<SentEmail, typeof sendMailMutation>({
    query: sendMailMutation,
    variables: { ...data },
  });

  return response.sendEmail;
};