diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-17 23:28:17 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-17 23:28:17 +0100 |
| commit | efed6c0a820c5c47e097fa29455157bbd318ffca (patch) | |
| tree | 0c52968f8619ce62ba6f442c84dec10fbce4214d /src/services | |
| parent | 42315639d14ead79b5fac04508df8be793bbbc0b (diff) | |
chore: create mutation to send mail from contact form
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/graphql/contact.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/services/graphql/contact.ts b/src/services/graphql/contact.ts new file mode 100644 index 0000000..4699688 --- /dev/null +++ b/src/services/graphql/contact.ts @@ -0,0 +1,49 @@ +import { SendMailReturn, SentEmailResponse } from '@ts/types/contact'; +import { gql } from 'graphql-request'; +import { getGraphQLClient } from './client'; + +export const sendMail: SendMailReturn = async ( + subject: string, + body: string, + replyTo: string, + mutationId: string +) => { + const client = getGraphQLClient(); + const mutation = gql` + mutation SendEmail( + $subject: String! + $body: String! + $replyTo: String! + $mutationId: String! + ) { + sendEmail( + input: { + clientMutationId: $mutationId + body: $body + replyTo: $replyTo + subject: $subject + } + ) { + clientMutationId + message + sent + origin + replyTo + to + } + } + `; + + const variables = { subject, body, replyTo, mutationId }; + + try { + const response: SentEmailResponse = await client.request( + mutation, + variables + ); + return response.sendEmail; + } catch (error) { + console.error(error, undefined, 2); + process.exit(1); + } +}; |
