@jsb188/graphql 1.1.5 → 1.1.7

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.
Files changed (39) hide show
  1. package/cache/config.ts +12 -5
  2. package/cache/index.ts +258 -109
  3. package/gql/fragments/actionFragments.ts +16 -0
  4. package/gql/fragments/logFragments.ts +72 -2
  5. package/gql/fragments/organizationFragments.ts +64 -5
  6. package/gql/fragments/otherFragments.ts +10 -8
  7. package/gql/fragments/productFragments.ts +63 -0
  8. package/gql/fragments/reportFragments.ts +48 -0
  9. package/gql/fragments/storageFragments.ts +11 -0
  10. package/gql/mutations/accountMutations.ts +10 -0
  11. package/gql/mutations/authMutations.ts +11 -16
  12. package/gql/mutations/index.ts +2 -1
  13. package/gql/mutations/logMutations.ts +20 -6
  14. package/gql/mutations/organizationMutations.ts +42 -0
  15. package/gql/mutations/storageMutations.ts +36 -0
  16. package/gql/mutations/userAuthMutations.ts +0 -12
  17. package/gql/queries/aiChatQueries.ts +3 -0
  18. package/gql/queries/index.ts +6 -0
  19. package/gql/queries/logQueries.ts +60 -11
  20. package/gql/queries/organizationQueries.ts +61 -1
  21. package/gql/queries/productQueries.ts +70 -0
  22. package/gql/queries/reportQueries.ts +66 -0
  23. package/hooks/index.ts +146 -45
  24. package/hooks/use-account-mtn.ts +26 -1
  25. package/hooks/use-aiChat-mtn.ts +17 -1
  26. package/hooks/use-aiChat-qry.ts +19 -10
  27. package/hooks/use-auth-mtn.ts +25 -2
  28. package/hooks/use-log-mtn.ts +4 -4
  29. package/hooks/use-log-qry.ts +47 -16
  30. package/hooks/use-organization-mtn.ts +105 -0
  31. package/hooks/use-organization-qry.ts +119 -15
  32. package/hooks/use-product-qry.ts +109 -0
  33. package/hooks/use-report-qry.ts +69 -0
  34. package/hooks/use-storage-mtn.ts +56 -0
  35. package/hooks/use-storage-qry.ts +21 -0
  36. package/package.json +14 -11
  37. package/sse.ts +11 -0
  38. package/gql/mutations/otherMutations.ts +0 -46
  39. package/gql/queries/otherQueries.ts +0 -12
