@jsb188/graphql 1.1.7 → 1.1.8
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/index.ts +76 -15
- package/gql/fragments/storageFragments.ts +3 -0
- package/hooks/use-report-qry.ts +1 -1
- package/package.json +3 -3
package/cache/index.ts
CHANGED
|
@@ -144,7 +144,7 @@ export function loadFragment(id: string) {
|
|
|
144
144
|
return fragment;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
// const isTest = id.startsWith('$
|
|
147
|
+
// const isTest = id.startsWith('$reportFragment:3789505824043091-4255281447699102-3789105884863193');
|
|
148
148
|
// if (isTest) {
|
|
149
149
|
// ..
|
|
150
150
|
// }
|
|
@@ -155,8 +155,12 @@ export function loadFragment(id: string) {
|
|
|
155
155
|
if (Object.prototype.hasOwnProperty.call(spreads, key)) {
|
|
156
156
|
const spreadValue = spreads[key];
|
|
157
157
|
|
|
158
|
+
// if (isInnerTest) {
|
|
159
|
+
// console.log('SPREAD:', key, '->', spreadValue, typeof spreadValue);
|
|
160
|
+
// }
|
|
161
|
+
|
|
158
162
|
// if (isTest) {
|
|
159
|
-
// console.log('SPREAD:', key, '->', spreadValue);
|
|
163
|
+
// console.log('SPREAD:', key, '->', spreadValue, typeof spreadValue);
|
|
160
164
|
// }
|
|
161
165
|
|
|
162
166
|
let spreadData;
|
|
@@ -164,10 +168,16 @@ export function loadFragment(id: string) {
|
|
|
164
168
|
spreadData = enforceArrayType(FRAGMENTS.get(spreadValue));
|
|
165
169
|
} else if (Array.isArray(spreadValue)) {
|
|
166
170
|
spreadData = spreadValue.reduce((acc, value) => {
|
|
171
|
+
|
|
172
|
+
// if (isTest) {
|
|
173
|
+
// console.log('????', value);
|
|
174
|
+
// }
|
|
175
|
+
|
|
176
|
+
|
|
167
177
|
if (typeof value === 'string') {
|
|
168
178
|
const fragmentData = enforceArrayType(FRAGMENTS.get(value));
|
|
169
179
|
|
|
170
|
-
// if (isTest
|
|
180
|
+
// if (isTest) {
|
|
171
181
|
// console.log('1:', value, fragmentData);
|
|
172
182
|
// }
|
|
173
183
|
|
|
@@ -177,8 +187,6 @@ export function loadFragment(id: string) {
|
|
|
177
187
|
};
|
|
178
188
|
} else if (Array.isArray(value)) {
|
|
179
189
|
const [namespace, innerValue] = value;
|
|
180
|
-
// console.log('2:', namespace, value);
|
|
181
|
-
|
|
182
190
|
return {
|
|
183
191
|
...acc,
|
|
184
192
|
[namespace]: innerValue,
|
|
@@ -190,13 +198,29 @@ export function loadFragment(id: string) {
|
|
|
190
198
|
} else if (spreadValue?.__list === true) {
|
|
191
199
|
spreadData = spreadValue.data.map((val: any) => {
|
|
192
200
|
|
|
201
|
+
// if (isTest) {
|
|
202
|
+
// console.log('>>> VAL:', val);
|
|
203
|
+
// }
|
|
204
|
+
|
|
193
205
|
// NOTE: I haven't fully finished this work,
|
|
194
206
|
// but it should work for most cases.
|
|
195
207
|
|
|
196
208
|
if (typeof val === 'string') {
|
|
197
209
|
return loadFragment(val);
|
|
198
210
|
} else if (Array.isArray(val) && typeof val[0] === 'string' && val[0].startsWith('$')) {
|
|
199
|
-
|
|
211
|
+
const [innerFragmentKey, ...restInner] = val;
|
|
212
|
+
const innerFragment = loadFragment(innerFragmentKey);
|
|
213
|
+
|
|
214
|
+
if (innerFragment) {
|
|
215
|
+
for (const ri of restInner) {
|
|
216
|
+
if (Array.isArray(ri) && ri.length === 2) {
|
|
217
|
+
// ri[0] === 'files' && ri[1].length === 1 && console.log(ri);
|
|
218
|
+
// innerFragment[ri[0]] = ri[1];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return innerFragment;
|
|
200
224
|
}
|
|
201
225
|
|
|
202
226
|
// Unfinished work
|
|
@@ -264,8 +288,13 @@ function mapSelections(data: any, innerSelections: any[], updatedKeys: string[]
|
|
|
264
288
|
// Because partials might have data that's not in the main fragment
|
|
265
289
|
const currentData = loadFragment(fragmentKey);
|
|
266
290
|
|
|
267
|
-
//
|
|
268
|
-
//
|
|
291
|
+
// console.log(fragmentKey);
|
|
292
|
+
// if (fragmentKey.startsWith('$reportFragment:3789505824043091-4255281447699102-3789105884863193')) {
|
|
293
|
+
// console.log('>>>>');
|
|
294
|
+
// console.log('>>>>');
|
|
295
|
+
// console.log('>>>>');
|
|
296
|
+
// console.log('>>>>');
|
|
297
|
+
// console.log(currentData);
|
|
269
298
|
// console.log(data);
|
|
270
299
|
// console.log(extractFragment(data, innerSelections));
|
|
271
300
|
// }
|
|
@@ -344,6 +373,15 @@ function makeCacheObject(data: any, selections: any[], variables?: any, cacheMap
|
|
|
344
373
|
// Because partials might have data that's not in the main fragment
|
|
345
374
|
const currentData = loadFragment(fragmentKey);
|
|
346
375
|
|
|
376
|
+
// if (fragmentKey.startsWith('$reportFragment:3789505824043091-4255281447699102-3789105884863193')) {
|
|
377
|
+
// console.log('>>>>');
|
|
378
|
+
// console.log('>>>>');
|
|
379
|
+
// console.log('>>>>');
|
|
380
|
+
// console.log('>>>>');
|
|
381
|
+
// console.log(currentData);
|
|
382
|
+
// console.log(data);
|
|
383
|
+
// }
|
|
384
|
+
|
|
347
385
|
// console.log('>>>>', fragmentKey);
|
|
348
386
|
FRAGMENTS.set(fragmentKey, mergeNestedObjects(currentData, extractFragment(data, selections)));
|
|
349
387
|
updatedKeys.push(fragmentKey);
|
|
@@ -578,6 +616,21 @@ export function appendFragmentToCache(cacheData: any, testMode?: boolean) {
|
|
|
578
616
|
if (Array.isArray(d)) {
|
|
579
617
|
if (d.length === 1 && d?.[0]?.startsWith('$')) {
|
|
580
618
|
mapCacheId = d[0];
|
|
619
|
+
} else if (Array.isArray(d[1])) {
|
|
620
|
+
// Use __reactiveFragmentName to make client-side data up to date
|
|
621
|
+
item[d[0]] = d[1].map(dr => {
|
|
622
|
+
if (dr.__reactiveFragmentName) {
|
|
623
|
+
const crFKey = `${dr.__reactiveFragmentName}:${dr.id}`;
|
|
624
|
+
return FRAGMENTS.get(crFKey) || dr;
|
|
625
|
+
}
|
|
626
|
+
return dr;
|
|
627
|
+
});
|
|
628
|
+
return;
|
|
629
|
+
} else if (d[1]?.__reactiveFragmentName) {
|
|
630
|
+
// Use __reactiveFragmentName to make client-side data up to date
|
|
631
|
+
const clientReactiveFragmentKey = `${d[1].__reactiveFragmentName}:${d[1].id}`;
|
|
632
|
+
item[d[0]] = FRAGMENTS.get(clientReactiveFragmentKey) || d[1];
|
|
633
|
+
return;
|
|
581
634
|
} else {
|
|
582
635
|
item[d[0]] = d[1];
|
|
583
636
|
return;
|
|
@@ -605,7 +658,6 @@ export function appendFragmentToCache(cacheData: any, testMode?: boolean) {
|
|
|
605
658
|
}
|
|
606
659
|
|
|
607
660
|
const cachedFragment = loadFragment(fragmentKey);
|
|
608
|
-
|
|
609
661
|
if (cachedFragment) {
|
|
610
662
|
item = {
|
|
611
663
|
...item,
|
|
@@ -790,6 +842,15 @@ export function loadDataFromCache(
|
|
|
790
842
|
const fragmentKey = eagerFragmentKeyMap[qryName];
|
|
791
843
|
const cachedFragment = loadFragment(fragmentKey);
|
|
792
844
|
|
|
845
|
+
// if (fragmentKey.startsWith('$reportFragment:3789505824043091-4255281447699102-3789105884863193')) {
|
|
846
|
+
// console.log('>>>>');
|
|
847
|
+
// console.log('>>>>');
|
|
848
|
+
// console.log('>>>>');
|
|
849
|
+
// console.log('>>>>');
|
|
850
|
+
// console.log(cachedFragment);
|
|
851
|
+
// console.log(data);
|
|
852
|
+
// }
|
|
853
|
+
|
|
793
854
|
if (cachedFragment) {
|
|
794
855
|
data[qryName] = cachedFragment;
|
|
795
856
|
}
|
|
@@ -999,13 +1060,13 @@ export function updateFragment(
|
|
|
999
1060
|
updateObj = update;
|
|
1000
1061
|
}
|
|
1001
1062
|
|
|
1002
|
-
const
|
|
1063
|
+
const newUpdatedObj = { ...cache, ...updateObj };
|
|
1003
1064
|
|
|
1004
|
-
FRAGMENTS.set(updateFragmentKey,
|
|
1005
|
-
console.dev('✅ FRAGMENT UPDATED ->', updateFragmentKey,
|
|
1065
|
+
FRAGMENTS.set(updateFragmentKey, newUpdatedObj);
|
|
1066
|
+
console.dev('✅ FRAGMENT UPDATED ->', updateFragmentKey, newUpdatedObj);
|
|
1006
1067
|
|
|
1007
1068
|
if (replacementFragmentKey && replacementFragmentKey !== updateFragmentKey) {
|
|
1008
|
-
FRAGMENTS.set(replacementFragmentKey,
|
|
1069
|
+
FRAGMENTS.set(replacementFragmentKey, newUpdatedObj);
|
|
1009
1070
|
}
|
|
1010
1071
|
|
|
1011
1072
|
if (!doNotTriggerObserver && updateObservers) {
|
|
@@ -1047,10 +1108,10 @@ export function updateQuery(
|
|
|
1047
1108
|
updateObj = update;
|
|
1048
1109
|
}
|
|
1049
1110
|
|
|
1050
|
-
const
|
|
1111
|
+
const newUpdatedObj = Array.isArray(updateObj) ? updateObj : { ...cache, ...updateObj };
|
|
1051
1112
|
|
|
1052
1113
|
// console.log('UPDATING (3):', updateObj);
|
|
1053
|
-
QUERIES.set(queryId,
|
|
1114
|
+
QUERIES.set(queryId, newUpdatedObj);
|
|
1054
1115
|
|
|
1055
1116
|
if (!doNotTriggerObserver && updateObservers) {
|
|
1056
1117
|
updateObservers({
|
package/hooks/use-report-qry.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/graphql",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "GraphQL client for react, using recoil",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"graphql-tag": "^2.12.6"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@jsb188/app": "1.1.
|
|
52
|
-
"@jsb188/react": "1.1.
|
|
51
|
+
"@jsb188/app": "1.1.8",
|
|
52
|
+
"@jsb188/react": "1.1.8"
|
|
53
53
|
}
|
|
54
54
|
}
|