@jsb188/graphql 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,160 @@
1
+ import { getENVVariable } from '@jsb188/app';
2
+ import { getAuthToken } from '@jsb188/app/utils/api';
3
+ import SSE from '@jsb188/sse';
4
+ import { useEffect, useState } from 'react';
5
+ import { loadFragment } from '../cache/';
6
+ import { useQuery } from '../client';
7
+ import { aiChatMessagesQry, aiChatQry, aiChatsQry } from '../gql/queries/aiChatQueries';
8
+ import handleSSEData, { type PublishPayload } from '../sse';
9
+ import type { UseQueryParams } from '../types.d';
10
+
11
+ /**
12
+ * Constants
13
+ */
14
+
15
+ const AI_CHATS_LIMIT = 100; // Must match server code exactly
16
+ const AI_CHAT_MESSAGES_LIMIT = 100; // Must match server code exactly
17
+
18
+ /**
19
+ * Helper; get generating (status) key from SSE data
20
+ */
21
+
22
+ function getGeneratingFragmentId(sseData: PublishPayload) {
23
+ const { __type, dataFragmentKey, fragmentKey, fragmentNamespace, data } = sseData;
24
+ const finished = data?.finished;
25
+
26
+ if (__type === 'CONNECTED') {
27
+ return null;
28
+ }
29
+
30
+ const fragmentName = '$aiChatMessageFragment:';
31
+
32
+ if (typeof finished === 'boolean') {
33
+ if (dataFragmentKey?.startsWith(fragmentName) ) {
34
+ return finished ? null : dataFragmentKey;
35
+ } else if (fragmentKey?.startsWith(fragmentName)) {
36
+ return finished ? null : fragmentKey;
37
+ }
38
+ } else if (
39
+ fragmentKey?.startsWith(fragmentName) &&
40
+ fragmentNamespace === 'text'
41
+ ) {
42
+ return fragmentKey;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Fetch AI chat
48
+ */
49
+
50
+ export function useAIChatWithSSE(aiChatId?: string, initialSessionKey?: string | null, params: UseQueryParams = {}) {
51
+
52
+ const { data, ...other } = useQuery(aiChatQry, {
53
+ variables: {
54
+ aiChatId
55
+ },
56
+ skip: !aiChatId,
57
+ ...params,
58
+ });
59
+
60
+ const { updateObservers } = other;
61
+ const [sessionKey, setSessionKey] = useState<string | null>(initialSessionKey || null);
62
+ const [generatingFragmentId, setGeneratingFragmentId] = useState<string | null>(null);
63
+ const aiChat = data?.aiChat || loadFragment(`$aiChatFragment:${aiChatId}`);
64
+ const dataAIChatId = aiChat?.id;
65
+
66
+ useEffect(() => {
67
+ // Browser has too many issues such as proxy, network, roadblocks
68
+ // that make it unreliable to use perpetual SSE in production.
69
+ // So we have to write the logic to make it work without perpetual session.
70
+
71
+ if (dataAIChatId && sessionKey) {
72
+ // Only listen to events if data is loaded
73
+ const connection = new SSE({
74
+ host: getENVVariable('SSE_SERVER') as string,
75
+ path: `page_events/ai_chat/${dataAIChatId}`,
76
+ // path: 'test-sse',
77
+ searchParams: {
78
+ session_key: sessionKey,
79
+ auth_token: getAuthToken()
80
+ }
81
+ });
82
+
83
+ const connectParams = {
84
+ onMessage: (sseData: PublishPayload) => {
85
+ handleSSEData(sseData, updateObservers);
86
+
87
+ const nextValue = getGeneratingFragmentId(sseData);
88
+ if (nextValue === null || typeof nextValue === 'string') {
89
+ setGeneratingFragmentId(nextValue);
90
+ }
91
+ },
92
+ onError: () => {
93
+ setGeneratingFragmentId(null);
94
+ }
95
+ };
96
+
97
+ connection.connect(connectParams);
98
+
99
+ // const removeNetworkListeners = reconnectOnBrowserNetwork(connection, connectParams);
100
+
101
+ return () => {
102
+ connection.close();
103
+ // removeNetworkListeners();
104
+ };
105
+ }
106
+ }, [dataAIChatId, sessionKey]);
107
+
108
+ return {
109
+ aiChat,
110
+ generatingFragmentId,
111
+ sessionKey,
112
+ setSessionKey,
113
+ ...other
114
+ };
115
+ }
116
+
117
+ /**
118
+ * Fetch AI chat messages
119
+ */
120
+
121
+ export function useAIChatMessages(aiChatId?: string, params: UseQueryParams = {}) {
122
+
123
+ const { data, ...other } = useQuery(aiChatMessagesQry, {
124
+ variables: {
125
+ aiChatId,
126
+ cursor: null,
127
+ after: true,
128
+ limit: AI_CHAT_MESSAGES_LIMIT
129
+ },
130
+ // If this query is used for virtualized list pagination, set {params.skip=true}
131
+ skip: !aiChatId,
132
+ ...params,
133
+ });
134
+
135
+ return {
136
+ aiChatMessages: data?.aiChatMessages,
137
+ ...other
138
+ };
139
+ }
140
+
141
+ /**
142
+ * Fetch AI chats list
143
+ */
144
+
145
+ export function useAIChats(filter?: 'CAL_DATE') {
146
+ const { data, ...other } = useQuery(aiChatsQry, {
147
+ variables: {
148
+ filter,
149
+ cursor: null,
150
+ after: false,
151
+ limit: AI_CHATS_LIMIT
152
+ },
153
+ skip: false,
154
+ });
155
+
156
+ return {
157
+ aiChats: data?.aiChats,
158
+ ...other
159
+ };
160
+ }
@@ -0,0 +1,19 @@
1
+ import { useQuery } from '@jsb188/graphql/client';
2
+ import { updateNoteQry } from '../gql/queries/appQueries';
3
+ import type { UseQueryParams } from '../types.d';
4
+
5
+ /**
6
+ * Fetch update notes
7
+ */
8
+
9
+ export function useUpdateNote(accountId?: string | null, params: UseQueryParams = {}) {
10
+ const { data, ...other } = useQuery(updateNoteQry, {
11
+ skip: !accountId,
12
+ ...params,
13
+ });
14
+
15
+ return {
16
+ updateNote: data?.updateNote,
17
+ ...other
18
+ };
19
+ }
@@ -0,0 +1,234 @@
1
+ import i18n from '@jsb188/app/i18n';
2
+ import { useMutation } from './index';
3
+ import { changePasswordMtn, checkUsernameOrEmailMtn, emailVerificationStatusMtn, requestTokenizedEmailMtn, sendEmailVerificationMtn, signInMtn } from '../gql/mutations/userAuthMutations';
4
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
5
+ import { useOpenModalPopUp, type OpenModalPopUpFn } from '@jsb188/react/states';
6
+ import { useContext, useState } from 'react';
7
+ import appContext, { onAccountLogin } from '~/shared/states/appContext';
8
+
9
+ /**
10
+ * Types
11
+ */
12
+
13
+ interface SignInParams extends UseMutationParams {
14
+ initialError?: any;
15
+ initialFormData?: Record<string, any>;
16
+ }
17
+
18
+ /**
19
+ * Change password (while logged in)
20
+ */
21
+
22
+ export function useChangePassword(params: UseMutationParams = {}) {
23
+
24
+ const { dispatchApp, appState: { hasPassword, account } } = useContext(appContext);
25
+ const openModalPopUp = useOpenModalPopUp();
26
+ const { onCompleted, onError } = params;
27
+
28
+ const onCompleted_ = (data: any, err: any, variables: any) => {
29
+ if (onCompleted) {
30
+ onCompleted(data, err, variables);
31
+ }
32
+
33
+ const success = !!data?.changePassword;
34
+ if (success) {
35
+ openModalPopUp({
36
+ name: 'password_changed',
37
+ props: {
38
+ title: i18n.t('form.success'),
39
+ message: i18n.t('auth.password_changed_msg'),
40
+ iconName: 'lock-password-filled'
41
+ }
42
+ });
43
+
44
+ if (!hasPassword) {
45
+ dispatchApp({
46
+ __type: 'APP_EDIT_AUTH',
47
+ data: {
48
+ id: account?.id,
49
+ hasPassword: true,
50
+ }
51
+ });
52
+ }
53
+ }
54
+ };
55
+
56
+ const [changePassword, mtnValues] = useMutation(
57
+ changePasswordMtn,
58
+ {
59
+ openModalPopUp,
60
+ onCompleted: onCompleted_,
61
+ onError,
62
+ },
63
+ );
64
+
65
+ return {
66
+ openModalPopUp,
67
+ changePassword,
68
+ ...mtnValues,
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Reset password (from 30m email link)
74
+ */
75
+
76
+ export function useChangePasswordForm(params: UseMutationParams = {}) {
77
+
78
+ const { dispatchApp, appState: { hasPassword, account } } = useContext(appContext);
79
+ const { onCompleted, onError } = params;
80
+
81
+ const onCompleted_ = (data: any, err: any, variables: any) => {
82
+ if (onCompleted) {
83
+ onCompleted(data, err, variables);
84
+ }
85
+
86
+ const success = !!data?.changePassword;
87
+ if (success) {
88
+ // It's possible for user to use this hook without being logged in
89
+ // So we have to check for ID first
90
+ if (account?.id && !hasPassword) {
91
+ dispatchApp({
92
+ __type: 'APP_EDIT_AUTH',
93
+ data: {
94
+ id: account?.id,
95
+ hasPassword: true,
96
+ }
97
+ });
98
+ }
99
+ }
100
+ };
101
+
102
+ const [changePassword, mtnValues] = useMutation(
103
+ changePasswordMtn,
104
+ {
105
+ checkMountedBeforeCallback: true,
106
+ onCompleted: onCompleted_,
107
+ onError,
108
+ },
109
+ );
110
+
111
+ return {
112
+ changePassword,
113
+ ...mtnValues,
114
+ };
115
+ }
116
+
117
+ /**
118
+ * Check email verification status
119
+ */
120
+
121
+ export function useEmailVerification(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
122
+
123
+ const { onCompleted, onError } = params;
124
+ const [emailVerificationStatus, mtnValues1] = useMutation(
125
+ emailVerificationStatusMtn,
126
+ {
127
+ openModalPopUp,
128
+ onError,
129
+ onCompleted,
130
+ },
131
+ );
132
+
133
+ const [sendEmailVerification, mtnValues2] = useMutation(
134
+ sendEmailVerificationMtn,
135
+ {
136
+ openModalPopUp,
137
+ onError,
138
+ onCompleted,
139
+ },
140
+ );
141
+
142
+ return {
143
+ emailVerificationStatus,
144
+ sendEmailVerification,
145
+ verifying: mtnValues1.saving,
146
+ sending: mtnValues2.saving,
147
+ };
148
+ }
149
+
150
+ /**
151
+ * Request password reset (email with link)
152
+ */
153
+
154
+ export function useRequestTokenizedEmail(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
155
+
156
+ const { onCompleted, onError } = params;
157
+ const [requestTokenizedEmail, mtnValues] = useMutation(
158
+ requestTokenizedEmailMtn,
159
+ {
160
+ checkMountedBeforeCallback: true,
161
+ openModalPopUp,
162
+ onCompleted,
163
+ onError
164
+ },
165
+ );
166
+
167
+ return {
168
+ requestTokenizedEmail,
169
+ ...mtnValues,
170
+ };
171
+ }
172
+
173
+ /**
174
+ * Sign in
175
+ */
176
+
177
+ export function useSignIn(params: SignInParams = {}, openModalPopUp?: OpenModalPopUpFn) {
178
+ const { onError, onCompleted, initialError, initialFormData } = params;
179
+ const { dispatchApp } = useContext<any>(appContext);
180
+
181
+ const [dataForSchema, setDataForSchema] = useState({
182
+ hasInput: !!initialFormData?.usernameOrEmail,
183
+ lastIdentifier: initialFormData?.usernameOrEmail || '',
184
+ hidePassword: !initialFormData?.usernameOrEmail,
185
+ });
186
+
187
+ const [checkUsernameOrEmail, step1MtnValues, step1MtnHandlers] = useMutation(
188
+ checkUsernameOrEmailMtn,
189
+ {
190
+ openModalPopUp,
191
+ initialError,
192
+ onError,
193
+ onCompleted,
194
+ },
195
+ );
196
+
197
+ const [signIn, step2MtnValues, step2MtnHandlers] = useMutation(
198
+ signInMtn,
199
+ {
200
+ openModalPopUp,
201
+ initialError,
202
+ onError,
203
+ onCompleted: (data, error) => {
204
+ const result = data?.signIn;
205
+ if (result?.token && result.user?.id) {
206
+ onAccountLogin(result, dispatchApp);
207
+
208
+ if (onCompleted) {
209
+ onCompleted(data, error);
210
+ }
211
+ }
212
+ },
213
+ },
214
+ );
215
+
216
+ let mtnValues;
217
+ let mtnHandlers;
218
+ if (dataForSchema.hidePassword) {
219
+ mtnValues = step1MtnValues;
220
+ mtnHandlers = step1MtnHandlers;
221
+ } else {
222
+ mtnValues = step2MtnValues;
223
+ mtnHandlers = step2MtnHandlers;
224
+ }
225
+
226
+ return {
227
+ ...mtnValues,
228
+ ...mtnHandlers,
229
+ checkUsernameOrEmail,
230
+ signIn,
231
+ dataForSchema,
232
+ setDataForSchema,
233
+ };
234
+ }
@@ -0,0 +1,49 @@
1
+ import type { PaginationArgs, UseQueryParams } from '../types.d';
2
+ import { useQuery } from '../client';
3
+ import { journalEntriesQry } from '../gql/queries/journalQueries';
4
+
5
+ /**
6
+ * Constants
7
+ */
8
+
9
+ const JOURNAL_ENTRIES_LIMIT = 50;
10
+
11
+ /**
12
+ * Types
13
+ */
14
+
15
+ interface JournalEntriesVariables {
16
+ organizationId?: string;
17
+ accountId?: string;
18
+ }
19
+
20
+ interface JournalEntriesArgs extends PaginationArgs {
21
+ organizationId: string;
22
+ accountId?: string;
23
+ timeZone: string | null;
24
+ filter: FilterJournalEntriesArgs;
25
+ }
26
+
27
+ /**
28
+ * Fetch journal entries
29
+ */
30
+
31
+ export function useJournalEntries(variables: JournalEntriesArgs, params: UseQueryParams = {}) {
32
+
33
+ const { data, ...other } = useQuery(journalEntriesQry, {
34
+ variables: {
35
+ ...variables,
36
+ cursor: null,
37
+ after: true,
38
+ limit: JOURNAL_ENTRIES_LIMIT
39
+ },
40
+ // If this query is used for virtualized list pagination, set {params.skip=true}
41
+ skip: !variables.organizationId,
42
+ ...params,
43
+ });
44
+
45
+ return {
46
+ journalEntries: data?.journalEntries,
47
+ ...other
48
+ };
49
+ }
@@ -0,0 +1,37 @@
1
+ import { useQuery } from '@jsb188/graphql/client';
2
+ import { organizationRelationshipQry, myOrganizationsQry } from '../gql/queries/organizationQueries';
3
+ import type { UseQueryParams } from '../types.d';
4
+
5
+ /**
6
+ * Fetch organization relationship
7
+ */
8
+
9
+ export function useOrganizationRelationship(organizationId?: string | null, params: UseQueryParams = {}) {
10
+ const { data, ...other } = useQuery(organizationRelationshipQry, {
11
+ variables: {
12
+ organizationId
13
+ },
14
+ skip: !organizationId,
15
+ ...params,
16
+ });
17
+
18
+ return {
19
+ organizationRelationship: data?.organizationRelationship,
20
+ ...other
21
+ };
22
+ }
23
+
24
+ /**
25
+ * Fetch my organizations
26
+ */
27
+
28
+ export function useMyOrganizations(params: UseQueryParams = {}) {
29
+ const { data, ...other } = useQuery(myOrganizationsQry, {
30
+ ...params,
31
+ });
32
+
33
+ return {
34
+ myOrganizations: data?.myOrganizations,
35
+ ...other
36
+ };
37
+ }
package/package.json CHANGED
@@ -1,42 +1,61 @@
1
1
  {
2
2
  "name": "@jsb188/graphql",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "GraphQL client for react, using recoil",
5
5
  "license": "ISC",
6
6
  "author": "jsb188",
7
7
  "type": "module",
8
- "main": "main.ts",
9
8
  "types": "types.d.ts",
10
9
  "exports": {
11
- ".": "./main.ts",
12
- "./fragments/auth": "./gql/fragments/authFragments.ts",
10
+ "./fragments/account": "./gql/fragments/accountFragments.ts",
11
+ "./fragments/accountAuth": "./gql/fragments/accountAuthFragments.ts",
13
12
  "./fragments/aiChat": "./gql/fragments/aiChatFragments.ts",
14
13
  "./fragments/billing": "./gql/fragments/billingFragments.ts",
15
14
  "./fragments/card": "./gql/fragments/cardFragments.ts",
16
15
  "./fragments/chat": "./gql/fragments/chatFragments.ts",
16
+ "./fragments/journal": "./gql/fragments/journalFragments.ts",
17
+ "./fragments/organization": "./gql/fragments/organizationFragments.ts",
17
18
  "./fragments/other": "./gql/fragments/otherFragments.ts",
18
19
  "./fragments/user": "./gql/fragments/userFragments.ts",
20
+ "./fragments/userAuth": "./gql/fragments/userAuthFragments.ts",
21
+ "./hooks": "./hooks/",
22
+ "./hooks/use-aiChat-qry": "./hooks/use-aiChat-qry.ts",
23
+ "./hooks/use-app-qry": "./hooks/use-app-qry.ts",
24
+ "./hooks/use-journal-qry": "./hooks/use-journal-qry.ts",
25
+ "./hooks/use-organization-qry": "./hooks/use-organization-qry.ts",
26
+ "./hooks/use-auth-mtn": "./hooks/use-auth-mtn.ts",
27
+ "./mutations/accountAuth": "./gql/mutations/accountAuthMutations.ts",
19
28
  "./mutations/aiChat": "./gql/mutations/aiChatMutations.ts",
20
- "./mutations/auth": "./gql/mutations/authMutations.ts",
21
29
  "./mutations/billing": "./gql/mutations/billingMutations.ts",
22
30
  "./mutations/chat": "./gql/mutations/chatMutations.ts",
31
+ "./mutations/journal": "./gql/mutations/journalMutations.ts",
23
32
  "./mutations/other": "./gql/mutations/otherMutations.ts",
24
33
  "./mutations/user": "./gql/mutations/userMutations.ts",
34
+ "./mutations/userAuth": "./gql/mutations/userAuthMutations.ts",
25
35
  "./queries/aiChat": "./gql/queries/aiChatQueries.ts",
26
- "./queries/auth": "./gql/queries/authQueries.ts",
36
+ "./queries/app": "./gql/queries/appQueries.ts",
27
37
  "./queries/billing": "./gql/queries/billingQueries.ts",
28
38
  "./queries/card": "./gql/queries/cardQueries.ts",
29
39
  "./queries/chat": "./gql/queries/chatQueries.ts",
40
+ "./queries/journal": "./gql/queries/journalQueries.ts",
41
+ "./queries/organization": "./gql/queries/organizationQueries.ts",
30
42
  "./queries/other": "./gql/queries/otherQueries.ts",
31
43
  "./queries/user": "./gql/queries/userQueries.ts",
32
- "./types": "./types.d.ts",
33
- "./utils": "./cache/utils.ts"
44
+ "./cache": "./cache/index.ts",
45
+ "./client": "./client/index.ts",
46
+ "./sse": "./sse.ts",
47
+ "./types.d": "./types.d.ts",
48
+ "./utils": "./utils.ts"
34
49
  },
35
50
  "scripts": {
36
51
  "test": "echo \"Error: no test specified\" && exit 1"
37
52
  },
38
53
  "dependencies": {
39
- "graphql-tag": "^2.12.6",
40
- "@jsb188/app": "^1.0.2"
54
+ "graphql": "^16.10.0",
55
+ "graphql-tag": "^2.12.6"
56
+ },
57
+ "peerDependencies": {
58
+ "@jsb188/app": "1.1.1",
59
+ "@jsb188/react": "1.1.1"
41
60
  }
42
61
  }
package/sse.ts ADDED
@@ -0,0 +1,132 @@
1
+ import { addFragmentToCache, updateFragment, updateQuery } from './cache/';
2
+ import type { UpdateObserversFn } from './types.d';
3
+
4
+ /**
5
+ * Types
6
+ */
7
+
8
+ type ValidSSEType = (
9
+ // Default SSE events
10
+ 'CONNECTED' |
11
+ // Query handlers
12
+ 'QUERY_APPEND' | 'QUERY_PREPEND' |
13
+ // Fragment handlers
14
+ 'DATA_APPEND' | 'DATA_PREPEND' | 'DATA_UPDATE'
15
+ );
16
+
17
+ export interface PublishPayload {
18
+ __type: ValidSSEType;
19
+ fragmentKey: string;
20
+ fragmentNamespace?: string;
21
+ dataFragmentKey?: string;
22
+ data: Record<string, any>;
23
+ otherData?: Record<string, any>;
24
+ }
25
+
26
+ /**
27
+ * Append or prepend data to a query
28
+ */
29
+
30
+ function handleQueryConcat(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
31
+
32
+ const { __type, fragmentKey, fragmentNamespace, dataFragmentKey, data, otherData } = payload;
33
+
34
+ if (fragmentKey && fragmentNamespace && dataFragmentKey && data) {
35
+ const isAppend = __type === 'QUERY_APPEND';
36
+ const updateData = (currentData: any) => {
37
+ const currentList = currentData?.[fragmentNamespace]?.data;
38
+ if (
39
+ currentData?.[fragmentNamespace]?.__list &&
40
+ Array.isArray(currentList) &&
41
+ !currentList.find(a => a[0] === dataFragmentKey)
42
+ ) {
43
+ addFragmentToCache(dataFragmentKey, data);
44
+ const updatedList = isAppend ? [...currentList, [dataFragmentKey]] : [[dataFragmentKey], ...currentList];
45
+ return {
46
+ ...currentData,
47
+ ...otherData,
48
+ [fragmentNamespace]: {
49
+ ...currentData?.[fragmentNamespace],
50
+ data: updatedList
51
+ }
52
+ };
53
+ }
54
+ return currentData;
55
+ }
56
+
57
+ updateQuery(
58
+ fragmentKey,
59
+ updateData,
60
+ false,
61
+ updateObservers
62
+ );
63
+ }
64
+
65
+ return null;
66
+ }
67
+
68
+ /**
69
+ * Append or prepend data to a fragment
70
+ */
71
+
72
+ function handleFragmentConcat(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
73
+ const { __type, fragmentKey, fragmentNamespace, data, otherData } = payload;
74
+ const isAppend = __type === 'DATA_APPEND';
75
+
76
+ if (fragmentKey && fragmentNamespace && data) {
77
+ const namespaceType = typeof fragmentNamespace;
78
+ const updateData = (currentData: any) => {
79
+ if (typeof currentData[fragmentNamespace] === namespaceType) {
80
+ let nextValue;
81
+ if (namespaceType === 'string') {
82
+ nextValue = isAppend ? `${currentData[fragmentNamespace]}${data}` : `${data}${currentData[fragmentNamespace]}`;
83
+ } else if (Array.isArray(currentData[fragmentNamespace])) {
84
+ nextValue = isAppend ? [...currentData[fragmentNamespace], data] : [data, ...currentData[fragmentNamespace]];
85
+ }
86
+ return {
87
+ ...currentData,
88
+ ...otherData,
89
+ [fragmentNamespace]: nextValue
90
+ }
91
+ }
92
+ return currentData;
93
+ };
94
+
95
+ updateFragment(fragmentKey, updateData, null, false, updateObservers);
96
+ }
97
+
98
+ }
99
+
100
+ /**
101
+ * Update data in a fragment
102
+ */
103
+
104
+ function handleFragmentUpdate(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
105
+ const { fragmentKey, dataFragmentKey, data } = payload;
106
+ updateFragment(dataFragmentKey || fragmentKey, data, null, false, updateObservers);
107
+ }
108
+
109
+ /**
110
+ * Data handler for SSE
111
+ */
112
+
113
+ function handleSSEData(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
114
+ switch (payload.__type) {
115
+ case 'CONNECTED':
116
+ // Do nothing
117
+ break;
118
+ case 'QUERY_APPEND':
119
+ case 'QUERY_PREPEND':
120
+ return handleQueryConcat(payload, updateObservers)
121
+ case 'DATA_APPEND':
122
+ case 'DATA_PREPEND':
123
+ return handleFragmentConcat(payload, updateObservers)
124
+ case 'DATA_UPDATE':
125
+ return handleFragmentUpdate(payload, updateObservers)
126
+ default:
127
+ console.log('Unknown {__type} in handleSSEData():', payload.__type);
128
+ break;
129
+ }
130
+ }
131
+
132
+ export default handleSSEData;