@isograph/react 0.0.0-main-81ce1b46 → 0.0.0-main-a33a3ba5
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/dist/core/cache.d.ts +1 -1
- package/dist/core/cache.js +15 -15
- package/package.json +4 -4
- package/src/core/cache.ts +21 -22
package/dist/core/cache.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function getOrCreateCacheForArtifact<TReadFromStore extends {
|
|
|
20
20
|
data: object;
|
|
21
21
|
}, TClientFieldValue>(environment: IsographEnvironment, entrypoint: IsographEntrypoint<TReadFromStore, TClientFieldValue>, variables: ExtractParameters<TReadFromStore>, fetchOptions?: FetchOptions): ParentCache<FragmentReference<TReadFromStore, TClientFieldValue>>;
|
|
22
22
|
type NetworkResponseScalarValue = string | number | boolean;
|
|
23
|
-
type NetworkResponseValue = NetworkResponseScalarValue | null | NetworkResponseObject | NetworkResponseObject[] | NetworkResponseScalarValue[];
|
|
23
|
+
type NetworkResponseValue = NetworkResponseScalarValue | null | NetworkResponseObject | (NetworkResponseObject | null)[] | (NetworkResponseScalarValue | null)[];
|
|
24
24
|
export type NetworkResponseObject = {
|
|
25
25
|
[index: string]: undefined | NetworkResponseValue;
|
|
26
26
|
id?: DataId;
|
package/dist/core/cache.js
CHANGED
|
@@ -274,7 +274,8 @@ function normalizeLinkedField(environment, astNode, networkResponseParentRecord,
|
|
|
274
274
|
targetParentRecord[parentRecordKey] = null;
|
|
275
275
|
return existingValue !== null;
|
|
276
276
|
}
|
|
277
|
-
if (
|
|
277
|
+
if (isScalarOrEmptyArray(networkResponseData) &&
|
|
278
|
+
!isNullOrEmptyArray(networkResponseData)) {
|
|
278
279
|
throw new Error('Unexpected scalar network response when normalizing a linked field');
|
|
279
280
|
}
|
|
280
281
|
if (Array.isArray(networkResponseData)) {
|
|
@@ -282,6 +283,10 @@ function normalizeLinkedField(environment, astNode, networkResponseParentRecord,
|
|
|
282
283
|
const dataIds = [];
|
|
283
284
|
for (let i = 0; i < networkResponseData.length; i++) {
|
|
284
285
|
const networkResponseObject = networkResponseData[i];
|
|
286
|
+
if (networkResponseObject === null) {
|
|
287
|
+
dataIds.push(null);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
285
290
|
const newStoreRecordId = normalizeNetworkResponseObject(environment, astNode, networkResponseObject, targetParentRecordLink, variables, i, nestedRefetchQueries, mutableEncounteredIds);
|
|
286
291
|
dataIds.push({ __link: newStoreRecordId });
|
|
287
292
|
}
|
|
@@ -309,16 +314,15 @@ function normalizeInlineFragment(environment, astNode, networkResponseParentReco
|
|
|
309
314
|
return false;
|
|
310
315
|
}
|
|
311
316
|
function dataIdsAreTheSame(existingValue, newDataIds) {
|
|
317
|
+
var _a;
|
|
312
318
|
if (Array.isArray(existingValue)) {
|
|
313
319
|
if (newDataIds.length !== existingValue.length) {
|
|
314
320
|
return false;
|
|
315
321
|
}
|
|
316
322
|
for (let i = 0; i < newDataIds.length; i++) {
|
|
317
323
|
const maybeLink = (0, IsographEnvironment_1.getLink)(existingValue[i]);
|
|
318
|
-
if (
|
|
319
|
-
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
324
|
+
if (((_a = newDataIds[i]) === null || _a === void 0 ? void 0 : _a.__link) !== (maybeLink === null || maybeLink === void 0 ? void 0 : maybeLink.__link)) {
|
|
325
|
+
return false;
|
|
322
326
|
}
|
|
323
327
|
}
|
|
324
328
|
return true;
|
|
@@ -341,24 +345,20 @@ function isScalarOrEmptyArray(data) {
|
|
|
341
345
|
// This is maybe fixed in a new version of Typescript??
|
|
342
346
|
return data.every((x) => isScalarOrEmptyArray(x));
|
|
343
347
|
}
|
|
344
|
-
const isScalarValue =
|
|
348
|
+
const isScalarValue = data === null ||
|
|
349
|
+
typeof data === 'string' ||
|
|
345
350
|
typeof data === 'number' ||
|
|
346
351
|
typeof data === 'boolean';
|
|
347
352
|
return isScalarValue;
|
|
348
353
|
}
|
|
349
|
-
function
|
|
350
|
-
// N.B. empty arrays count as empty arrays of linked fields.
|
|
354
|
+
function isNullOrEmptyArray(data) {
|
|
351
355
|
if (Array.isArray(data)) {
|
|
352
356
|
if (data.length === 0) {
|
|
353
|
-
return
|
|
357
|
+
return true;
|
|
354
358
|
}
|
|
355
|
-
|
|
356
|
-
return data.every((x) => isScalarOrEmptyArray(x));
|
|
359
|
+
return data.every((x) => isNullOrEmptyArray(x));
|
|
357
360
|
}
|
|
358
|
-
|
|
359
|
-
typeof data === 'number' ||
|
|
360
|
-
typeof data === 'boolean';
|
|
361
|
-
return isScalarValue;
|
|
361
|
+
return data === null;
|
|
362
362
|
}
|
|
363
363
|
function getParentRecordKey(astNode, variables) {
|
|
364
364
|
let parentRecordKey = astNode.fieldName;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isograph/react",
|
|
3
|
-
"version": "0.0.0-main-
|
|
3
|
+
"version": "0.0.0-main-a33a3ba5",
|
|
4
4
|
"description": "Use Isograph with React",
|
|
5
5
|
"homepage": "https://isograph.dev",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"iso-watch": "../../target/debug/isograph_cli --config ./isograph.config.json --watch"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@isograph/disposable-types": "0.0.0-main-
|
|
23
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
|
24
|
-
"@isograph/reference-counted-pointer": "0.0.0-main-
|
|
22
|
+
"@isograph/disposable-types": "0.0.0-main-a33a3ba5",
|
|
23
|
+
"@isograph/react-disposable-state": "0.0.0-main-a33a3ba5",
|
|
24
|
+
"@isograph/reference-counted-pointer": "0.0.0-main-a33a3ba5"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "18.3.1"
|
package/src/core/cache.ts
CHANGED
|
@@ -127,8 +127,8 @@ type NetworkResponseValue =
|
|
|
127
127
|
| NetworkResponseScalarValue
|
|
128
128
|
| null
|
|
129
129
|
| NetworkResponseObject
|
|
130
|
-
| NetworkResponseObject[]
|
|
131
|
-
| NetworkResponseScalarValue[];
|
|
130
|
+
| (NetworkResponseObject | null)[]
|
|
131
|
+
| (NetworkResponseScalarValue | null)[];
|
|
132
132
|
|
|
133
133
|
export type NetworkResponseObject = {
|
|
134
134
|
// N.B. undefined is here to support optional id's, but
|
|
@@ -461,7 +461,10 @@ function normalizeLinkedField(
|
|
|
461
461
|
return existingValue !== null;
|
|
462
462
|
}
|
|
463
463
|
|
|
464
|
-
if (
|
|
464
|
+
if (
|
|
465
|
+
isScalarOrEmptyArray(networkResponseData) &&
|
|
466
|
+
!isNullOrEmptyArray(networkResponseData)
|
|
467
|
+
) {
|
|
465
468
|
throw new Error(
|
|
466
469
|
'Unexpected scalar network response when normalizing a linked field',
|
|
467
470
|
);
|
|
@@ -469,9 +472,13 @@ function normalizeLinkedField(
|
|
|
469
472
|
|
|
470
473
|
if (Array.isArray(networkResponseData)) {
|
|
471
474
|
// TODO check astNode.plural or the like
|
|
472
|
-
const dataIds: Link[] = [];
|
|
475
|
+
const dataIds: (Link | null)[] = [];
|
|
473
476
|
for (let i = 0; i < networkResponseData.length; i++) {
|
|
474
477
|
const networkResponseObject = networkResponseData[i];
|
|
478
|
+
if (networkResponseObject === null) {
|
|
479
|
+
dataIds.push(null);
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
475
482
|
const newStoreRecordId = normalizeNetworkResponseObject(
|
|
476
483
|
environment,
|
|
477
484
|
astNode,
|
|
@@ -539,7 +546,7 @@ function normalizeInlineFragment(
|
|
|
539
546
|
|
|
540
547
|
function dataIdsAreTheSame(
|
|
541
548
|
existingValue: DataTypeValue,
|
|
542
|
-
newDataIds: Link[],
|
|
549
|
+
newDataIds: (Link | null)[],
|
|
543
550
|
): boolean {
|
|
544
551
|
if (Array.isArray(existingValue)) {
|
|
545
552
|
if (newDataIds.length !== existingValue.length) {
|
|
@@ -547,10 +554,8 @@ function dataIdsAreTheSame(
|
|
|
547
554
|
}
|
|
548
555
|
for (let i = 0; i < newDataIds.length; i++) {
|
|
549
556
|
const maybeLink = getLink(existingValue[i]);
|
|
550
|
-
if (
|
|
551
|
-
|
|
552
|
-
return false;
|
|
553
|
-
}
|
|
557
|
+
if (newDataIds[i]?.__link !== maybeLink?.__link) {
|
|
558
|
+
return false;
|
|
554
559
|
}
|
|
555
560
|
}
|
|
556
561
|
return true;
|
|
@@ -596,35 +601,29 @@ function normalizeNetworkResponseObject(
|
|
|
596
601
|
|
|
597
602
|
function isScalarOrEmptyArray(
|
|
598
603
|
data: NonNullable<NetworkResponseValue>,
|
|
599
|
-
): data is NetworkResponseScalarValue | NetworkResponseScalarValue[] {
|
|
604
|
+
): data is NetworkResponseScalarValue | (NetworkResponseScalarValue | null)[] {
|
|
600
605
|
// N.B. empty arrays count as empty arrays of scalar fields.
|
|
601
606
|
if (Array.isArray(data)) {
|
|
602
607
|
// This is maybe fixed in a new version of Typescript??
|
|
603
608
|
return (data as any).every((x: any) => isScalarOrEmptyArray(x));
|
|
604
609
|
}
|
|
605
610
|
const isScalarValue =
|
|
611
|
+
data === null ||
|
|
606
612
|
typeof data === 'string' ||
|
|
607
613
|
typeof data === 'number' ||
|
|
608
614
|
typeof data === 'boolean';
|
|
609
615
|
return isScalarValue;
|
|
610
616
|
}
|
|
611
617
|
|
|
612
|
-
function
|
|
613
|
-
data: NonNullable<NetworkResponseValue>,
|
|
614
|
-
): data is NetworkResponseScalarValue | NetworkResponseScalarValue[] {
|
|
615
|
-
// N.B. empty arrays count as empty arrays of linked fields.
|
|
618
|
+
function isNullOrEmptyArray(data: unknown): data is never[] | null[] | null {
|
|
616
619
|
if (Array.isArray(data)) {
|
|
617
620
|
if (data.length === 0) {
|
|
618
|
-
return
|
|
621
|
+
return true;
|
|
619
622
|
}
|
|
620
|
-
|
|
621
|
-
return (data as any).every((x: any) => isScalarOrEmptyArray(x));
|
|
623
|
+
return data.every((x) => isNullOrEmptyArray(x));
|
|
622
624
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
typeof data === 'number' ||
|
|
626
|
-
typeof data === 'boolean';
|
|
627
|
-
return isScalarValue;
|
|
625
|
+
|
|
626
|
+
return data === null;
|
|
628
627
|
}
|
|
629
628
|
|
|
630
629
|
export function getParentRecordKey(
|