webapp/src/graphql/client/chat.ts

79 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-11-28 13:18:25 +00:00
// inbox
import createChat from '../mutation/chat/chat-create'
import deleteChat from '../mutation/chat/chat-delete'
import markAsRead from '../mutation/chat/chat-mark-as-read'
import createChatMessage from '../mutation/chat/chat-message-create'
import deleteChatMessage from '../mutation/chat/chat-message-delete'
import updateChatMessage from '../mutation/chat/chat-message-update'
import updateChat from '../mutation/chat/chat-update'
import { getPrivateClient } from '../privateGraphQLClient'
import chatMessagesLoadBy from '../query/chat/chat-messages-load-by'
import loadRecipients from '../query/chat/chat-recipients'
import myChats from '../query/chat/chats-load'
import {
Chat,
2023-11-28 15:36:00 +00:00
MutationCreate_ChatArgs,
MutationCreate_MessageArgs,
MutationDelete_ChatArgs,
MutationDelete_MessageArgs,
MutationMark_As_ReadArgs,
MutationUpdate_ChatArgs,
MutationUpdate_MessageArgs,
QueryLoad_ChatsArgs,
QueryLoad_Messages_ByArgs,
QueryLoad_RecipientsArgs,
2023-11-28 13:18:25 +00:00
} from '../schema/chat.gen'
const privateInboxGraphQLClient = getPrivateClient('chat')
export const inboxClient = {
2023-11-28 15:36:00 +00:00
loadChats: async (options: QueryLoad_ChatsArgs): Promise<Chat[]> => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.query(myChats, options).toPromise()
return resp.data.load_chats.chats
},
2023-11-28 15:36:00 +00:00
createChat: async (options: MutationCreate_ChatArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.mutation(createChat, options).toPromise()
return resp.data.create_chat
},
2023-11-28 15:36:00 +00:00
markAsRead: async (options: MutationMark_As_ReadArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.mutation(markAsRead, options).toPromise()
return resp.data.mark_as_read
},
2023-11-28 15:36:00 +00:00
updateChat: async (options: MutationUpdate_ChatArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.mutation(updateChat, options).toPromise()
return resp.data.update_chat
},
2023-11-28 15:36:00 +00:00
deleteChat: async (options: MutationDelete_ChatArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.mutation(deleteChat, options).toPromise()
return resp.data.delete_chat
},
2023-11-28 15:36:00 +00:00
createMessage: async (options: MutationCreate_MessageArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.mutation(createChatMessage, options).toPromise()
return resp.data.create_message.message
},
2023-11-28 15:36:00 +00:00
updateMessage: async (options: MutationUpdate_MessageArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.mutation(updateChatMessage, options).toPromise()
return resp.data.update_message.message
},
2023-11-28 15:36:00 +00:00
deleteMessage: async (options: MutationDelete_MessageArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.mutation(deleteChatMessage, options).toPromise()
return resp.data.delete_message
},
2023-11-28 15:36:00 +00:00
loadChatMessages: async (options: QueryLoad_Messages_ByArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.query(chatMessagesLoadBy, options).toPromise()
return resp.data.load_messages_by.messages
},
2023-11-28 15:36:00 +00:00
loadRecipients: async (options: QueryLoad_RecipientsArgs) => {
2023-11-28 13:18:25 +00:00
const resp = await privateInboxGraphQLClient.query(loadRecipients, options).toPromise()
return resp.data.load_recipients.members
},
}