@isograph/react 0.0.0-main-47c37332 → 0.0.0-main-872d4a99
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/cache.js +24 -0
- package/dist/entrypoint.d.ts +6 -1
- package/package.json +3 -3
- package/src/cache.ts +55 -1
- package/src/entrypoint.ts +8 -1
package/dist/cache.js
CHANGED
@@ -7,6 +7,7 @@ const IsographEnvironment_1 = require("./IsographEnvironment");
|
|
7
7
|
const garbageCollection_1 = require("./garbageCollection");
|
8
8
|
const read_1 = require("./read");
|
9
9
|
const areEqualWithDeepComparison_1 = require("./areEqualWithDeepComparison");
|
10
|
+
const TYPENAME_FIELD_NAME = '__typename';
|
10
11
|
function getOrCreateCache(environment, index, factory) {
|
11
12
|
if (typeof window !== 'undefined' && window.__LOG) {
|
12
13
|
console.log('getting cache for', {
|
@@ -211,11 +212,23 @@ function normalizeDataIntoRecord(environment, normalizationAst, networkResponseP
|
|
211
212
|
recordHasBeenUpdated || linkedFieldResultedInChange;
|
212
213
|
break;
|
213
214
|
}
|
215
|
+
case 'InlineFragment': {
|
216
|
+
const inlineFragmentResultedInChange = normalizeInlineFragment(environment, normalizationNode, networkResponseParentRecord, targetParentRecord, targetParentRecordId, variables, nestedRefetchQueries, mutableEncounteredIds);
|
217
|
+
recordHasBeenUpdated =
|
218
|
+
recordHasBeenUpdated || inlineFragmentResultedInChange;
|
219
|
+
break;
|
220
|
+
}
|
221
|
+
default: {
|
222
|
+
// @ts-expect-error(6133)
|
223
|
+
let _ = normalizationNode;
|
224
|
+
throw new Error('Unexpected normalization node kind');
|
225
|
+
}
|
214
226
|
}
|
215
227
|
}
|
216
228
|
if (recordHasBeenUpdated) {
|
217
229
|
mutableEncounteredIds.add(targetParentRecordId);
|
218
230
|
}
|
231
|
+
return recordHasBeenUpdated;
|
219
232
|
}
|
220
233
|
function normalizeScalarField(astNode, networkResponseParentRecord, targetStoreRecord, variables) {
|
221
234
|
const networkResponseKey = getNetworkResponseKey(astNode);
|
@@ -266,6 +279,17 @@ function normalizeLinkedField(environment, astNode, networkResponseParentRecord,
|
|
266
279
|
return (link === null || link === void 0 ? void 0 : link.__link) !== newStoreRecordId;
|
267
280
|
}
|
268
281
|
}
|
282
|
+
/**
|
283
|
+
* Mutate targetParentRecord with a given linked field ast node.
|
284
|
+
*/
|
285
|
+
function normalizeInlineFragment(environment, astNode, networkResponseParentRecord, targetParentRecord, targetParentRecordId, variables, nestedRefetchQueries, mutableEncounteredIds) {
|
286
|
+
const typeToRefineTo = astNode.type;
|
287
|
+
if (networkResponseParentRecord[TYPENAME_FIELD_NAME] === typeToRefineTo) {
|
288
|
+
const hasBeenModified = normalizeDataIntoRecord(environment, astNode.selections, networkResponseParentRecord, targetParentRecord, targetParentRecordId, variables, nestedRefetchQueries, mutableEncounteredIds);
|
289
|
+
return hasBeenModified;
|
290
|
+
}
|
291
|
+
return false;
|
292
|
+
}
|
269
293
|
function dataIdsAreTheSame(existingValue, newDataIds) {
|
270
294
|
if (Array.isArray(existingValue)) {
|
271
295
|
if (newDataIds.length !== existingValue.length) {
|
package/dist/entrypoint.d.ts
CHANGED
@@ -7,7 +7,7 @@ export type IsographEntrypoint<TReadFromStore extends Object, TClientFieldValue>
|
|
7
7
|
readonly readerArtifact: TopLevelReaderArtifact<TReadFromStore, TClientFieldValue, any>;
|
8
8
|
readonly nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[];
|
9
9
|
};
|
10
|
-
export type NormalizationAstNode = NormalizationScalarField | NormalizationLinkedField;
|
10
|
+
export type NormalizationAstNode = NormalizationScalarField | NormalizationLinkedField | NormalizationInlineFragment;
|
11
11
|
export type NormalizationAst = ReadonlyArray<NormalizationAstNode>;
|
12
12
|
export type NormalizationScalarField = {
|
13
13
|
readonly kind: 'Scalar';
|
@@ -20,6 +20,11 @@ export type NormalizationLinkedField = {
|
|
20
20
|
readonly arguments: Arguments | null;
|
21
21
|
readonly selections: NormalizationAst;
|
22
22
|
};
|
23
|
+
export type NormalizationInlineFragment = {
|
24
|
+
readonly kind: 'InlineFragment';
|
25
|
+
readonly type: string;
|
26
|
+
readonly selections: NormalizationAst;
|
27
|
+
};
|
23
28
|
export type RefetchQueryNormalizationArtifact = {
|
24
29
|
readonly kind: 'RefetchQuery';
|
25
30
|
readonly queryText: string;
|
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-872d4a99",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"homepage": "https://isograph.dev",
|
6
6
|
"main": "dist/index.js",
|
@@ -16,8 +16,8 @@
|
|
16
16
|
"prepack": "yarn run test && yarn run compile"
|
17
17
|
},
|
18
18
|
"dependencies": {
|
19
|
-
"@isograph/disposable-types": "0.0.0-main-
|
20
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
19
|
+
"@isograph/disposable-types": "0.0.0-main-872d4a99",
|
20
|
+
"@isograph/react-disposable-state": "0.0.0-main-872d4a99",
|
21
21
|
"react": "^18.2.0"
|
22
22
|
},
|
23
23
|
"devDependencies": {
|
package/src/cache.ts
CHANGED
@@ -22,6 +22,7 @@ import {
|
|
22
22
|
import {
|
23
23
|
IsographEntrypoint,
|
24
24
|
NormalizationAst,
|
25
|
+
NormalizationInlineFragment,
|
25
26
|
NormalizationLinkedField,
|
26
27
|
NormalizationScalarField,
|
27
28
|
RefetchQueryNormalizationArtifact,
|
@@ -33,6 +34,8 @@ import { WithEncounteredRecords, readButDoNotEvaluate } from './read';
|
|
33
34
|
import { FragmentReference, Variables } from './FragmentReference';
|
34
35
|
import { areEqualObjectsWithDeepComparison } from './areEqualWithDeepComparison';
|
35
36
|
|
37
|
+
const TYPENAME_FIELD_NAME = '__typename';
|
38
|
+
|
36
39
|
declare global {
|
37
40
|
interface Window {
|
38
41
|
__LOG: boolean;
|
@@ -345,7 +348,7 @@ function normalizeDataIntoRecord(
|
|
345
348
|
variables: Variables,
|
346
349
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
347
350
|
mutableEncounteredIds: Set<DataId>,
|
348
|
-
) {
|
351
|
+
): RecordHasBeenUpdated {
|
349
352
|
let recordHasBeenUpdated = false;
|
350
353
|
for (const normalizationNode of normalizationAst) {
|
351
354
|
switch (normalizationNode.kind) {
|
@@ -375,11 +378,32 @@ function normalizeDataIntoRecord(
|
|
375
378
|
recordHasBeenUpdated || linkedFieldResultedInChange;
|
376
379
|
break;
|
377
380
|
}
|
381
|
+
case 'InlineFragment': {
|
382
|
+
const inlineFragmentResultedInChange = normalizeInlineFragment(
|
383
|
+
environment,
|
384
|
+
normalizationNode,
|
385
|
+
networkResponseParentRecord,
|
386
|
+
targetParentRecord,
|
387
|
+
targetParentRecordId,
|
388
|
+
variables,
|
389
|
+
nestedRefetchQueries,
|
390
|
+
mutableEncounteredIds,
|
391
|
+
);
|
392
|
+
recordHasBeenUpdated =
|
393
|
+
recordHasBeenUpdated || inlineFragmentResultedInChange;
|
394
|
+
break;
|
395
|
+
}
|
396
|
+
default: {
|
397
|
+
// @ts-expect-error(6133)
|
398
|
+
let _: never = normalizationNode;
|
399
|
+
throw new Error('Unexpected normalization node kind');
|
400
|
+
}
|
378
401
|
}
|
379
402
|
}
|
380
403
|
if (recordHasBeenUpdated) {
|
381
404
|
mutableEncounteredIds.add(targetParentRecordId);
|
382
405
|
}
|
406
|
+
return recordHasBeenUpdated;
|
383
407
|
}
|
384
408
|
|
385
409
|
type RecordHasBeenUpdated = boolean;
|
@@ -474,6 +498,36 @@ function normalizeLinkedField(
|
|
474
498
|
}
|
475
499
|
}
|
476
500
|
|
501
|
+
/**
|
502
|
+
* Mutate targetParentRecord with a given linked field ast node.
|
503
|
+
*/
|
504
|
+
function normalizeInlineFragment(
|
505
|
+
environment: IsographEnvironment,
|
506
|
+
astNode: NormalizationInlineFragment,
|
507
|
+
networkResponseParentRecord: NetworkResponseObject,
|
508
|
+
targetParentRecord: StoreRecord,
|
509
|
+
targetParentRecordId: DataId,
|
510
|
+
variables: Variables,
|
511
|
+
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
512
|
+
mutableEncounteredIds: Set<DataId>,
|
513
|
+
): RecordHasBeenUpdated {
|
514
|
+
const typeToRefineTo = astNode.type;
|
515
|
+
if (networkResponseParentRecord[TYPENAME_FIELD_NAME] === typeToRefineTo) {
|
516
|
+
const hasBeenModified = normalizeDataIntoRecord(
|
517
|
+
environment,
|
518
|
+
astNode.selections,
|
519
|
+
networkResponseParentRecord,
|
520
|
+
targetParentRecord,
|
521
|
+
targetParentRecordId,
|
522
|
+
variables,
|
523
|
+
nestedRefetchQueries,
|
524
|
+
mutableEncounteredIds,
|
525
|
+
);
|
526
|
+
return hasBeenModified;
|
527
|
+
}
|
528
|
+
return false;
|
529
|
+
}
|
530
|
+
|
477
531
|
function dataIdsAreTheSame(
|
478
532
|
existingValue: DataTypeValue,
|
479
533
|
newDataIds: Link[],
|
package/src/entrypoint.ts
CHANGED
@@ -20,7 +20,8 @@ export type IsographEntrypoint<
|
|
20
20
|
|
21
21
|
export type NormalizationAstNode =
|
22
22
|
| NormalizationScalarField
|
23
|
-
| NormalizationLinkedField
|
23
|
+
| NormalizationLinkedField
|
24
|
+
| NormalizationInlineFragment;
|
24
25
|
export type NormalizationAst = ReadonlyArray<NormalizationAstNode>;
|
25
26
|
|
26
27
|
export type NormalizationScalarField = {
|
@@ -36,6 +37,12 @@ export type NormalizationLinkedField = {
|
|
36
37
|
readonly selections: NormalizationAst;
|
37
38
|
};
|
38
39
|
|
40
|
+
export type NormalizationInlineFragment = {
|
41
|
+
readonly kind: 'InlineFragment';
|
42
|
+
readonly type: string;
|
43
|
+
readonly selections: NormalizationAst;
|
44
|
+
};
|
45
|
+
|
39
46
|
// This is more like an entrypoint, but one specifically for a refetch query/mutation
|
40
47
|
export type RefetchQueryNormalizationArtifact = {
|
41
48
|
readonly kind: 'RefetchQuery';
|