Merge branch 'more-gqls' into 'dev'
subs, queries See merge request discoursio/discoursio-webapp!28
This commit is contained in:
commit
fc3f944a22
|
@ -70,7 +70,7 @@ export const InboxView = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: удалить когда будет готова подписка
|
||||
/*
|
||||
createEffect(() => {
|
||||
setInterval(async () => {
|
||||
if (!currentDialog()) return
|
||||
|
@ -83,7 +83,7 @@ export const InboxView = () => {
|
|||
}
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
*/
|
||||
onMount(async () => {
|
||||
try {
|
||||
const response = await loadRecipients({ days: 365 })
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type { Accessor, JSX } from 'solid-js'
|
||||
import { createContext, createSignal, useContext, createMemo } from 'solid-js'
|
||||
import { createChatClient } from '../graphql/privateGraphQLClient'
|
||||
import { createSubClient } from '../graphql/privateGraphQLClient'
|
||||
import type { Chat, Message, MutationCreateMessageArgs } from '../graphql/types.gen'
|
||||
import { apiClient } from '../utils/apiClient'
|
||||
import newMessage from '../graphql/subs/new-message'
|
||||
|
@ -29,7 +29,7 @@ export function useInbox() {
|
|||
export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||
const [chats, setChats] = createSignal<Chat[]>([])
|
||||
const [messages, setMessages] = createSignal<Message[]>([])
|
||||
const subclient = createMemo<Client>(() => createChatClient())
|
||||
const subclient = createMemo<Client>(() => createSubClient())
|
||||
const loadChats = async () => {
|
||||
try {
|
||||
const newChats = await apiClient.getChats({ limit: 50, offset: 0 })
|
||||
|
@ -71,8 +71,8 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
|||
return chat
|
||||
}
|
||||
|
||||
const { unsubscribe } = pipe(
|
||||
() => subclient().subscription(newMessage, {}),
|
||||
pipe(
|
||||
subclient().subscription(newMessage, {}),
|
||||
subscribe((result) => {
|
||||
console.info('[subscription]')
|
||||
console.debug(result)
|
||||
|
@ -83,8 +83,8 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
|||
createChat,
|
||||
loadChats,
|
||||
getMessages,
|
||||
sendMessage,
|
||||
unsubscribe // TODO: call unsubscribe some time!
|
||||
sendMessage
|
||||
// unsubscribe // TODO: call unsubscribe some time!
|
||||
}
|
||||
|
||||
const value: InboxContextType = { chats, messages, actions }
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
createClient
|
||||
} from '@urql/core'
|
||||
// import { createClient as createSubClient } from 'graphql-sse'
|
||||
import { createClient as createSubClient } from 'graphql-ws'
|
||||
import { createClient as createWSClient } from 'graphql-ws'
|
||||
import { devtoolsExchange } from '@urql/devtools'
|
||||
import { isDev, apiBaseUrl } from '../utils/config'
|
||||
// import { cache } from './cache'
|
||||
|
@ -55,8 +55,8 @@ const options: ClientOptions = {
|
|||
|
||||
export const privateGraphQLClient = createClient(options)
|
||||
|
||||
export const createChatClient = () => {
|
||||
const subClient = createSubClient({
|
||||
export const createSubClient = () => {
|
||||
const subClient = createWSClient({
|
||||
url: apiBaseUrl.replace('http', 'ws') // + '/messages'
|
||||
})
|
||||
|
||||
|
|
26
src/graphql/subs/new-reaction.ts
Normal file
26
src/graphql/subs/new-reaction.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { gql } from '@urql/core'
|
||||
|
||||
export default gql`
|
||||
subscription {
|
||||
newReactions {
|
||||
id
|
||||
body
|
||||
kind
|
||||
range
|
||||
createdAt
|
||||
replyTo
|
||||
stat {
|
||||
rating
|
||||
}
|
||||
shout {
|
||||
id
|
||||
slug
|
||||
}
|
||||
createdBy {
|
||||
name
|
||||
slug
|
||||
userpic
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
25
src/graphql/subs/new-shout.ts
Normal file
25
src/graphql/subs/new-shout.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { gql } from '@urql/core'
|
||||
|
||||
export default gql`
|
||||
subscription {
|
||||
newShout {
|
||||
id
|
||||
slug
|
||||
title
|
||||
subtitle
|
||||
body
|
||||
topics {
|
||||
# id
|
||||
title
|
||||
slug
|
||||
}
|
||||
authors {
|
||||
id
|
||||
name
|
||||
slug
|
||||
userpic
|
||||
caption
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
|
@ -38,6 +38,7 @@ import myChats from '../graphql/query/chats-load'
|
|||
import chatMessagesLoadBy from '../graphql/query/chat-messages-load-by'
|
||||
import authorBySlug from '../graphql/query/author-by-slug'
|
||||
import userSubscribers from '../graphql/query/author-followers'
|
||||
import userFollowing from '../graphql/query/author-following'
|
||||
import topicBySlug from '../graphql/query/topic-by-slug'
|
||||
import createChat from '../graphql/mutation/create-chat'
|
||||
import reactionsLoadBy from '../graphql/query/reactions-load-by'
|
||||
|
@ -221,6 +222,10 @@ export const apiClient = {
|
|||
const response = await publicGraphQLClient.query(userSubscribers, { slug }).toPromise()
|
||||
return response.data.userFollowers
|
||||
},
|
||||
getAuthorFollowing: async ({ slug }: { slug: string }): Promise<Author[]> => {
|
||||
const response = await publicGraphQLClient.query(userFollowing, { slug }).toPromise()
|
||||
return response.data.userFollowing
|
||||
},
|
||||
updateProfile: async (input: ProfileInput) => {
|
||||
const response = await privateGraphQLClient.mutation(updateProfile, { profile: input }).toPromise()
|
||||
return response.data.updateProfile
|
||||
|
|
Loading…
Reference in New Issue
Block a user