@jsb188/graphql 1.1.7 → 1.1.10
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.
- package/cache/config.ts +14 -4
- package/cache/index.test.ts +319 -0
- package/cache/index.ts +522 -85
- package/client/index.ts +2 -2
- package/client/request.ts +48 -9
- package/deno.test.json +6 -0
- package/gql/fragments/accountFragments.ts +1 -0
- package/gql/fragments/aiChatFragments.ts +1 -0
- package/gql/fragments/dataTableFragments.ts +212 -0
- package/gql/fragments/emailFragments.ts +26 -0
- package/gql/fragments/inboundContactFragments.ts +15 -0
- package/gql/fragments/integrationFragments.ts +22 -0
- package/gql/fragments/logFragments.ts +40 -12
- package/gql/fragments/organizationFragments.ts +59 -24
- package/gql/fragments/productFragments.ts +0 -24
- package/gql/fragments/reportFragments.ts +52 -10
- package/gql/fragments/sheetFragments.ts +145 -0
- package/gql/fragments/storageFragments.ts +3 -1
- package/gql/fragments/workflowFragments.ts +43 -0
- package/gql/mutations/accountMutations.ts +24 -2
- package/gql/mutations/aiChatMutations.ts +28 -1
- package/gql/mutations/authMutations.ts +3 -3
- package/gql/mutations/billingMutations.ts +1 -1
- package/gql/mutations/dataTableMutations.ts +84 -0
- package/gql/mutations/inboundContactMutations.ts +24 -0
- package/gql/mutations/index.ts +12 -8
- package/gql/mutations/integrationMutations.ts +25 -0
- package/gql/mutations/logMutations.ts +15 -1
- package/gql/mutations/organizationMutations.ts +151 -2
- package/gql/mutations/sheetMutations.ts +168 -0
- package/gql/mutations/storageMutations.ts +1 -2
- package/gql/queries/aiChatQueries.ts +1 -1
- package/gql/queries/billingQueries.ts +1 -1
- package/gql/queries/dataTableQueries.ts +45 -0
- package/gql/queries/emailQueries.ts +44 -0
- package/gql/queries/inboundContactQueries.ts +40 -0
- package/gql/queries/index.ts +11 -6
- package/gql/queries/logQueries.ts +47 -20
- package/gql/queries/organizationQueries.ts +62 -8
- package/gql/queries/productQueries.ts +1 -40
- package/gql/queries/reportQueries.ts +81 -13
- package/gql/queries/sheetQueries.ts +72 -0
- package/gql/queries/workflowQueries.ts +30 -0
- package/hooks/index.ts +208 -58
- package/hooks/use-account-mtn.ts +52 -4
- package/hooks/use-aiChat-mtn.ts +62 -6
- package/hooks/use-aiChat-qry.ts +76 -24
- package/hooks/use-app-qry.ts +2 -2
- package/hooks/use-auth-mtn.ts +5 -5
- package/hooks/use-dataTable-mtn.ts +87 -0
- package/hooks/use-dataTable-qry.ts +172 -0
- package/hooks/use-email-qry.ts +112 -0
- package/hooks/use-inboundContact-mtn.ts +31 -0
- package/hooks/use-inboundContact-qry.ts +88 -0
- package/hooks/use-integration-mtn.ts +59 -0
- package/hooks/use-integration-qry.ts +15 -0
- package/hooks/use-log-mtn.ts +6 -6
- package/hooks/use-log-qry.ts +38 -35
- package/hooks/use-organization-mtn.ts +288 -16
- package/hooks/use-organization-qry.ts +71 -22
- package/hooks/use-product-qry.ts +4 -46
- package/hooks/use-report-qry.ts +94 -10
- package/hooks/use-sheet-mtn.ts +181 -0
- package/hooks/use-sheet-qry.ts +157 -0
- package/hooks/use-storage-mtn.ts +6 -5
- package/hooks/use-storage-qry.ts +1 -1
- package/hooks/use-workflow-qry.ts +72 -0
- package/package.json +23 -4
- package/sse.ts +2 -2
- package/tsconfig.json +12 -0
- package/types.d.ts +2 -1
- package/utils.ts +2 -4
- package/gql/fragments/actionFragments.ts +0 -16
package/cache/config.ts
CHANGED
|
@@ -27,21 +27,31 @@ export const RULES = {
|
|
|
27
27
|
childOrganizations: true,
|
|
28
28
|
eventsList: true,
|
|
29
29
|
eventAttendanceList: true,
|
|
30
|
+
integrationConnection: true,
|
|
30
31
|
parentOrganization: true,
|
|
32
|
+
logEntry: true,
|
|
31
33
|
logEntries: true,
|
|
32
|
-
|
|
34
|
+
logEntriesForReport: true,
|
|
33
35
|
myChats: true,
|
|
34
36
|
myOrganizations: true,
|
|
37
|
+
organizationMembers: true,
|
|
35
38
|
organizationRelationship: true,
|
|
36
|
-
|
|
39
|
+
organizationSites: true,
|
|
37
40
|
platformProducts: true,
|
|
38
|
-
productAttendanceList: true,
|
|
39
41
|
productsList: true,
|
|
42
|
+
report: true,
|
|
43
|
+
reportGroups: true,
|
|
40
44
|
reports: true,
|
|
41
|
-
|
|
45
|
+
reportSubmissions: true,
|
|
46
|
+
dataTables: true,
|
|
47
|
+
dataTableRows: true,
|
|
48
|
+
sheets: true,
|
|
49
|
+
sheet: true,
|
|
50
|
+
sheetGrid: true,
|
|
42
51
|
searchUsers: true,
|
|
43
52
|
updateNote: true,
|
|
44
53
|
userIdToChatId: true,
|
|
54
|
+
workflows: true,
|
|
45
55
|
|
|
46
56
|
// All fragments are cached,
|
|
47
57
|
// but if you want to skip some, add it here
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { makeVariablesKey } from '@jsb188/app/utils/logic.ts';
|
|
2
|
+
import {
|
|
3
|
+
clearGraphQLClientCache,
|
|
4
|
+
fetchCachedData,
|
|
5
|
+
loadDataFromCache,
|
|
6
|
+
loadFragment,
|
|
7
|
+
resetQuery,
|
|
8
|
+
setDataToCache,
|
|
9
|
+
} from './index.ts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a GraphQL field selection node for cache tests.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function makeField(name: string, selections?: any[]) {
|
|
16
|
+
return {
|
|
17
|
+
kind: 'Field',
|
|
18
|
+
name: { value: name },
|
|
19
|
+
...(selections ? {
|
|
20
|
+
selectionSet: { selections },
|
|
21
|
+
} : {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a GraphQL fragment spread node for cache tests.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
function makeFragmentSpread(name: string) {
|
|
30
|
+
return {
|
|
31
|
+
kind: 'FragmentSpread',
|
|
32
|
+
name: { value: name },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create a GraphQL inline fragment node for cache tests.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
function makeInlineFragment(typeName: string, selections: any[]) {
|
|
41
|
+
return {
|
|
42
|
+
kind: 'InlineFragment',
|
|
43
|
+
typeCondition: {
|
|
44
|
+
name: { value: typeName },
|
|
45
|
+
},
|
|
46
|
+
selectionSet: { selections },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create a GraphQL fragment definition node for cache tests.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
function makeFragmentDefinition(name: string, selections: any[]) {
|
|
55
|
+
return {
|
|
56
|
+
kind: 'FragmentDefinition',
|
|
57
|
+
name: { value: name },
|
|
58
|
+
selectionSet: { selections },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create a minimal GraphQL operation document for cache tests.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
function makeQuery(queryName: string, selections: any[], extraDefinitions: any[] = []) {
|
|
67
|
+
return {
|
|
68
|
+
definitions: [{
|
|
69
|
+
kind: 'OperationDefinition',
|
|
70
|
+
selectionSet: {
|
|
71
|
+
selections: [{
|
|
72
|
+
kind: 'Field',
|
|
73
|
+
name: { value: queryName },
|
|
74
|
+
selectionSet: { selections },
|
|
75
|
+
}],
|
|
76
|
+
},
|
|
77
|
+
}, ...extraDefinitions],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Normalize nested values into a stable structure for comparisons.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
function normalizeValue(value: unknown): unknown {
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
return value.map(normalizeValue);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (value && typeof value === 'object') {
|
|
91
|
+
return Object.keys(value as Record<string, unknown>)
|
|
92
|
+
.sort()
|
|
93
|
+
.reduce((acc, key) => {
|
|
94
|
+
acc[key] = normalizeValue((value as Record<string, unknown>)[key]);
|
|
95
|
+
return acc;
|
|
96
|
+
}, {} as Record<string, unknown>);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Assert that two values are deeply equal.
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
function assertDeepEqual(actual: unknown, expected: unknown, label: string) {
|
|
107
|
+
const actualJson = JSON.stringify(normalizeValue(actual));
|
|
108
|
+
const expectedJson = JSON.stringify(normalizeValue(expected));
|
|
109
|
+
|
|
110
|
+
if (actualJson !== expectedJson) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`${label}\nExpected: ${expectedJson}\nActual: ${actualJson}`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Reset the shared cache state before each test run.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
function resetCacheState() {
|
|
122
|
+
clearGraphQLClientCache();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
Deno.test('loadFragment rebuilds nested list items without inner fragments', () => {
|
|
126
|
+
resetCacheState();
|
|
127
|
+
|
|
128
|
+
const gqlQuery = makeQuery('report', [
|
|
129
|
+
makeFragmentSpread('reportFragment'),
|
|
130
|
+
makeField('sections', [
|
|
131
|
+
makeField('id'),
|
|
132
|
+
makeField('title'),
|
|
133
|
+
]),
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
const requestData = {
|
|
137
|
+
report: {
|
|
138
|
+
id: 'report-1',
|
|
139
|
+
title: 'Daily Report',
|
|
140
|
+
sections: [{
|
|
141
|
+
id: 'section-1',
|
|
142
|
+
title: 'Overview',
|
|
143
|
+
}, {
|
|
144
|
+
id: 'section-2',
|
|
145
|
+
title: 'Tasks',
|
|
146
|
+
}],
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
setDataToCache(requestData, gqlQuery);
|
|
151
|
+
|
|
152
|
+
const cachedFragment = loadFragment('$reportFragment:report-1');
|
|
153
|
+
|
|
154
|
+
assertDeepEqual(cachedFragment, requestData.report, 'fragment cache should rebuild plain nested list items');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
Deno.test('loadDataFromCache preserves mixed list items with fragment refs and inline fields', () => {
|
|
158
|
+
resetCacheState();
|
|
159
|
+
|
|
160
|
+
const gqlQuery = makeQuery('report', [
|
|
161
|
+
makeFragmentSpread('reportFragment'),
|
|
162
|
+
makeField('sections', [
|
|
163
|
+
makeFragmentSpread('reportSectionFragment'),
|
|
164
|
+
makeField('files', [
|
|
165
|
+
makeField('uri'),
|
|
166
|
+
]),
|
|
167
|
+
]),
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
const requestData = {
|
|
171
|
+
report: {
|
|
172
|
+
id: 'report-2',
|
|
173
|
+
title: 'Inspection',
|
|
174
|
+
sections: [{
|
|
175
|
+
id: 'section-a',
|
|
176
|
+
title: 'Photos',
|
|
177
|
+
files: [{
|
|
178
|
+
uri: '/files/a.jpg',
|
|
179
|
+
}],
|
|
180
|
+
}],
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
setDataToCache(requestData, gqlQuery);
|
|
185
|
+
|
|
186
|
+
const cachedData = loadDataFromCache(
|
|
187
|
+
{},
|
|
188
|
+
gqlQuery,
|
|
189
|
+
makeVariablesKey(undefined),
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
assertDeepEqual(cachedData, requestData, 'query cache should rebuild mixed list items from fragment and inline cache data');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
Deno.test('fetchCachedData rejects cached query data missing newly selected nested fields', () => {
|
|
196
|
+
resetCacheState();
|
|
197
|
+
|
|
198
|
+
const oldQuery = makeQuery('myOrganizations', [
|
|
199
|
+
makeField('id'),
|
|
200
|
+
makeField('organization', [
|
|
201
|
+
makeField('id'),
|
|
202
|
+
makeField('name'),
|
|
203
|
+
]),
|
|
204
|
+
]);
|
|
205
|
+
const newQuery = makeQuery('myOrganizations', [
|
|
206
|
+
makeField('id'),
|
|
207
|
+
makeField('organization', [
|
|
208
|
+
makeField('id'),
|
|
209
|
+
makeField('name'),
|
|
210
|
+
makeField('integrations', [
|
|
211
|
+
makeField('id'),
|
|
212
|
+
makeField('provider'),
|
|
213
|
+
]),
|
|
214
|
+
]),
|
|
215
|
+
]);
|
|
216
|
+
const requestData = {
|
|
217
|
+
myOrganizations: [{
|
|
218
|
+
id: 'rel-1',
|
|
219
|
+
organization: {
|
|
220
|
+
id: 'org-1',
|
|
221
|
+
name: 'Marketday',
|
|
222
|
+
},
|
|
223
|
+
}],
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
setDataToCache(requestData, oldQuery);
|
|
227
|
+
|
|
228
|
+
const cachedData = fetchCachedData(
|
|
229
|
+
newQuery,
|
|
230
|
+
makeVariablesKey(undefined),
|
|
231
|
+
() => {},
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
assertDeepEqual(cachedData, null, 'cached query data should be invalidated when the current query asks for missing fields');
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
Deno.test('fetchCachedData ignores nonmatching inline fragments for union data', () => {
|
|
238
|
+
resetCacheState();
|
|
239
|
+
|
|
240
|
+
const gqlQuery = makeQuery('logEntries', [
|
|
241
|
+
makeField('id'),
|
|
242
|
+
makeField('details', [
|
|
243
|
+
makeInlineFragment('LogArable', [
|
|
244
|
+
makeFragmentSpread('logArableFragment'),
|
|
245
|
+
]),
|
|
246
|
+
makeInlineFragment('LogLivestock', [
|
|
247
|
+
makeFragmentSpread('logLivestockFragment'),
|
|
248
|
+
]),
|
|
249
|
+
]),
|
|
250
|
+
], [
|
|
251
|
+
makeFragmentDefinition('logArableFragment', [
|
|
252
|
+
makeField('__typename'),
|
|
253
|
+
makeField('id'),
|
|
254
|
+
makeField('activity'),
|
|
255
|
+
]),
|
|
256
|
+
makeFragmentDefinition('logLivestockFragment', [
|
|
257
|
+
makeField('__typename'),
|
|
258
|
+
makeField('id'),
|
|
259
|
+
makeField('livestock'),
|
|
260
|
+
]),
|
|
261
|
+
]);
|
|
262
|
+
const requestData = {
|
|
263
|
+
logEntries: [{
|
|
264
|
+
id: 'log-1',
|
|
265
|
+
details: {
|
|
266
|
+
__typename: 'LogArable',
|
|
267
|
+
id: 'log-1',
|
|
268
|
+
activity: 'SEEDING',
|
|
269
|
+
},
|
|
270
|
+
}],
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
setDataToCache(requestData, gqlQuery);
|
|
274
|
+
|
|
275
|
+
const cachedData = fetchCachedData(
|
|
276
|
+
gqlQuery,
|
|
277
|
+
makeVariablesKey(undefined),
|
|
278
|
+
() => {},
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
assertDeepEqual(cachedData, requestData, 'cached union data should only require fields for the matching inline fragment type');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
Deno.test('resetQuery reset-only clears matching query cache and notifies observers without force refetch', () => {
|
|
285
|
+
resetCacheState();
|
|
286
|
+
|
|
287
|
+
const gqlQuery = makeQuery('logEntries', [
|
|
288
|
+
makeField('id'),
|
|
289
|
+
makeField('status'),
|
|
290
|
+
]);
|
|
291
|
+
const variablesKey = makeVariablesKey({
|
|
292
|
+
organizationId: 'org-1',
|
|
293
|
+
});
|
|
294
|
+
const requestData = {
|
|
295
|
+
logEntries: [{
|
|
296
|
+
id: 'log-1',
|
|
297
|
+
status: 'COMPLETED',
|
|
298
|
+
}],
|
|
299
|
+
};
|
|
300
|
+
const observerArgs: any[] = [];
|
|
301
|
+
|
|
302
|
+
setDataToCache(requestData, gqlQuery, variablesKey);
|
|
303
|
+
resetQuery('#logEntries:', false, (args) => {
|
|
304
|
+
observerArgs.push(args);
|
|
305
|
+
}, true);
|
|
306
|
+
|
|
307
|
+
const cachedData = fetchCachedData(
|
|
308
|
+
gqlQuery,
|
|
309
|
+
variablesKey,
|
|
310
|
+
() => {},
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
assertDeepEqual(observerArgs, [{
|
|
314
|
+
queryId: '#logEntries:',
|
|
315
|
+
forceRefetch: false,
|
|
316
|
+
resetOnly: true,
|
|
317
|
+
}], 'reset-only should notify mounted query observers without force refetch');
|
|
318
|
+
assertDeepEqual(cachedData, null, 'reset-only should remove matching cached query data');
|
|
319
|
+
});
|