@cobuildlab/8base-chat
Version:
Chat component that uses 8base
78 lines (65 loc) • 1.37 kB
text/typescript
import gql from 'graphql-tag';
import { ATTACHMENT_FRAGMENT, USER_PREVIEW_FRAGMENT } from './index';
// -- FRAGMENTS
export const MESSAGE_FRAGMENT = gql`
fragment Message on Message {
id
createdAt
createdBy {
...UserPreview
}
text
attachments {
items {
...Attachment
}
}
}
${USER_PREVIEW_FRAGMENT}
${ATTACHMENT_FRAGMENT}
`;
// -- MUTATIONS
export const MESSAGE_CREATE_MUTATION = gql`
mutation MessageCreate($data: MessageCreateInput!) {
messageCreate(data: $data) {
...Message
}
}
${MESSAGE_FRAGMENT}
`;
export const MESSAGE_DELETE_MUTATION = gql`
mutation MessageDelete($data: MessageDeleteInput!) {
messageDelete(data: $data) {
success
}
}
`;
export const MESSAGE_UPDATE_MUTATION = gql`
mutation MessageUpdate($data: MessageUpdateInput!) {
messageUpdate(data: $data) {
id
}
}
`;
// -- SUBSCRIPTIONS
export const USER_CHANNELS_MESSAGES_SUB = gql`
subscription UserChannelsMessagesSub($userId: ID!) {
Message(
filter: {
mutation_in: [create, update]
node: { channel: { members: { some: { user: { id: { equals: $userId } } } } } }
}
) {
mutation
node {
...Message
isDeleted
channel {
id
type
}
}
}
}
${MESSAGE_FRAGMENT}
`;