@isograph/react 0.0.0-main-cebaca69 → 0.0.0-main-00af1d07
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/FragmentReference.d.ts +2 -2
- package/dist/core/FragmentReference.js +1 -1
- package/dist/core/IsographEnvironment.d.ts +3 -3
- package/dist/core/cache.d.ts +3 -3
- package/dist/core/cache.js +21 -21
- package/dist/core/componentCache.js +3 -4
- package/dist/core/logging.d.ts +3 -3
- package/dist/core/read.d.ts +2 -2
- package/dist/core/read.js +28 -28
- package/dist/core/reader.d.ts +2 -2
- package/dist/react/useImperativeReference.js +1 -1
- package/package.json +4 -4
- package/src/core/FragmentReference.ts +3 -3
- package/src/core/IsographEnvironment.ts +3 -3
- package/src/core/cache.ts +26 -22
- package/src/core/componentCache.ts +4 -4
- package/src/core/logging.ts +3 -3
- package/src/core/read.ts +36 -30
- package/src/core/reader.ts +2 -2
- package/src/react/useImperativeReference.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Link } from './IsographEnvironment';
|
|
2
2
|
import { ReaderWithRefetchQueries } from '../core/entrypoint';
|
|
3
3
|
import { PromiseWrapper } from './PromiseWrapper';
|
|
4
4
|
export type VariableValue = string | number | boolean | null | object;
|
|
@@ -17,7 +17,7 @@ export type FragmentReference<TReadFromStore extends {
|
|
|
17
17
|
}, TClientFieldValue> = {
|
|
18
18
|
readonly kind: 'FragmentReference';
|
|
19
19
|
readonly readerWithRefetchQueries: PromiseWrapper<ReaderWithRefetchQueries<TReadFromStore, TClientFieldValue>>;
|
|
20
|
-
readonly root:
|
|
20
|
+
readonly root: Link;
|
|
21
21
|
readonly variables: ExtractParameters<TReadFromStore>;
|
|
22
22
|
readonly networkRequest: PromiseWrapper<void, any>;
|
|
23
23
|
};
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.stableIdForFragmentReference = stableIdForFragmentReference;
|
|
4
4
|
function stableIdForFragmentReference(fragmentReference) {
|
|
5
5
|
var _a;
|
|
6
|
-
return `${fragmentReference.root}/TODO_FRAGMENT_NAME/${serializeVariables((_a = fragmentReference.variables) !== null && _a !== void 0 ? _a : {})}`;
|
|
6
|
+
return `${fragmentReference.root.__link}/TODO_FRAGMENT_NAME/${serializeVariables((_a = fragmentReference.variables) !== null && _a !== void 0 ? _a : {})}`;
|
|
7
7
|
}
|
|
8
8
|
function serializeVariables(variables) {
|
|
9
9
|
let s = '';
|
|
@@ -29,7 +29,7 @@ export type FragmentSubscription<TReadFromStore extends {
|
|
|
29
29
|
type AnyChangesToRecordSubscription = {
|
|
30
30
|
readonly kind: 'AnyChangesToRecord';
|
|
31
31
|
readonly callback: () => void;
|
|
32
|
-
readonly
|
|
32
|
+
readonly recordLink: Link;
|
|
33
33
|
};
|
|
34
34
|
type AnyRecordSubscription = {
|
|
35
35
|
readonly kind: 'AnyRecords';
|
|
@@ -56,7 +56,7 @@ export type IsographEnvironment = {
|
|
|
56
56
|
readonly gcBufferSize: number;
|
|
57
57
|
readonly loggers: Set<WrappedLogFunction>;
|
|
58
58
|
};
|
|
59
|
-
export type MissingFieldHandler = (storeRecord: StoreRecord, root:
|
|
59
|
+
export type MissingFieldHandler = (storeRecord: StoreRecord, root: Link, fieldName: string, arguments_: {
|
|
60
60
|
[index: string]: any;
|
|
61
61
|
} | null, variables: Variables | null) => Link | undefined;
|
|
62
62
|
export type IsographNetworkFunction = (queryText: string, variables: Variables) => Promise<any>;
|
|
@@ -77,7 +77,7 @@ export type IsographStore = {
|
|
|
77
77
|
};
|
|
78
78
|
export declare function createIsographEnvironment(store: IsographStore, networkFunction: IsographNetworkFunction, missingFieldHandler?: MissingFieldHandler | null, logFunction?: LogFunction | null): IsographEnvironment;
|
|
79
79
|
export declare function createIsographStore(): IsographStore;
|
|
80
|
-
export declare function defaultMissingFieldHandler(_storeRecord: StoreRecord, _root:
|
|
80
|
+
export declare function defaultMissingFieldHandler(_storeRecord: StoreRecord, _root: Link, fieldName: string, arguments_: {
|
|
81
81
|
[index: string]: any;
|
|
82
82
|
} | null, variables: Variables | null): Link | undefined;
|
|
83
83
|
export declare function assertLink(link: DataTypeValue): Link | null | undefined;
|
package/dist/core/cache.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Factory, ParentCache } from '@isograph/react-disposable-state';
|
|
2
|
-
import { DataId, type IsographEnvironment } from './IsographEnvironment';
|
|
2
|
+
import { DataId, Link, type IsographEnvironment } from './IsographEnvironment';
|
|
3
3
|
import { IsographEntrypoint, NormalizationAst, NormalizationLinkedField, NormalizationScalarField, RefetchQueryNormalizationArtifactWrapper } from '../core/entrypoint';
|
|
4
4
|
import { ReaderLinkedField, ReaderScalarField, type ReaderAst } from './reader';
|
|
5
5
|
import { WithEncounteredRecords } from './read';
|
|
@@ -26,12 +26,12 @@ export type NetworkResponseObject = {
|
|
|
26
26
|
};
|
|
27
27
|
export declare function normalizeData(environment: IsographEnvironment, normalizationAst: NormalizationAst, networkResponse: NetworkResponseObject, variables: Variables, nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[]): Set<DataId>;
|
|
28
28
|
export declare function subscribeToAnyChange(environment: IsographEnvironment, callback: () => void): () => void;
|
|
29
|
-
export declare function subscribeToAnyChangesToRecord(environment: IsographEnvironment,
|
|
29
|
+
export declare function subscribeToAnyChangesToRecord(environment: IsographEnvironment, recordLink: Link, callback: () => void): () => void;
|
|
30
30
|
export declare function subscribe<TReadFromStore extends {
|
|
31
31
|
parameters: object;
|
|
32
32
|
data: object;
|
|
33
33
|
}>(environment: IsographEnvironment, encounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>, fragmentReference: FragmentReference<TReadFromStore, any>, callback: (newEncounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>) => void, readerAst: ReaderAst<TReadFromStore>): () => void;
|
|
34
|
-
export declare function onNextChangeToRecord(environment: IsographEnvironment,
|
|
34
|
+
export declare function onNextChangeToRecord(environment: IsographEnvironment, recordLink: Link): Promise<void>;
|
|
35
35
|
export declare function getParentRecordKey(astNode: NormalizationLinkedField | NormalizationScalarField | ReaderLinkedField | ReaderScalarField, variables: Variables): string;
|
|
36
36
|
export declare const FIRST_SPLIT_KEY = "____";
|
|
37
37
|
export declare const SECOND_SPLIT_KEY = "___";
|
package/dist/core/cache.js
CHANGED
|
@@ -64,7 +64,7 @@ function getOrCreateCacheForArtifact(environment, entrypoint, variables) {
|
|
|
64
64
|
readerArtifact: entrypoint.readerWithRefetchQueries.readerArtifact,
|
|
65
65
|
nestedRefetchQueries: entrypoint.readerWithRefetchQueries.nestedRefetchQueries,
|
|
66
66
|
}),
|
|
67
|
-
root: IsographEnvironment_1.ROOT_ID,
|
|
67
|
+
root: { __link: IsographEnvironment_1.ROOT_ID },
|
|
68
68
|
variables,
|
|
69
69
|
networkRequest: networkRequest,
|
|
70
70
|
},
|
|
@@ -82,7 +82,7 @@ function normalizeData(environment, normalizationAst, networkResponse, variables
|
|
|
82
82
|
networkResponse,
|
|
83
83
|
variables,
|
|
84
84
|
});
|
|
85
|
-
normalizeDataIntoRecord(environment, normalizationAst, networkResponse, environment.store.__ROOT, IsographEnvironment_1.ROOT_ID, variables, nestedRefetchQueries, encounteredIds);
|
|
85
|
+
normalizeDataIntoRecord(environment, normalizationAst, networkResponse, environment.store.__ROOT, { __link: IsographEnvironment_1.ROOT_ID }, variables, nestedRefetchQueries, encounteredIds);
|
|
86
86
|
(0, logging_1.logMessage)(environment, {
|
|
87
87
|
kind: 'AfterNormalization',
|
|
88
88
|
store: environment.store,
|
|
@@ -99,10 +99,10 @@ function subscribeToAnyChange(environment, callback) {
|
|
|
99
99
|
environment.subscriptions.add(subscription);
|
|
100
100
|
return () => environment.subscriptions.delete(subscription);
|
|
101
101
|
}
|
|
102
|
-
function subscribeToAnyChangesToRecord(environment,
|
|
102
|
+
function subscribeToAnyChangesToRecord(environment, recordLink, callback) {
|
|
103
103
|
const subscription = {
|
|
104
104
|
kind: 'AnyChangesToRecord',
|
|
105
|
-
|
|
105
|
+
recordLink,
|
|
106
106
|
callback,
|
|
107
107
|
};
|
|
108
108
|
environment.subscriptions.add(subscription);
|
|
@@ -120,9 +120,9 @@ function subscribe(environment, encounteredDataAndRecords, fragmentReference, ca
|
|
|
120
120
|
environment.subscriptions.add(fragmentSubscription);
|
|
121
121
|
return () => environment.subscriptions.delete(fragmentSubscription);
|
|
122
122
|
}
|
|
123
|
-
function onNextChangeToRecord(environment,
|
|
123
|
+
function onNextChangeToRecord(environment, recordLink) {
|
|
124
124
|
return new Promise((resolve) => {
|
|
125
|
-
const unsubscribe = subscribeToAnyChangesToRecord(environment,
|
|
125
|
+
const unsubscribe = subscribeToAnyChangesToRecord(environment, recordLink, () => {
|
|
126
126
|
unsubscribe();
|
|
127
127
|
resolve();
|
|
128
128
|
});
|
|
@@ -185,7 +185,7 @@ function callSubscriptions(environment, recordsEncounteredWhenNormalizing) {
|
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
case 'AnyChangesToRecord': {
|
|
188
|
-
if (recordsEncounteredWhenNormalizing.has(subscription.
|
|
188
|
+
if (recordsEncounteredWhenNormalizing.has(subscription.recordLink.__link)) {
|
|
189
189
|
subscription.callback();
|
|
190
190
|
}
|
|
191
191
|
return;
|
|
@@ -210,7 +210,7 @@ function hasOverlappingIds(set1, set2) {
|
|
|
210
210
|
/**
|
|
211
211
|
* Mutate targetParentRecord according to the normalizationAst and networkResponseParentRecord.
|
|
212
212
|
*/
|
|
213
|
-
function normalizeDataIntoRecord(environment, normalizationAst, networkResponseParentRecord, targetParentRecord,
|
|
213
|
+
function normalizeDataIntoRecord(environment, normalizationAst, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, nestedRefetchQueries, mutableEncounteredIds) {
|
|
214
214
|
let recordHasBeenUpdated = false;
|
|
215
215
|
for (const normalizationNode of normalizationAst) {
|
|
216
216
|
switch (normalizationNode.kind) {
|
|
@@ -221,13 +221,13 @@ function normalizeDataIntoRecord(environment, normalizationAst, networkResponseP
|
|
|
221
221
|
break;
|
|
222
222
|
}
|
|
223
223
|
case 'Linked': {
|
|
224
|
-
const linkedFieldResultedInChange = normalizeLinkedField(environment, normalizationNode, networkResponseParentRecord, targetParentRecord,
|
|
224
|
+
const linkedFieldResultedInChange = normalizeLinkedField(environment, normalizationNode, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, nestedRefetchQueries, mutableEncounteredIds);
|
|
225
225
|
recordHasBeenUpdated =
|
|
226
226
|
recordHasBeenUpdated || linkedFieldResultedInChange;
|
|
227
227
|
break;
|
|
228
228
|
}
|
|
229
229
|
case 'InlineFragment': {
|
|
230
|
-
const inlineFragmentResultedInChange = normalizeInlineFragment(environment, normalizationNode, networkResponseParentRecord, targetParentRecord,
|
|
230
|
+
const inlineFragmentResultedInChange = normalizeInlineFragment(environment, normalizationNode, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, nestedRefetchQueries, mutableEncounteredIds);
|
|
231
231
|
recordHasBeenUpdated =
|
|
232
232
|
recordHasBeenUpdated || inlineFragmentResultedInChange;
|
|
233
233
|
break;
|
|
@@ -241,7 +241,7 @@ function normalizeDataIntoRecord(environment, normalizationAst, networkResponseP
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
if (recordHasBeenUpdated) {
|
|
244
|
-
mutableEncounteredIds.add(
|
|
244
|
+
mutableEncounteredIds.add(targetParentRecordLink.__link);
|
|
245
245
|
}
|
|
246
246
|
return recordHasBeenUpdated;
|
|
247
247
|
}
|
|
@@ -262,7 +262,7 @@ function normalizeScalarField(astNode, networkResponseParentRecord, targetStoreR
|
|
|
262
262
|
/**
|
|
263
263
|
* Mutate targetParentRecord with a given linked field ast node.
|
|
264
264
|
*/
|
|
265
|
-
function normalizeLinkedField(environment, astNode, networkResponseParentRecord, targetParentRecord,
|
|
265
|
+
function normalizeLinkedField(environment, astNode, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, nestedRefetchQueries, mutableEncounteredIds) {
|
|
266
266
|
const networkResponseKey = getNetworkResponseKey(astNode);
|
|
267
267
|
const networkResponseData = networkResponseParentRecord[networkResponseKey];
|
|
268
268
|
const parentRecordKey = getParentRecordKey(astNode, variables);
|
|
@@ -279,14 +279,14 @@ function normalizeLinkedField(environment, astNode, networkResponseParentRecord,
|
|
|
279
279
|
const dataIds = [];
|
|
280
280
|
for (let i = 0; i < networkResponseData.length; i++) {
|
|
281
281
|
const networkResponseObject = networkResponseData[i];
|
|
282
|
-
const newStoreRecordId = normalizeNetworkResponseObject(environment, astNode, networkResponseObject,
|
|
282
|
+
const newStoreRecordId = normalizeNetworkResponseObject(environment, astNode, networkResponseObject, targetParentRecordLink, variables, i, nestedRefetchQueries, mutableEncounteredIds);
|
|
283
283
|
dataIds.push({ __link: newStoreRecordId });
|
|
284
284
|
}
|
|
285
285
|
targetParentRecord[parentRecordKey] = dataIds;
|
|
286
286
|
return !dataIdsAreTheSame(existingValue, dataIds);
|
|
287
287
|
}
|
|
288
288
|
else {
|
|
289
|
-
const newStoreRecordId = normalizeNetworkResponseObject(environment, astNode, networkResponseData,
|
|
289
|
+
const newStoreRecordId = normalizeNetworkResponseObject(environment, astNode, networkResponseData, targetParentRecordLink, variables, null, nestedRefetchQueries, mutableEncounteredIds);
|
|
290
290
|
targetParentRecord[parentRecordKey] = {
|
|
291
291
|
__link: newStoreRecordId,
|
|
292
292
|
};
|
|
@@ -297,10 +297,10 @@ function normalizeLinkedField(environment, astNode, networkResponseParentRecord,
|
|
|
297
297
|
/**
|
|
298
298
|
* Mutate targetParentRecord with a given linked field ast node.
|
|
299
299
|
*/
|
|
300
|
-
function normalizeInlineFragment(environment, astNode, networkResponseParentRecord, targetParentRecord,
|
|
300
|
+
function normalizeInlineFragment(environment, astNode, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, nestedRefetchQueries, mutableEncounteredIds) {
|
|
301
301
|
const typeToRefineTo = astNode.type;
|
|
302
302
|
if (networkResponseParentRecord[TYPENAME_FIELD_NAME] === typeToRefineTo) {
|
|
303
|
-
const hasBeenModified = normalizeDataIntoRecord(environment, astNode.selections, networkResponseParentRecord, targetParentRecord,
|
|
303
|
+
const hasBeenModified = normalizeDataIntoRecord(environment, astNode.selections, networkResponseParentRecord, targetParentRecord, targetParentRecordLink, variables, nestedRefetchQueries, mutableEncounteredIds);
|
|
304
304
|
return hasBeenModified;
|
|
305
305
|
}
|
|
306
306
|
return false;
|
|
@@ -324,12 +324,12 @@ function dataIdsAreTheSame(existingValue, newDataIds) {
|
|
|
324
324
|
return false;
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
function normalizeNetworkResponseObject(environment, astNode, networkResponseData,
|
|
327
|
+
function normalizeNetworkResponseObject(environment, astNode, networkResponseData, targetParentRecordLink, variables, index, nestedRefetchQueries, mutableEncounteredIds) {
|
|
328
328
|
var _a;
|
|
329
|
-
const newStoreRecordId = getDataIdOfNetworkResponse(
|
|
329
|
+
const newStoreRecordId = getDataIdOfNetworkResponse(targetParentRecordLink, networkResponseData, astNode, variables, index);
|
|
330
330
|
const newStoreRecord = (_a = environment.store[newStoreRecordId]) !== null && _a !== void 0 ? _a : {};
|
|
331
331
|
environment.store[newStoreRecordId] = newStoreRecord;
|
|
332
|
-
normalizeDataIntoRecord(environment, astNode.selections, networkResponseData, newStoreRecord, newStoreRecordId, variables, nestedRefetchQueries, mutableEncounteredIds);
|
|
332
|
+
normalizeDataIntoRecord(environment, astNode.selections, networkResponseData, newStoreRecord, { __link: newStoreRecordId }, variables, nestedRefetchQueries, mutableEncounteredIds);
|
|
333
333
|
return newStoreRecordId;
|
|
334
334
|
}
|
|
335
335
|
function isScalarOrEmptyArray(data) {
|
|
@@ -435,14 +435,14 @@ function getNetworkResponseKey(astNode) {
|
|
|
435
435
|
exports.FIRST_SPLIT_KEY = '____';
|
|
436
436
|
exports.SECOND_SPLIT_KEY = '___';
|
|
437
437
|
// Returns a key to look up an item in the store
|
|
438
|
-
function getDataIdOfNetworkResponse(
|
|
438
|
+
function getDataIdOfNetworkResponse(parentRecordLink, dataToNormalize, astNode, variables, index) {
|
|
439
439
|
// Check whether the dataToNormalize has an id field. If so, that is the key.
|
|
440
440
|
// If not, we construct an id from the parentRecordId and the field parameters.
|
|
441
441
|
const dataId = dataToNormalize.id;
|
|
442
442
|
if (dataId != null) {
|
|
443
443
|
return dataId;
|
|
444
444
|
}
|
|
445
|
-
let storeKey = `${
|
|
445
|
+
let storeKey = `${parentRecordLink.__link}.${astNode.fieldName}`;
|
|
446
446
|
if (index != null) {
|
|
447
447
|
storeKey += `.${index}`;
|
|
448
448
|
}
|
|
@@ -11,9 +11,8 @@ function getOrCreateCachedComponent(environment, componentName, fragmentReferenc
|
|
|
11
11
|
// stringified args. These three, together, uniquely identify a read at a given
|
|
12
12
|
// time.
|
|
13
13
|
const cachedComponentsById = environment.componentCache;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const componentsByName = cachedComponentsById[fragmentReference.root];
|
|
14
|
+
const recordLink = fragmentReference.root.__link;
|
|
15
|
+
const componentsByName = ((_a = cachedComponentsById[recordLink]) !== null && _a !== void 0 ? _a : (cachedComponentsById[recordLink] = {}));
|
|
17
16
|
componentsByName[componentName] = (_b = componentsByName[componentName]) !== null && _b !== void 0 ? _b : {};
|
|
18
17
|
const byArgs = componentsByName[componentName];
|
|
19
18
|
const stringifiedArgs = JSON.stringify((0, cache_1.stableCopy)(fragmentReference.variables));
|
|
@@ -25,7 +24,7 @@ function getOrCreateCachedComponent(environment, componentName, fragmentReferenc
|
|
|
25
24
|
(0, logging_1.logMessage)(environment, {
|
|
26
25
|
kind: 'ComponentRerendered',
|
|
27
26
|
componentName,
|
|
28
|
-
|
|
27
|
+
rootLink: fragmentReference.root,
|
|
29
28
|
});
|
|
30
29
|
const firstParameter = {
|
|
31
30
|
data,
|
package/dist/core/logging.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CleanupFn } from '@isograph/disposable-types';
|
|
2
|
-
import {
|
|
2
|
+
import { IsographEnvironment, IsographStore, StoreRecord, type Link } from './IsographEnvironment';
|
|
3
3
|
import { IsographEntrypoint, NormalizationAst, RefetchQueryNormalizationArtifact } from './entrypoint';
|
|
4
4
|
import { FragmentReference, Variables } from './FragmentReference';
|
|
5
5
|
import { NetworkResponseObject } from './cache';
|
|
@@ -28,7 +28,7 @@ export type LogMessage = {
|
|
|
28
28
|
} | {
|
|
29
29
|
kind: 'ComponentRerendered';
|
|
30
30
|
componentName: string;
|
|
31
|
-
|
|
31
|
+
rootLink: Link;
|
|
32
32
|
} | {
|
|
33
33
|
kind: 'MakeNetworkRequest';
|
|
34
34
|
artifact: RefetchQueryNormalizationArtifact | IsographEntrypoint<any, any>;
|
|
@@ -40,7 +40,7 @@ export type LogMessage = {
|
|
|
40
40
|
networkRequestId: string;
|
|
41
41
|
} | {
|
|
42
42
|
kind: 'MissingFieldHandlerCalled';
|
|
43
|
-
root:
|
|
43
|
+
root: Link;
|
|
44
44
|
storeRecord: StoreRecord;
|
|
45
45
|
fieldName: string;
|
|
46
46
|
arguments: Arguments | null;
|
package/dist/core/read.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FragmentReference, ExtractData } from './FragmentReference';
|
|
2
|
-
import { DataId, IsographEnvironment } from './IsographEnvironment';
|
|
2
|
+
import { DataId, IsographEnvironment, type Link } from './IsographEnvironment';
|
|
3
3
|
export type WithEncounteredRecords<T> = {
|
|
4
4
|
readonly encounteredRecords: Set<DataId>;
|
|
5
5
|
readonly item: ExtractData<T>;
|
|
@@ -16,7 +16,7 @@ export type ReadDataResult<TReadFromStore> = {
|
|
|
16
16
|
readonly kind: 'MissingData';
|
|
17
17
|
readonly reason: string;
|
|
18
18
|
readonly nestedReason?: ReadDataResult<unknown>;
|
|
19
|
-
readonly
|
|
19
|
+
readonly recordLink: Link;
|
|
20
20
|
};
|
|
21
21
|
export type NetworkRequestReaderOptions = {
|
|
22
22
|
suspendIfInFlight: boolean;
|
package/dist/core/read.js
CHANGED
|
@@ -31,11 +31,11 @@ function readButDoNotEvaluate(environment, fragmentReference, networkRequestOpti
|
|
|
31
31
|
networkRequestOptions.throwOnNetworkError) {
|
|
32
32
|
// TODO assert that the network request state is not Err
|
|
33
33
|
throw new Promise((resolve, reject) => {
|
|
34
|
-
(0, cache_1.onNextChangeToRecord)(environment, response.
|
|
34
|
+
(0, cache_1.onNextChangeToRecord)(environment, response.recordLink).then(resolve);
|
|
35
35
|
fragmentReference.networkRequest.promise.catch(reject);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
throw (0, cache_1.onNextChangeToRecord)(environment, response.
|
|
38
|
+
throw (0, cache_1.onNextChangeToRecord)(environment, response.recordLink);
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
41
41
|
return {
|
|
@@ -46,13 +46,13 @@ function readButDoNotEvaluate(environment, fragmentReference, networkRequestOpti
|
|
|
46
46
|
}
|
|
47
47
|
function readData(environment, ast, root, variables, nestedRefetchQueries, networkRequest, networkRequestOptions, mutableEncounteredRecords) {
|
|
48
48
|
var _a, _b, _c, _d, _e;
|
|
49
|
-
mutableEncounteredRecords.add(root);
|
|
50
|
-
let storeRecord = environment.store[root];
|
|
49
|
+
mutableEncounteredRecords.add(root.__link);
|
|
50
|
+
let storeRecord = environment.store[root.__link];
|
|
51
51
|
if (storeRecord === undefined) {
|
|
52
52
|
return {
|
|
53
53
|
kind: 'MissingData',
|
|
54
|
-
reason: 'No record for root ' + root,
|
|
55
|
-
|
|
54
|
+
reason: 'No record for root ' + root.__link,
|
|
55
|
+
recordLink: root,
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
if (storeRecord === null) {
|
|
@@ -73,8 +73,8 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
73
73
|
if (value === undefined) {
|
|
74
74
|
return {
|
|
75
75
|
kind: 'MissingData',
|
|
76
|
-
reason: 'No value for ' + storeRecordName + ' on root ' + root,
|
|
77
|
-
|
|
76
|
+
reason: 'No value for ' + storeRecordName + ' on root ' + root.__link,
|
|
77
|
+
recordLink: root,
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
target[(_a = field.alias) !== null && _a !== void 0 ? _a : field.fieldName] = value;
|
|
@@ -93,28 +93,28 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
93
93
|
reason: 'No link for ' +
|
|
94
94
|
storeRecordName +
|
|
95
95
|
' on root ' +
|
|
96
|
-
root +
|
|
96
|
+
root.__link +
|
|
97
97
|
'. Link is ' +
|
|
98
98
|
JSON.stringify(item),
|
|
99
|
-
|
|
99
|
+
recordLink: root,
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
else if (link === null) {
|
|
103
103
|
results.push(null);
|
|
104
104
|
continue;
|
|
105
105
|
}
|
|
106
|
-
const result = readData(environment, field.selections, link
|
|
106
|
+
const result = readData(environment, field.selections, link, variables, nestedRefetchQueries, networkRequest, networkRequestOptions, mutableEncounteredRecords);
|
|
107
107
|
if (result.kind === 'MissingData') {
|
|
108
108
|
return {
|
|
109
109
|
kind: 'MissingData',
|
|
110
110
|
reason: 'Missing data for ' +
|
|
111
111
|
storeRecordName +
|
|
112
112
|
' on root ' +
|
|
113
|
-
root +
|
|
113
|
+
root.__link +
|
|
114
114
|
'. Link is ' +
|
|
115
115
|
JSON.stringify(item),
|
|
116
116
|
nestedReason: result,
|
|
117
|
-
|
|
117
|
+
recordLink: result.recordLink,
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
results.push(result.data);
|
|
@@ -141,10 +141,10 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
141
141
|
reason: 'No link for ' +
|
|
142
142
|
storeRecordName +
|
|
143
143
|
' on root ' +
|
|
144
|
-
root +
|
|
144
|
+
root.__link +
|
|
145
145
|
'. Link is ' +
|
|
146
146
|
JSON.stringify(value),
|
|
147
|
-
|
|
147
|
+
recordLink: root,
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
@@ -155,14 +155,14 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
155
155
|
target[(_d = field.alias) !== null && _d !== void 0 ? _d : field.fieldName] = null;
|
|
156
156
|
break;
|
|
157
157
|
}
|
|
158
|
-
const targetId = link
|
|
158
|
+
const targetId = link;
|
|
159
159
|
const data = readData(environment, field.selections, targetId, variables, nestedRefetchQueries, networkRequest, networkRequestOptions, mutableEncounteredRecords);
|
|
160
160
|
if (data.kind === 'MissingData') {
|
|
161
161
|
return {
|
|
162
162
|
kind: 'MissingData',
|
|
163
|
-
reason: 'Missing data for ' + storeRecordName + ' on root ' + root,
|
|
163
|
+
reason: 'Missing data for ' + storeRecordName + ' on root ' + root.__link,
|
|
164
164
|
nestedReason: data,
|
|
165
|
-
|
|
165
|
+
recordLink: data.recordLink,
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
target[(_e = field.alias) !== null && _e !== void 0 ? _e : field.fieldName] = data.data;
|
|
@@ -180,9 +180,9 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
180
180
|
if (data.kind === 'MissingData') {
|
|
181
181
|
return {
|
|
182
182
|
kind: 'MissingData',
|
|
183
|
-
reason: 'Missing data for ' + field.alias + ' on root ' + root,
|
|
183
|
+
reason: 'Missing data for ' + field.alias + ' on root ' + root.__link,
|
|
184
184
|
nestedReason: data,
|
|
185
|
-
|
|
185
|
+
recordLink: data.recordLink,
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
else {
|
|
@@ -197,7 +197,7 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
197
197
|
// use the resolver reader AST to get the resolver parameters.
|
|
198
198
|
target[field.alias] = (args) => [
|
|
199
199
|
// Stable id
|
|
200
|
-
root + '__' + field.name,
|
|
200
|
+
root.__link + '__' + field.name,
|
|
201
201
|
// Fetcher
|
|
202
202
|
field.refetchReaderArtifact.resolver(environment, refetchQueryArtifact, data.data, filterVariables(Object.assign(Object.assign({}, args), variables), allowedVariables), root,
|
|
203
203
|
// TODO these params should be removed
|
|
@@ -215,9 +215,9 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
215
215
|
if (data.kind === 'MissingData') {
|
|
216
216
|
return {
|
|
217
217
|
kind: 'MissingData',
|
|
218
|
-
reason: 'Missing data for ' + field.alias + ' on root ' + root,
|
|
218
|
+
reason: 'Missing data for ' + field.alias + ' on root ' + root.__link,
|
|
219
219
|
nestedReason: data,
|
|
220
|
-
|
|
220
|
+
recordLink: data.recordLink,
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
223
|
else {
|
|
@@ -259,9 +259,9 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
259
259
|
if (refetchReaderParams.kind === 'MissingData') {
|
|
260
260
|
return {
|
|
261
261
|
kind: 'MissingData',
|
|
262
|
-
reason: 'Missing data for ' + field.alias + ' on root ' + root,
|
|
262
|
+
reason: 'Missing data for ' + field.alias + ' on root ' + root.__link,
|
|
263
263
|
nestedReason: refetchReaderParams,
|
|
264
|
-
|
|
264
|
+
recordLink: refetchReaderParams.recordLink,
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
267
|
else {
|
|
@@ -275,7 +275,7 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
275
275
|
writeQueryArgsToVariables(localVariables, field.queryArguments, variables);
|
|
276
276
|
return [
|
|
277
277
|
// Stable id
|
|
278
|
-
root +
|
|
278
|
+
root.__link +
|
|
279
279
|
'/' +
|
|
280
280
|
field.name +
|
|
281
281
|
'/' +
|
|
@@ -293,7 +293,7 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
293
293
|
.nestedRefetchQueries,
|
|
294
294
|
}),
|
|
295
295
|
// TODO localVariables is not guaranteed to have an id field
|
|
296
|
-
root: localVariables.id,
|
|
296
|
+
root: { __link: localVariables.id },
|
|
297
297
|
variables: localVariables,
|
|
298
298
|
networkRequest,
|
|
299
299
|
};
|
|
@@ -326,7 +326,7 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, netwo
|
|
|
326
326
|
kind: 'FragmentReference',
|
|
327
327
|
readerWithRefetchQueries: (0, PromiseWrapper_1.wrapPromise)(readerWithRefetchPromise),
|
|
328
328
|
// TODO localVariables is not guaranteed to have an id field
|
|
329
|
-
root: localVariables.id,
|
|
329
|
+
root: { __link: localVariables.id },
|
|
330
330
|
variables: localVariables,
|
|
331
331
|
networkRequest,
|
|
332
332
|
};
|
package/dist/core/reader.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Factory } from '@isograph/disposable-types';
|
|
2
2
|
import { FragmentReference, ExtractParameters, ExtractData } from './FragmentReference';
|
|
3
|
-
import { ComponentOrFieldName,
|
|
3
|
+
import { ComponentOrFieldName, IsographEnvironment, type Link } from './IsographEnvironment';
|
|
4
4
|
import { IsographEntrypoint, IsographEntrypointLoader, RefetchQueryNormalizationArtifact, RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
|
|
5
5
|
import { Arguments } from './util';
|
|
6
6
|
export type TopLevelReaderArtifact<TReadFromStore extends {
|
|
@@ -34,7 +34,7 @@ export type ResolverFirstParameter<TReadFromStore extends {
|
|
|
34
34
|
export type RefetchReaderArtifact = {
|
|
35
35
|
readonly kind: 'RefetchReaderArtifact';
|
|
36
36
|
readonly readerAst: ReaderAst<unknown>;
|
|
37
|
-
readonly resolver: (environment: IsographEnvironment, artifact: RefetchQueryNormalizationArtifact, variables: any, filteredVariables: any,
|
|
37
|
+
readonly resolver: (environment: IsographEnvironment, artifact: RefetchQueryNormalizationArtifact, variables: any, filteredVariables: any, rootLink: Link, readerArtifact: TopLevelReaderArtifact<any, any, any> | null, nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[]) => () => void;
|
|
38
38
|
};
|
|
39
39
|
export type ReaderAstNode = ReaderScalarField | ReaderLinkedField | ReaderNonLoadableResolverField | ReaderImperativelyLoadedField | ReaderLoadableField;
|
|
40
40
|
export type ReaderAst<TReadFromStore> = ReadonlyArray<ReaderAstNode>;
|
|
@@ -22,7 +22,7 @@ function useImperativeReference(entrypoint) {
|
|
|
22
22
|
readerArtifact: entrypoint.readerWithRefetchQueries.readerArtifact,
|
|
23
23
|
nestedRefetchQueries: entrypoint.readerWithRefetchQueries.nestedRefetchQueries,
|
|
24
24
|
}),
|
|
25
|
-
root: IsographEnvironment_1.ROOT_ID,
|
|
25
|
+
root: { __link: IsographEnvironment_1.ROOT_ID },
|
|
26
26
|
variables,
|
|
27
27
|
networkRequest,
|
|
28
28
|
},
|
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-00af1d07",
|
|
4
4
|
"description": "Use Isograph with React",
|
|
5
5
|
"homepage": "https://isograph.dev",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"tsc": "tsc"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@isograph/disposable-types": "0.0.0-main-
|
|
21
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
|
22
|
-
"@isograph/reference-counted-pointer": "0.0.0-main-
|
|
20
|
+
"@isograph/disposable-types": "0.0.0-main-00af1d07",
|
|
21
|
+
"@isograph/react-disposable-state": "0.0.0-main-00af1d07",
|
|
22
|
+
"@isograph/reference-counted-pointer": "0.0.0-main-00af1d07"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": "18.3.1"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Link } from './IsographEnvironment';
|
|
2
2
|
import { ReaderWithRefetchQueries } from '../core/entrypoint';
|
|
3
3
|
import { PromiseWrapper } from './PromiseWrapper';
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ export type FragmentReference<
|
|
|
27
27
|
readonly readerWithRefetchQueries: PromiseWrapper<
|
|
28
28
|
ReaderWithRefetchQueries<TReadFromStore, TClientFieldValue>
|
|
29
29
|
>;
|
|
30
|
-
readonly root:
|
|
30
|
+
readonly root: Link;
|
|
31
31
|
readonly variables: ExtractParameters<TReadFromStore>;
|
|
32
32
|
readonly networkRequest: PromiseWrapper<void, any>;
|
|
33
33
|
};
|
|
@@ -35,7 +35,7 @@ export type FragmentReference<
|
|
|
35
35
|
export function stableIdForFragmentReference(
|
|
36
36
|
fragmentReference: FragmentReference<any, any>,
|
|
37
37
|
): string {
|
|
38
|
-
return `${fragmentReference.root}/TODO_FRAGMENT_NAME/${serializeVariables(fragmentReference.variables ?? {})}`;
|
|
38
|
+
return `${fragmentReference.root.__link}/TODO_FRAGMENT_NAME/${serializeVariables(fragmentReference.variables ?? {})}`;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function serializeVariables(variables: Variables) {
|
|
@@ -31,7 +31,7 @@ export type FragmentSubscription<
|
|
|
31
31
|
type AnyChangesToRecordSubscription = {
|
|
32
32
|
readonly kind: 'AnyChangesToRecord';
|
|
33
33
|
readonly callback: () => void;
|
|
34
|
-
readonly
|
|
34
|
+
readonly recordLink: Link;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
type AnyRecordSubscription = {
|
|
@@ -69,7 +69,7 @@ export type IsographEnvironment = {
|
|
|
69
69
|
|
|
70
70
|
export type MissingFieldHandler = (
|
|
71
71
|
storeRecord: StoreRecord,
|
|
72
|
-
root:
|
|
72
|
+
root: Link,
|
|
73
73
|
fieldName: string,
|
|
74
74
|
arguments_: { [index: string]: any } | null,
|
|
75
75
|
variables: Variables | null,
|
|
@@ -145,7 +145,7 @@ export function createIsographStore(): IsographStore {
|
|
|
145
145
|
|
|
146
146
|
export function defaultMissingFieldHandler(
|
|
147
147
|
_storeRecord: StoreRecord,
|
|
148
|
-
_root:
|
|
148
|
+
_root: Link,
|
|
149
149
|
fieldName: string,
|
|
150
150
|
arguments_: { [index: string]: any } | null,
|
|
151
151
|
variables: Variables | null,
|
package/src/core/cache.ts
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
} from '@isograph/react-disposable-state';
|
|
6
6
|
import {
|
|
7
7
|
DataId,
|
|
8
|
+
Link,
|
|
8
9
|
ROOT_ID,
|
|
9
10
|
StoreRecord,
|
|
10
|
-
Link,
|
|
11
11
|
type IsographEnvironment,
|
|
12
12
|
DataTypeValue,
|
|
13
13
|
getLink,
|
|
@@ -106,7 +106,7 @@ export function getOrCreateCacheForArtifact<
|
|
|
106
106
|
nestedRefetchQueries:
|
|
107
107
|
entrypoint.readerWithRefetchQueries.nestedRefetchQueries,
|
|
108
108
|
}),
|
|
109
|
-
root: ROOT_ID,
|
|
109
|
+
root: { __link: ROOT_ID },
|
|
110
110
|
variables,
|
|
111
111
|
networkRequest: networkRequest,
|
|
112
112
|
},
|
|
@@ -152,7 +152,7 @@ export function normalizeData(
|
|
|
152
152
|
normalizationAst,
|
|
153
153
|
networkResponse,
|
|
154
154
|
environment.store.__ROOT,
|
|
155
|
-
ROOT_ID,
|
|
155
|
+
{ __link: ROOT_ID },
|
|
156
156
|
variables as any,
|
|
157
157
|
nestedRefetchQueries,
|
|
158
158
|
encounteredIds,
|
|
@@ -182,12 +182,12 @@ export function subscribeToAnyChange(
|
|
|
182
182
|
|
|
183
183
|
export function subscribeToAnyChangesToRecord(
|
|
184
184
|
environment: IsographEnvironment,
|
|
185
|
-
|
|
185
|
+
recordLink: Link,
|
|
186
186
|
callback: () => void,
|
|
187
187
|
): () => void {
|
|
188
188
|
const subscription = {
|
|
189
189
|
kind: 'AnyChangesToRecord',
|
|
190
|
-
|
|
190
|
+
recordLink,
|
|
191
191
|
callback,
|
|
192
192
|
} as const;
|
|
193
193
|
environment.subscriptions.add(subscription);
|
|
@@ -219,12 +219,12 @@ export function subscribe<
|
|
|
219
219
|
|
|
220
220
|
export function onNextChangeToRecord(
|
|
221
221
|
environment: IsographEnvironment,
|
|
222
|
-
|
|
222
|
+
recordLink: Link,
|
|
223
223
|
): Promise<void> {
|
|
224
224
|
return new Promise((resolve) => {
|
|
225
225
|
const unsubscribe = subscribeToAnyChangesToRecord(
|
|
226
226
|
environment,
|
|
227
|
-
|
|
227
|
+
recordLink,
|
|
228
228
|
() => {
|
|
229
229
|
unsubscribe();
|
|
230
230
|
resolve();
|
|
@@ -310,7 +310,11 @@ function callSubscriptions(
|
|
|
310
310
|
return;
|
|
311
311
|
}
|
|
312
312
|
case 'AnyChangesToRecord': {
|
|
313
|
-
if (
|
|
313
|
+
if (
|
|
314
|
+
recordsEncounteredWhenNormalizing.has(
|
|
315
|
+
subscription.recordLink.__link,
|
|
316
|
+
)
|
|
317
|
+
) {
|
|
314
318
|
subscription.callback();
|
|
315
319
|
}
|
|
316
320
|
return;
|
|
@@ -343,7 +347,7 @@ function normalizeDataIntoRecord(
|
|
|
343
347
|
normalizationAst: NormalizationAst,
|
|
344
348
|
networkResponseParentRecord: NetworkResponseObject,
|
|
345
349
|
targetParentRecord: StoreRecord,
|
|
346
|
-
|
|
350
|
+
targetParentRecordLink: Link,
|
|
347
351
|
variables: Variables,
|
|
348
352
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
|
349
353
|
mutableEncounteredIds: Set<DataId>,
|
|
@@ -368,7 +372,7 @@ function normalizeDataIntoRecord(
|
|
|
368
372
|
normalizationNode,
|
|
369
373
|
networkResponseParentRecord,
|
|
370
374
|
targetParentRecord,
|
|
371
|
-
|
|
375
|
+
targetParentRecordLink,
|
|
372
376
|
variables,
|
|
373
377
|
nestedRefetchQueries,
|
|
374
378
|
mutableEncounteredIds,
|
|
@@ -383,7 +387,7 @@ function normalizeDataIntoRecord(
|
|
|
383
387
|
normalizationNode,
|
|
384
388
|
networkResponseParentRecord,
|
|
385
389
|
targetParentRecord,
|
|
386
|
-
|
|
390
|
+
targetParentRecordLink,
|
|
387
391
|
variables,
|
|
388
392
|
nestedRefetchQueries,
|
|
389
393
|
mutableEncounteredIds,
|
|
@@ -401,7 +405,7 @@ function normalizeDataIntoRecord(
|
|
|
401
405
|
}
|
|
402
406
|
}
|
|
403
407
|
if (recordHasBeenUpdated) {
|
|
404
|
-
mutableEncounteredIds.add(
|
|
408
|
+
mutableEncounteredIds.add(targetParentRecordLink.__link);
|
|
405
409
|
}
|
|
406
410
|
return recordHasBeenUpdated;
|
|
407
411
|
}
|
|
@@ -437,7 +441,7 @@ function normalizeLinkedField(
|
|
|
437
441
|
astNode: NormalizationLinkedField,
|
|
438
442
|
networkResponseParentRecord: NetworkResponseObject,
|
|
439
443
|
targetParentRecord: StoreRecord,
|
|
440
|
-
|
|
444
|
+
targetParentRecordLink: Link,
|
|
441
445
|
variables: Variables,
|
|
442
446
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
|
443
447
|
mutableEncounteredIds: Set<DataId>,
|
|
@@ -467,7 +471,7 @@ function normalizeLinkedField(
|
|
|
467
471
|
environment,
|
|
468
472
|
astNode,
|
|
469
473
|
networkResponseObject,
|
|
470
|
-
|
|
474
|
+
targetParentRecordLink,
|
|
471
475
|
variables,
|
|
472
476
|
i,
|
|
473
477
|
nestedRefetchQueries,
|
|
@@ -483,7 +487,7 @@ function normalizeLinkedField(
|
|
|
483
487
|
environment,
|
|
484
488
|
astNode,
|
|
485
489
|
networkResponseData,
|
|
486
|
-
|
|
490
|
+
targetParentRecordLink,
|
|
487
491
|
variables,
|
|
488
492
|
null,
|
|
489
493
|
nestedRefetchQueries,
|
|
@@ -506,7 +510,7 @@ function normalizeInlineFragment(
|
|
|
506
510
|
astNode: NormalizationInlineFragment,
|
|
507
511
|
networkResponseParentRecord: NetworkResponseObject,
|
|
508
512
|
targetParentRecord: StoreRecord,
|
|
509
|
-
|
|
513
|
+
targetParentRecordLink: Link,
|
|
510
514
|
variables: Variables,
|
|
511
515
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
|
512
516
|
mutableEncounteredIds: Set<DataId>,
|
|
@@ -518,7 +522,7 @@ function normalizeInlineFragment(
|
|
|
518
522
|
astNode.selections,
|
|
519
523
|
networkResponseParentRecord,
|
|
520
524
|
targetParentRecord,
|
|
521
|
-
|
|
525
|
+
targetParentRecordLink,
|
|
522
526
|
variables,
|
|
523
527
|
nestedRefetchQueries,
|
|
524
528
|
mutableEncounteredIds,
|
|
@@ -554,14 +558,14 @@ function normalizeNetworkResponseObject(
|
|
|
554
558
|
environment: IsographEnvironment,
|
|
555
559
|
astNode: NormalizationLinkedField,
|
|
556
560
|
networkResponseData: NetworkResponseObject,
|
|
557
|
-
|
|
561
|
+
targetParentRecordLink: Link,
|
|
558
562
|
variables: Variables,
|
|
559
563
|
index: number | null,
|
|
560
564
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
|
561
565
|
mutableEncounteredIds: Set<DataId>,
|
|
562
566
|
): DataId /* The id of the modified or newly created item */ {
|
|
563
567
|
const newStoreRecordId = getDataIdOfNetworkResponse(
|
|
564
|
-
|
|
568
|
+
targetParentRecordLink,
|
|
565
569
|
networkResponseData,
|
|
566
570
|
astNode,
|
|
567
571
|
variables,
|
|
@@ -576,7 +580,7 @@ function normalizeNetworkResponseObject(
|
|
|
576
580
|
astNode.selections,
|
|
577
581
|
networkResponseData,
|
|
578
582
|
newStoreRecord,
|
|
579
|
-
newStoreRecordId,
|
|
583
|
+
{ __link: newStoreRecordId },
|
|
580
584
|
variables,
|
|
581
585
|
nestedRefetchQueries,
|
|
582
586
|
mutableEncounteredIds,
|
|
@@ -714,7 +718,7 @@ export const SECOND_SPLIT_KEY = '___';
|
|
|
714
718
|
|
|
715
719
|
// Returns a key to look up an item in the store
|
|
716
720
|
function getDataIdOfNetworkResponse(
|
|
717
|
-
|
|
721
|
+
parentRecordLink: Link,
|
|
718
722
|
dataToNormalize: NetworkResponseObject,
|
|
719
723
|
astNode: NormalizationLinkedField | NormalizationScalarField,
|
|
720
724
|
variables: Variables,
|
|
@@ -728,7 +732,7 @@ function getDataIdOfNetworkResponse(
|
|
|
728
732
|
return dataId;
|
|
729
733
|
}
|
|
730
734
|
|
|
731
|
-
let storeKey = `${
|
|
735
|
+
let storeKey = `${parentRecordLink.__link}.${astNode.fieldName}`;
|
|
732
736
|
if (index != null) {
|
|
733
737
|
storeKey += `.${index}`;
|
|
734
738
|
}
|
|
@@ -17,9 +17,9 @@ export function getOrCreateCachedComponent(
|
|
|
17
17
|
// time.
|
|
18
18
|
const cachedComponentsById = environment.componentCache;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const componentsByName = cachedComponentsById[
|
|
20
|
+
const recordLink = fragmentReference.root.__link;
|
|
21
|
+
|
|
22
|
+
const componentsByName = (cachedComponentsById[recordLink] ??= {});
|
|
23
23
|
|
|
24
24
|
componentsByName[componentName] = componentsByName[componentName] ?? {};
|
|
25
25
|
const byArgs = componentsByName[componentName];
|
|
@@ -44,7 +44,7 @@ export function getOrCreateCachedComponent(
|
|
|
44
44
|
logMessage(environment, {
|
|
45
45
|
kind: 'ComponentRerendered',
|
|
46
46
|
componentName,
|
|
47
|
-
|
|
47
|
+
rootLink: fragmentReference.root,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
const firstParameter = {
|
package/src/core/logging.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CleanupFn } from '@isograph/disposable-types';
|
|
2
2
|
import {
|
|
3
|
-
DataId,
|
|
4
3
|
IsographEnvironment,
|
|
5
4
|
IsographStore,
|
|
6
5
|
StoreRecord,
|
|
6
|
+
type Link,
|
|
7
7
|
} from './IsographEnvironment';
|
|
8
8
|
import {
|
|
9
9
|
IsographEntrypoint,
|
|
@@ -43,7 +43,7 @@ export type LogMessage =
|
|
|
43
43
|
| {
|
|
44
44
|
kind: 'ComponentRerendered';
|
|
45
45
|
componentName: string;
|
|
46
|
-
|
|
46
|
+
rootLink: Link;
|
|
47
47
|
}
|
|
48
48
|
| {
|
|
49
49
|
kind: 'MakeNetworkRequest';
|
|
@@ -61,7 +61,7 @@ export type LogMessage =
|
|
|
61
61
|
}
|
|
62
62
|
| {
|
|
63
63
|
kind: 'MissingFieldHandlerCalled';
|
|
64
|
-
root:
|
|
64
|
+
root: Link;
|
|
65
65
|
storeRecord: StoreRecord;
|
|
66
66
|
fieldName: string;
|
|
67
67
|
arguments: Arguments | null;
|
package/src/core/read.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
defaultMissingFieldHandler,
|
|
18
18
|
getOrLoadIsographArtifact,
|
|
19
19
|
IsographEnvironment,
|
|
20
|
+
type Link,
|
|
20
21
|
} from './IsographEnvironment';
|
|
21
22
|
import { makeNetworkRequest } from './makeNetworkRequest';
|
|
22
23
|
import {
|
|
@@ -80,11 +81,11 @@ export function readButDoNotEvaluate<
|
|
|
80
81
|
) {
|
|
81
82
|
// TODO assert that the network request state is not Err
|
|
82
83
|
throw new Promise((resolve, reject) => {
|
|
83
|
-
onNextChangeToRecord(environment, response.
|
|
84
|
+
onNextChangeToRecord(environment, response.recordLink).then(resolve);
|
|
84
85
|
fragmentReference.networkRequest.promise.catch(reject);
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
|
-
throw onNextChangeToRecord(environment, response.
|
|
88
|
+
throw onNextChangeToRecord(environment, response.recordLink);
|
|
88
89
|
} else {
|
|
89
90
|
return {
|
|
90
91
|
encounteredRecords: mutableEncounteredRecords,
|
|
@@ -103,26 +104,26 @@ export type ReadDataResult<TReadFromStore> =
|
|
|
103
104
|
readonly kind: 'MissingData';
|
|
104
105
|
readonly reason: string;
|
|
105
106
|
readonly nestedReason?: ReadDataResult<unknown>;
|
|
106
|
-
readonly
|
|
107
|
+
readonly recordLink: Link;
|
|
107
108
|
};
|
|
108
109
|
|
|
109
110
|
function readData<TReadFromStore>(
|
|
110
111
|
environment: IsographEnvironment,
|
|
111
112
|
ast: ReaderAst<TReadFromStore>,
|
|
112
|
-
root:
|
|
113
|
+
root: Link,
|
|
113
114
|
variables: ExtractParameters<TReadFromStore>,
|
|
114
115
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
|
115
116
|
networkRequest: PromiseWrapper<void, any>,
|
|
116
117
|
networkRequestOptions: NetworkRequestReaderOptions,
|
|
117
118
|
mutableEncounteredRecords: Set<DataId>,
|
|
118
119
|
): ReadDataResult<TReadFromStore> {
|
|
119
|
-
mutableEncounteredRecords.add(root);
|
|
120
|
-
let storeRecord = environment.store[root];
|
|
120
|
+
mutableEncounteredRecords.add(root.__link);
|
|
121
|
+
let storeRecord = environment.store[root.__link];
|
|
121
122
|
if (storeRecord === undefined) {
|
|
122
123
|
return {
|
|
123
124
|
kind: 'MissingData',
|
|
124
|
-
reason: 'No record for root ' + root,
|
|
125
|
-
|
|
125
|
+
reason: 'No record for root ' + root.__link,
|
|
126
|
+
recordLink: root,
|
|
126
127
|
};
|
|
127
128
|
}
|
|
128
129
|
|
|
@@ -146,8 +147,9 @@ function readData<TReadFromStore>(
|
|
|
146
147
|
if (value === undefined) {
|
|
147
148
|
return {
|
|
148
149
|
kind: 'MissingData',
|
|
149
|
-
reason:
|
|
150
|
-
|
|
150
|
+
reason:
|
|
151
|
+
'No value for ' + storeRecordName + ' on root ' + root.__link,
|
|
152
|
+
recordLink: root,
|
|
151
153
|
};
|
|
152
154
|
}
|
|
153
155
|
target[field.alias ?? field.fieldName] = value;
|
|
@@ -167,10 +169,10 @@ function readData<TReadFromStore>(
|
|
|
167
169
|
'No link for ' +
|
|
168
170
|
storeRecordName +
|
|
169
171
|
' on root ' +
|
|
170
|
-
root +
|
|
172
|
+
root.__link +
|
|
171
173
|
'. Link is ' +
|
|
172
174
|
JSON.stringify(item),
|
|
173
|
-
|
|
175
|
+
recordLink: root,
|
|
174
176
|
};
|
|
175
177
|
} else if (link === null) {
|
|
176
178
|
results.push(null);
|
|
@@ -179,7 +181,7 @@ function readData<TReadFromStore>(
|
|
|
179
181
|
const result = readData(
|
|
180
182
|
environment,
|
|
181
183
|
field.selections,
|
|
182
|
-
link
|
|
184
|
+
link,
|
|
183
185
|
variables,
|
|
184
186
|
nestedRefetchQueries,
|
|
185
187
|
networkRequest,
|
|
@@ -193,11 +195,11 @@ function readData<TReadFromStore>(
|
|
|
193
195
|
'Missing data for ' +
|
|
194
196
|
storeRecordName +
|
|
195
197
|
' on root ' +
|
|
196
|
-
root +
|
|
198
|
+
root.__link +
|
|
197
199
|
'. Link is ' +
|
|
198
200
|
JSON.stringify(item),
|
|
199
201
|
nestedReason: result,
|
|
200
|
-
|
|
202
|
+
recordLink: result.recordLink,
|
|
201
203
|
};
|
|
202
204
|
}
|
|
203
205
|
results.push(result.data);
|
|
@@ -234,10 +236,10 @@ function readData<TReadFromStore>(
|
|
|
234
236
|
'No link for ' +
|
|
235
237
|
storeRecordName +
|
|
236
238
|
' on root ' +
|
|
237
|
-
root +
|
|
239
|
+
root.__link +
|
|
238
240
|
'. Link is ' +
|
|
239
241
|
JSON.stringify(value),
|
|
240
|
-
|
|
242
|
+
recordLink: root,
|
|
241
243
|
};
|
|
242
244
|
} else {
|
|
243
245
|
link = altLink;
|
|
@@ -246,7 +248,7 @@ function readData<TReadFromStore>(
|
|
|
246
248
|
target[field.alias ?? field.fieldName] = null;
|
|
247
249
|
break;
|
|
248
250
|
}
|
|
249
|
-
const targetId = link
|
|
251
|
+
const targetId = link;
|
|
250
252
|
const data = readData(
|
|
251
253
|
environment,
|
|
252
254
|
field.selections,
|
|
@@ -260,9 +262,10 @@ function readData<TReadFromStore>(
|
|
|
260
262
|
if (data.kind === 'MissingData') {
|
|
261
263
|
return {
|
|
262
264
|
kind: 'MissingData',
|
|
263
|
-
reason:
|
|
265
|
+
reason:
|
|
266
|
+
'Missing data for ' + storeRecordName + ' on root ' + root.__link,
|
|
264
267
|
nestedReason: data,
|
|
265
|
-
|
|
268
|
+
recordLink: data.recordLink,
|
|
266
269
|
};
|
|
267
270
|
}
|
|
268
271
|
target[field.alias ?? field.fieldName] = data.data;
|
|
@@ -287,9 +290,10 @@ function readData<TReadFromStore>(
|
|
|
287
290
|
if (data.kind === 'MissingData') {
|
|
288
291
|
return {
|
|
289
292
|
kind: 'MissingData',
|
|
290
|
-
reason:
|
|
293
|
+
reason:
|
|
294
|
+
'Missing data for ' + field.alias + ' on root ' + root.__link,
|
|
291
295
|
nestedReason: data,
|
|
292
|
-
|
|
296
|
+
recordLink: data.recordLink,
|
|
293
297
|
};
|
|
294
298
|
} else {
|
|
295
299
|
const refetchQueryIndex = field.refetchQuery;
|
|
@@ -304,7 +308,7 @@ function readData<TReadFromStore>(
|
|
|
304
308
|
// use the resolver reader AST to get the resolver parameters.
|
|
305
309
|
target[field.alias] = (args: any) => [
|
|
306
310
|
// Stable id
|
|
307
|
-
root + '__' + field.name,
|
|
311
|
+
root.__link + '__' + field.name,
|
|
308
312
|
// Fetcher
|
|
309
313
|
field.refetchReaderArtifact.resolver(
|
|
310
314
|
environment,
|
|
@@ -341,9 +345,10 @@ function readData<TReadFromStore>(
|
|
|
341
345
|
if (data.kind === 'MissingData') {
|
|
342
346
|
return {
|
|
343
347
|
kind: 'MissingData',
|
|
344
|
-
reason:
|
|
348
|
+
reason:
|
|
349
|
+
'Missing data for ' + field.alias + ' on root ' + root.__link,
|
|
345
350
|
nestedReason: data,
|
|
346
|
-
|
|
351
|
+
recordLink: data.recordLink,
|
|
347
352
|
};
|
|
348
353
|
} else {
|
|
349
354
|
const firstParameter = {
|
|
@@ -397,9 +402,10 @@ function readData<TReadFromStore>(
|
|
|
397
402
|
if (refetchReaderParams.kind === 'MissingData') {
|
|
398
403
|
return {
|
|
399
404
|
kind: 'MissingData',
|
|
400
|
-
reason:
|
|
405
|
+
reason:
|
|
406
|
+
'Missing data for ' + field.alias + ' on root ' + root.__link,
|
|
401
407
|
nestedReason: refetchReaderParams,
|
|
402
|
-
|
|
408
|
+
recordLink: refetchReaderParams.recordLink,
|
|
403
409
|
};
|
|
404
410
|
} else {
|
|
405
411
|
target[field.alias] = (args: any) => {
|
|
@@ -420,7 +426,7 @@ function readData<TReadFromStore>(
|
|
|
420
426
|
|
|
421
427
|
return [
|
|
422
428
|
// Stable id
|
|
423
|
-
root +
|
|
429
|
+
root.__link +
|
|
424
430
|
'/' +
|
|
425
431
|
field.name +
|
|
426
432
|
'/' +
|
|
@@ -445,7 +451,7 @@ function readData<TReadFromStore>(
|
|
|
445
451
|
} as const),
|
|
446
452
|
|
|
447
453
|
// TODO localVariables is not guaranteed to have an id field
|
|
448
|
-
root: localVariables.id,
|
|
454
|
+
root: { __link: localVariables.id },
|
|
449
455
|
variables: localVariables,
|
|
450
456
|
networkRequest,
|
|
451
457
|
};
|
|
@@ -514,7 +520,7 @@ function readData<TReadFromStore>(
|
|
|
514
520
|
),
|
|
515
521
|
|
|
516
522
|
// TODO localVariables is not guaranteed to have an id field
|
|
517
|
-
root: localVariables.id,
|
|
523
|
+
root: { __link: localVariables.id },
|
|
518
524
|
variables: localVariables,
|
|
519
525
|
networkRequest,
|
|
520
526
|
};
|
package/src/core/reader.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
} from './FragmentReference';
|
|
7
7
|
import {
|
|
8
8
|
ComponentOrFieldName,
|
|
9
|
-
DataId,
|
|
10
9
|
IsographEnvironment,
|
|
10
|
+
type Link,
|
|
11
11
|
} from './IsographEnvironment';
|
|
12
12
|
import {
|
|
13
13
|
IsographEntrypoint,
|
|
@@ -66,7 +66,7 @@ export type RefetchReaderArtifact = {
|
|
|
66
66
|
variables: any,
|
|
67
67
|
// TODO type this better
|
|
68
68
|
filteredVariables: any,
|
|
69
|
-
|
|
69
|
+
rootLink: Link,
|
|
70
70
|
readerArtifact: TopLevelReaderArtifact<any, any, any> | null,
|
|
71
71
|
// TODO type this better
|
|
72
72
|
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|