package/cache/config.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  export const QUERY_EXPIRE_TIMES = {
8
- __default: 3.6e+6, // 1 hour
8
+ __default: 5.4e+6, // 1.5 hours
9
9
  // 6.48e+7, // 18 hours
10
10
  } as {
11
11
  [key: string]: number;
@@ -22,15 +22,23 @@ export const RULES = {
22
22
  aiChats: true,
23
23
  aiChatMessages: true,
24
24
  alerts: true,
25
- cardsForUser: true,
26
25
  chat: true,
27
26
  chatsList: true,
28
- editChat: true,
29
- friend: true,
27
+ childOrganizations: true,
28
+ eventsList: true,
29
+ eventAttendanceList: true,
30
+ parentOrganization: true,
30
31
  logEntries: true,
32
+ logEvidences: true,
31
33
  myChats: true,
34
+ myOrganizations: true,
32
35
  organizationRelationship: true,
36
+ organizationWorkflows: true,
33
37
  platformProducts: true,
38
+ productAttendanceList: true,
39
+ productsList: true,
40
+ reports: true,
41
+ availableReports: true,
34
42
  searchUsers: true,
35
43
  updateNote: true,
36
44
  userIdToChatId: true,
@@ -47,5 +55,4 @@ export const PARTIALS_MAP = {
47
55
  // Partial fragments are supported if you map them to its original fragment name
48
56
  chatPartial: 'chatFragment',
49
57
  chatStatusPartial: 'chatFragment',
50
- userPartial: 'userFragment',
51
58
  } as Record<string, string>;
package/cache/index.ts CHANGED
@@ -1,14 +1,11 @@
1
- import { cloneArrayLike, mapArrayLikeObjects } from '@jsb188/app/utils/object';
1
+ import { makeVariablesKey } from '@jsb188/app/utils/logic';
2
+ import { cloneArrayLike, mapArrayLikeObjects, uniq } from '@jsb188/app/utils/object';
2
3
  import type { UpdateObserversFn } from '../types.d';
3
4
  import { PARTIALS_MAP, RULES } from './config';
4
5
 
5
- const DO_LOG = [
6
- false, // [0] Log name
7
- false, // [1] Log data
8
- ];
9
-
10
6
  const QUERIES = new Map();
11
7
  const FRAGMENTS = new Map();
8
+ const RESET_TIME = new Map();
12
9
 
13
10
  /**
14
11
  * JS Map will sometimes convert nested Array into Array-like Object
@@ -43,7 +40,7 @@ function enforceArrayType(obj: any): any {
43
40
  * Merge nested objects together
44
41
  */
45
42
 
46
- export function mergeNestedObjects(obj1: any, obj2: any) {
43
+ function mergeNestedObjects(obj1: any, obj2: any) {
47
44
  if (!obj1) {
48
45
  return { ...obj2 };
49
46
  }
@@ -62,40 +59,11 @@ export function mergeNestedObjects(obj1: any, obj2: any) {
62
59
  return newObj;
63
60
  }
64
61
 
65
- /**
66
- * Get a single string to represent all variables for a query
67
- * NOTE: This isn't perfect because variables could have extra or unnnecessary keys/values
68
- * The correct way to do this would be to compare it against the query {variableDefinitions}
69
- * But this will work as long as each variables object is used consistently to match the used query.
70
- *
71
- * NOTE: Same logic is used in SSE [publish.ts]
72
- */
73
-
74
- export function makeVariablesKey(variables?: any) {
75
- if (variables) {
76
- const key = Object.keys(variables).sort().reduce((acc, key) => {
77
- const value = variables[key];
78
- if (value || value === 0 || value === false) {
79
- return `${acc}$${key}:${typeof value === 'object' ? JSON.stringify(value) : value}`;
80
- }
81
- return acc;
82
- }, '');
83
-
84
- // NOTE: I can't think of a query where capitalization matters;
85
- // So I'm doing lowerCase() here.
86
- // Also, I don't think there's any query where null/undefined matters;
87
- // So I'm omitting all of those.
88
-
89
- return key.toLowerCase();
90
- }
91
- return 'none';
92
- }
93
-
94
62
  /**
95
63
  * Make Object for fragment, omitting what you don't need
96
64
  */
97
65
 
98
- function extractFragment(dataObj: any, innerSelection: any[]) {
66
+ function extractFragment(dataObj: any, innerSelection: any[], isTest?: boolean) {
99
67
  if (innerSelection.length <= 1) {
100
68
  return dataObj;
101
69
  }
@@ -152,7 +120,9 @@ export function loadQuery(queryKey: string, referencesOnly?: boolean) {
152
120
 
153
121
  return mappedCache;
154
122
  } else if (references) {
155
- const singleCacheData = appendFragmentToCache(references);
123
+ // console.log('references single:', references);
124
+ const singleCacheData = appendFragmentToCache(references, true);
125
+ // console.log('singleCacheData >>>>:', singleCacheData);
156
126
  return singleCacheData;
157
127
  }
158
128
  }
@@ -167,7 +137,6 @@ export function loadFragment(id: string) {
167
137
  const fragment = enforceArrayType(FRAGMENTS.get(id));
168
138
  if (!fragment) {
169
139
  return null;
170
-
171
140
  }
172
141
 
173
142
  const spreads = FRAGMENTS.get(`${id}.spreads`);
@@ -175,11 +144,67 @@ export function loadFragment(id: string) {
175
144
  return fragment;
176
145
  }
177
146
 
147
+ // const isTest = id.startsWith('$logEntryFragment:9479647167133727') && false;
148
+ // if (isTest) {
149
+ // ..
150
+ // }
151
+
178
152
  let fragmentWithSpreads = { ...fragment };
179
153
  for (const key in spreads) {
154
+
180
155
  if (Object.prototype.hasOwnProperty.call(spreads, key)) {
181
- const spreadId = spreads[key];
182
- const spreadData = enforceArrayType(FRAGMENTS.get(spreadId));
156
+ const spreadValue = spreads[key];
157
+
158
+ // if (isTest) {
159
+ // console.log('SPREAD:', key, '->', spreadValue);
160
+ // }
161
+
162
+ let spreadData;
163
+ if (typeof spreadValue === 'string') {
164
+ spreadData = enforceArrayType(FRAGMENTS.get(spreadValue));
165
+ } else if (Array.isArray(spreadValue)) {
166
+ spreadData = spreadValue.reduce((acc, value) => {
167
+ if (typeof value === 'string') {
168
+ const fragmentData = enforceArrayType(FRAGMENTS.get(value));
169
+
170
+ // if (isTest && key === 'details') {
171
+ // console.log('1:', value, fragmentData);
172
+ // }
173
+
174
+ return {
175
+ ...acc,
176
+ ...fragmentData,
177
+ };
178
+ } else if (Array.isArray(value)) {
179
+ const [namespace, innerValue] = value;
180
+ // console.log('2:', namespace, value);
181
+
182
+ return {
183
+ ...acc,
184
+ [namespace]: innerValue,
185
+ };
186
+ }
187
+
188
+ return acc;
189
+ }, {});
190
+ } else if (spreadValue?.__list === true) {
191
+ spreadData = spreadValue.data.map((val: any) => {
192
+
193
+ // NOTE: I haven't fully finished this work,
194
+ // but it should work for most cases.
195
+
196
+ if (typeof val === 'string') {
197
+ return loadFragment(val);
198
+ } else if (Array.isArray(val) && typeof val[0] === 'string' && val[0].startsWith('$')) {
199
+ return loadFragment(val[0]);
200
+ }
201
+
202
+ // Unfinished work
203
+ console.warn('Unfinished GraphQL cache scenario!: ', val)
204
+ return null;
205
+ }).filter(Boolean);
206
+ }
207
+
183
208
  if (spreadData) {
184
209
  fragmentWithSpreads[key] = spreadData;
185
210
  }
@@ -194,6 +219,7 @@ export function loadFragment(id: string) {
194
219
  */
195
220
 
196
221
  function mapSelections(data: any, innerSelections: any[], updatedKeys: string[] = []) {
222
+
197
223
  return innerSelections.map((inner) => {
198
224
 
199
225
  let fragmentKey;
@@ -201,17 +227,35 @@ function mapSelections(data: any, innerSelections: any[], updatedKeys: string[]
201
227
  // These are fragment spreads
202
228
  const frgName = inner.name.value;
203
229
  const frgMap = PARTIALS_MAP[frgName];
230
+
204
231
  fragmentKey = `$${frgMap || frgName}:${data.id || 'none'}`;
205
232
 
206
- if (DO_LOG[0]) {
207
- console.log('SETTING (1): ', fragmentKey);
208
- }
209
- if (DO_LOG[1]) {
210
- console.log('SETTING (1): ', extractFragment(data, innerSelections));
233
+ } else if (inner.kind === 'Field' && inner.selectionSet && inner.selectionSet.selections?.length) {
234
+
235
+ // These are nested fragments, they need to be cached as a fragment
236
+
237
+ const innerData = data?.[inner.name.value];
238
+ const innerSelections = inner.selectionSet.selections?.filter((sel: any) => sel.kind === 'FragmentSpread');
239
+
240
+ if (innerData && Array.isArray(innerSelections)) {
241
+ if (Array.isArray(innerData)) {
242
+ for (const item of innerData) {
243
+ mapSelections(item, inner.selectionSet.selections, updatedKeys);
244
+ }
245
+ } else {
246
+ mapSelections(innerData, inner.selectionSet.selections, updatedKeys);
247
+ }
211
248
  }
249
+
212
250
  } else if (inner.kind === 'InlineFragment') {
213
251
  // This is Union, etc
214
252
  const frgNamesJoined = inner.selectionSet.selections.map((sel: any) => PARTIALS_MAP[sel.name.value] || sel.name.value).join('.');
253
+
254
+ if (frgNamesJoined.toLowerCase().indexOf(data.__typename.toLowerCase()) < 0) {
255
+ // This is untested, but should be fine
256
+ return null;
257
+ }
258
+
215
259
  fragmentKey = `$${frgNamesJoined}:${data.id || 'none'}`;
216
260
  }
217
261
 
@@ -220,7 +264,14 @@ function mapSelections(data: any, innerSelections: any[], updatedKeys: string[]
220
264
  // Because partials might have data that's not in the main fragment
221
265
  const currentData = loadFragment(fragmentKey);
222
266
 
223
- FRAGMENTS.set(fragmentKey, mergeNestedObjects(currentData, extractFragment(data, innerSelections)));
267
+ // if (fragmentKey.startsWith('$accountFragment:')) {
268
+ // console.log('>>>>', fragmentKey);
269
+ // console.log(data);
270
+ // console.log(extractFragment(data, innerSelections));
271
+ // }
272
+
273
+ const fragmentFromData = extractFragment(data, innerSelections);
274
+ FRAGMENTS.set(fragmentKey, mergeNestedObjects(currentData, fragmentFromData));
224
275
  updatedKeys.push(fragmentKey);
225
276
 
226
277
  return fragmentKey;
@@ -235,7 +286,7 @@ function mapSelections(data: any, innerSelections: any[], updatedKeys: string[]
235
286
  // name: inner.name.value,
236
287
  // value: data[key]?.[inner.name.value]
237
288
  // };
238
- });
289
+ }).filter(Boolean);
239
290
  }
240
291
 
241
292
  /**
@@ -253,10 +304,6 @@ function makeCacheObject(data: any, selections: any[], variables?: any, cacheMap
253
304
  continue;
254
305
  }
255
306
 
256
- // if (DO_LOG[2]) {
257
- // console.log(sel);
258
- // }
259
-
260
307
  switch (sel.kind) {
261
308
  case 'Field':
262
309
  {
@@ -286,13 +333,6 @@ function makeCacheObject(data: any, selections: any[], variables?: any, cacheMap
286
333
  const fragmentKey = `$${frgMap || frgName}:${data.id || 'none'}`;
287
334
 
288
335
  if (RULES[frgName] !== false) {
289
- if (DO_LOG[0]) {
290
- console.log('SETTING (2): ', fragmentKey);
291
- }
292
- if (DO_LOG[1]) {
293
- console.log('SETTING (2): ', extractFragment(data, selections));
294
- }
295
-
296
336
  // if (testMode) {
297
337
  // console.log('Array.isArray(data)');
298
338
  // console.log(Array.isArray(data));
@@ -304,6 +344,7 @@ function makeCacheObject(data: any, selections: any[], variables?: any, cacheMap
304
344
  // Because partials might have data that's not in the main fragment
305
345
  const currentData = loadFragment(fragmentKey);
306
346
 
347
+ // console.log('>>>>', fragmentKey);
307
348
  FRAGMENTS.set(fragmentKey, mergeNestedObjects(currentData, extractFragment(data, selections)));
308
349
  updatedKeys.push(fragmentKey);
309
350
  }
@@ -332,21 +373,40 @@ function makeCacheObject(data: any, selections: any[], variables?: any, cacheMap
332
373
  if (cacheObj.__flat?.data?.[0]) {
333
374
  const spreadsFragmentKey = `${cacheObj.__flat.data[0]}.spreads`;
334
375
 
335
- let spreads: Record<string, string> | undefined;
376
+ let spreads: Record<string, any> | undefined;
336
377
  for (const cKey in cacheObj) {
337
378
  if (
338
379
  cKey !== '__flat' &&
339
- Object.prototype.hasOwnProperty.call(cacheObj, cKey) &&
340
- typeof cacheObj[cKey]?.data?.[0] === 'string'
380
+ Object.prototype.hasOwnProperty.call(cacheObj, cKey)
341
381
  ) {
342
382
  if (!spreads) {
343
383
  spreads = {};
344
384
  }
345
- spreads[cKey] = cacheObj[cKey].data[0];
385
+
386
+ // Spreads here
387
+
388
+ if (cacheObj[cKey]?.data?.length === 1 && typeof cacheObj[cKey]?.data?.[0] === 'string') {
389
+ // Single spread with single fragment
390
+ spreads[cKey] = cacheObj[cKey].data[0];
391
+ } else if (cacheObj[cKey].__list === true) {
392
+ // List of spreads
393
+ spreads[cKey] = {
394
+ __list: true,
395
+ data: cacheObj[cKey].data
396
+ };
397
+ } else if (Array.isArray(cacheObj[cKey]?.data)) {
398
+ // Spread with more spreads inside
399
+ spreads[cKey] = cacheObj[cKey].data;
400
+ }
346
401
  }
347
402
  }
348
403
 
349
404
  if (spreads) {
405
+ // if (spreadsFragmentKey.startsWith('$emailFragment:')) {
406
+ // console.log('>>>>', spreadsFragmentKey);
407
+ // console.log(data);
408
+ // console.log(spreads);
409
+ // }
350
410
  FRAGMENTS.set(spreadsFragmentKey, spreads);
351
411
  }
352
412
  }
@@ -410,6 +470,7 @@ function saveQueryToMemory(
410
470
  if (saveQueryToCache) {
411
471
  const customCacheData = cacheMap(data, cacheData, selections, variables);
412
472
  // console.log('1--->', queryId);
473
+ // console.log('UPDATING (1):', typeof customCacheData === 'undefined' ? null : customCacheData);
413
474
  QUERIES.set(queryId, typeof customCacheData === 'undefined' ? null : customCacheData);
414
475
 
415
476
  if (updateObservers) {
@@ -422,6 +483,7 @@ function saveQueryToMemory(
422
483
  if (saveQueryToCache) {
423
484
  // console.log('2--->', queryId);
424
485
  // console.log('2--->', cacheData);
486
+ // console.log('UPDATING (2):', cacheData);
425
487
  QUERIES.set(queryId, cacheData);
426
488
  }
427
489
 
@@ -486,58 +548,72 @@ export function setDataToCache(
486
548
 
487
549
  export function appendFragmentToCache(cacheData: any, testMode?: boolean) {
488
550
  let newObj = cloneArrayLike(cacheData);
551
+ let flatObj: any;
489
552
 
490
553
  // if (testMode) {
491
554
  // console.log('appendFragmentToCache:', newObj);
492
555
  // }
493
556
 
494
557
  for (const key in newObj) {
558
+
559
+ // if (testMode) {
560
+ // console.log('******* key:', key);
561
+ // console.log('******* ??:', newObj[key]);
562
+ // }
563
+
495
564
  if (newObj[key] && typeof newObj[key] === 'object') {
496
565
  const isFlat = key === '__flat';
497
566
  const isCache = newObj[key].__cache && newObj[key].data;
498
567
 
499
568
  if (isCache) {
500
-
501
569
  let cachedObj = {};
502
570
  let cacheIsValid = true;
503
571
 
504
572
  if (newObj[key].__list) {
505
-
506
573
  cachedObj = newObj[key].data.map((di: any[]) => {
507
574
 
508
575
  let item = {};
509
576
  di.forEach((d) => {
577
+ let mapCacheId;
510
578
  if (Array.isArray(d)) {
511
- item[d[0]] = d[1];
512
- } else if (typeof d === 'string') {
513
- const frgIndex = d.indexOf(':');
514
- const frgName = d.substring(1, frgIndex);
515
- const frgMap = PARTIALS_MAP[frgName];
516
-
517
- let fragmentKey;
518
- if (frgMap) {
519
- fragmentKey = `$${frgMap}:${d.substring(frgIndex + 1)}`;
579
+ if (d.length === 1 && d?.[0]?.startsWith('$')) {
580
+ mapCacheId = d[0];
520
581
  } else {
521
- fragmentKey = d;
582
+ item[d[0]] = d[1];
583
+ return;
522
584
  }
585
+ } else if (typeof d === 'string') {
586
+ mapCacheId = d;
587
+ }
523
588
 
524
- const cachedFragment = loadFragment(fragmentKey);
525
- if (DO_LOG[0]) {
526
- console.log('LOAD (1): ', d);
527
- }
528
- if (DO_LOG[1]) {
529
- console.log('LOAD (1): ', cachedFragment);
530
- }
589
+ // if (Array.isArray(d)) {
590
+ // item[d[0]] = d[1];
591
+ // return;
592
+ // } else if (typeof d === 'string') {
593
+ // mapCacheId = d;
594
+ // }
531
595
 
532
- if (cachedFragment) {
533
- item = {
534
- ...item,
535
- ...cachedFragment,
536
- };
537
- } else {
538
- // Cache was invalidated
539
- cacheIsValid = false;
540
- }
596
+ const frgIndex = mapCacheId.indexOf(':');
597
+ const frgName = mapCacheId.substring(1, frgIndex);
598
+ const frgMap = PARTIALS_MAP[frgName];
599
+
600
+ let fragmentKey;
601
+ if (frgMap) {
602
+ fragmentKey = `$${frgMap}:${mapCacheId.substring(frgIndex + 1)}`;
603
+ } else {
604
+ fragmentKey = mapCacheId;
605
+ }
606
+
607
+ const cachedFragment = loadFragment(fragmentKey);
608
+
609
+ if (cachedFragment) {
610
+ item = {
611
+ ...item,
612
+ ...cachedFragment,
613
+ };
614
+ } else {
615
+ // Cache was invalidated
616
+ cacheIsValid = false;
541
617
  }
542
618
  });
543
619
 
@@ -568,19 +644,23 @@ export function appendFragmentToCache(cacheData: any, testMode?: boolean) {
568
644
  }
569
645
 
570
646
  const cachedFragment = loadFragment(fragmentKey);
571
- if (DO_LOG[0]) {
572
- console.log('LOAD (2): ', d);
573
- }
574
- if (DO_LOG[1]) {
575
- console.log('LOAD (2): ', cachedFragment);
576
- }
577
647
 
578
648
  if (cachedFragment) {
579
649
  if (isFlat) {
580
- newObj = {
581
- ...newObj,
582
- ...cachedFragment,
583
- };
650
+ // if (testMode) {
651
+ // console.log('///////');
652
+ // console.log('///////');
653
+ // console.log('newObj before:', newObj);
654
+ // console.log('fragmentKey:', fragmentKey);
655
+ // console.log('cachedFragment:', cachedFragment);
656
+ // }
657
+
658
+ // newObj = {
659
+ // ...newObj,
660
+ // ...cachedFragment,
661
+ // };
662
+
663
+ flatObj = cachedFragment,
584
664
  delete newObj.__flat;
585
665
  } else {
586
666
  cachedObj = {
@@ -624,6 +704,17 @@ export function appendFragmentToCache(cacheData: any, testMode?: boolean) {
624
704
  }
625
705
  }
626
706
 
707
+ // Merge flat data
708
+
709
+ if (flatObj) {
710
+ for (const key in flatObj) {
711
+ // console.log('FLAT:', key, flatObj[key], newObj[key]);
712
+ if (newObj[key] === undefined) {
713
+ newObj[key] = flatObj[key];
714
+ }
715
+ }
716
+ }
717
+
627
718
  return newObj;
628
719
  }
629
720
 
@@ -820,8 +911,36 @@ export function clearGraphQLClientCache() {
820
911
  FRAGMENTS.clear();
821
912
  }
822
913
 
914
+ /**
915
+ * Check if query was reset (used on mount to check if a new fetch is needed)
916
+ */
917
+
918
+ export function getQueryRefreshTime(queryName: string, variablesKey: string) {
919
+ // if (RESET_TIME.get(`#${queryName}:`) || RESET_TIME.get(`#${queryName}:${variablesKey}`)) {
920
+ // console.log(`#${queryName}:${variablesKey}`);
921
+ // console.log('1 >>>>>>>', RESET_TIME.get(`#${queryName}:`));
922
+ // console.log('2 >>>>>>>', RESET_TIME.get(`#${queryName}:${variablesKey}`));
923
+ // }
924
+
925
+ return (
926
+ RESET_TIME.get(`#${queryName}:`) ||
927
+ RESET_TIME.get(`#${queryName}:${variablesKey}`)
928
+ );
929
+ }
930
+
931
+ /**
932
+ * Clear the reset status of a query
933
+ */
934
+
935
+ export function clearQueryResetStatus(queryName: string, variablesKey: string) {
936
+ RESET_TIME.delete(`#${queryName}:`);
937
+ RESET_TIME.delete(`#${queryName}:${variablesKey}`);
938
+ }
939
+
823
940
  /**
824
941
  * Clear query cache
942
+ * NOTE: If "queryId" is a name of query postfixed by ":" like this => "#queryName:"
943
+ * it will reset all queries everywhere for the same GraphQL query.
825
944
  */
826
945
 
827
946
  export function resetQuery(queryId: string, forceRefetch?: boolean, updateObservers?: UpdateObserversFn) {
@@ -830,10 +949,31 @@ export function resetQuery(queryId: string, forceRefetch?: boolean, updateObserv
830
949
  // }
831
950
 
832
951
  if (updateObservers) {
833
- updateObservers({
834
- queryId,
835
- forceRefetch,
836
- });
952
+ if (queryId.startsWith('^')) {
953
+ // Reset using regex
954
+ const regex = new RegExp(queryId);
955
+
956
+ // Loop for each of QUERIES map keys
957
+ for (const key of QUERIES.keys()) {
958
+ if (regex.test(key)) {
959
+ RESET_TIME.set(key, Date.now());
960
+ console.dev('✅ RESET ->', key);
961
+ updateObservers({
962
+ queryId: key,
963
+ forceRefetch,
964
+ });
965
+ }
966
+ }
967
+ } else {
968
+ // Reset specific query
969
+ RESET_TIME.set(queryId, Date.now());
970
+ console.dev('✅ RESET ->', queryId);
971
+ updateObservers({
972
+ queryId,
973
+ forceRefetch,
974
+ });
975
+ }
976
+ // console.log('SETTING ->', queryId, RESET_TIME.get(queryId));
837
977
  }
838
978
  }
839
979
 
@@ -844,9 +984,10 @@ export function resetQuery(queryId: string, forceRefetch?: boolean, updateObserv
844
984
  export function updateFragment(
845
985
  updateFragmentKey: string,
846
986
  update: any | ((cache: any) => any),
847
- replaceId?: string | null,
987
+ replacementFragmentKey?: string | null,
848
988
  doNotTriggerObserver?: boolean,
849
989
  updateObservers?: UpdateObserversFn,
990
+ otherUpdatedFragmentKeys?: string[],
850
991
  ) {
851
992
  const cache = loadFragment(updateFragmentKey);
852
993
 
@@ -861,14 +1002,20 @@ export function updateFragment(
861
1002
  const updatedObj = { ...cache, ...updateObj };
862
1003
 
863
1004
  FRAGMENTS.set(updateFragmentKey, updatedObj);
1005
+ console.dev('✅ FRAGMENT UPDATED ->', updateFragmentKey, updatedObj);
864
1006
 
865
- if (replaceId && replaceId !== updateFragmentKey) {
866
- FRAGMENTS.set(replaceId, updatedObj);
1007
+ if (replacementFragmentKey && replacementFragmentKey !== updateFragmentKey) {
1008
+ FRAGMENTS.set(replacementFragmentKey, updatedObj);
867
1009
  }
868
1010
 
869
1011
  if (!doNotTriggerObserver && updateObservers) {
1012
+ let observingFragmentIds = [updateFragmentKey];
1013
+ if (Array.isArray(otherUpdatedFragmentKeys)) {
1014
+ observingFragmentIds = uniq(observingFragmentIds.concat(otherUpdatedFragmentKeys));
1015
+ }
1016
+
870
1017
  updateObservers({
871
- fragmentIds: [updateFragmentKey],
1018
+ fragmentIds: observingFragmentIds,
872
1019
  });
873
1020
 
874
1021
  // FRAGMENT_OBSERVER.value = {
@@ -901,6 +1048,8 @@ export function updateQuery(
901
1048
  }
902
1049
 
903
1050
  const updatedObj = Array.isArray(updateObj) ? updateObj : { ...cache, ...updateObj };
1051
+
1052
+ // console.log('UPDATING (3):', updateObj);
904
1053
  QUERIES.set(queryId, updatedObj);
905
1054
 
906
1055
  if (!doNotTriggerObserver && updateObservers) {
@@ -0,0 +1,16 @@
1
+
2
+ export const actionTaskFragment = `fragment actionTaskFragment on ActionTask {
3
+ id
4
+ logId
5
+
6
+ title
7
+ message
8
+ instruction
9
+
10
+ scheduledAt
11
+ delay
12
+ completed
13
+
14
+ createdAt
15
+ updatedAt
16
+ }`;