const useGetUserStatus = (isReadOnlyCache) => { const client = useApolloClient(); const readCache = () => { const { authentication } = client.readQuery({ query: GET_USER_STATUS }); return authentication; }; if (isReadOnlyCache) return readCache(); const { data, loading } = useQuery(GET_USER_STATUS); if (loading) return readCache(); return data.authentication; }
const useChatChanged = (channelId, userId) => { const client = useApolloClient(); const published = useSubscription(CHAT_CHANGED, { variables: { channelId } }); const chatChanged = published.data && published.data.chatChanged; if (!chatChanged) return; const cacheData = client.readQuery({ query: GET_CHAT_CACHED }); const data = addOrUpdateChat(userId, cacheData, chatChanged); client.writeQuery({ query: GET_CHAT_CACHED, data }); }
const useChangeChatSort = () => { const client = useApolloClient(); const changeSortType = (sortType) => { const { chatLogs } = client.readQuery({ query: GET_CHAT_CACHED }); const data = { chatLogs: { ...chatLogs, changeAction: chatInit(), sortType, }, }; client.writeQuery({ query: GET_CHAT_CACHED, data }); }; return changeSortType; }
if (!query.called || query.loading) return; const { chatLogs } = client.readQuery({ query: GET_CHAT_CACHED }); const logs = query.data.getChatLogs;