-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.ts
44 lines (42 loc) · 1.2 KB
/
api.ts
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { generateClient } from 'aws-amplify/data';
import type { Schema } from '@/amplify/data/resource'; // Caminho do arquivo do esquema criado
const client = generateClient<Schema>({
authMode: 'userPool',
});
export { client };
export default async function SendMessage(messageData: {
content: string,
senderId: string,
receiverId: string,
senderName: string,
receiverName: string,
}) {
const input = {
content: messageData.content,
senderId: messageData.senderId,
receiverId: messageData.receiverId ,
senderName: messageData.senderName,
receiverName: messageData.receiverName
};
try {
const response = await client.graphql({
query: `mutation createChat($input: CreateChatInput!) {
createChat(input: $input) {
id
content
senderId
receiverId
senderName
receiverName
createdAt
}
}`,
variables: { input },
});
console.log("Response:", response)
} catch (err){
console.error(err);
}
}
// Aqui estou importando o Schema criado no amplify/data/resource.ts e passando para o client para a criação do dataClient
// const response = await client.models.Chat.list();