relay-runtime 11.0.0-rc.0 → 12.0.0
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/handlers/connection/ConnectionHandler.js.flow +7 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +20 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +12 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +15 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +148 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +406 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -0
- package/lib/mutations/RelayRecordProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceMutator.js +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +7 -2
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +5 -2
- package/lib/mutations/validateMutation.js +39 -17
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayObservable.js +3 -1
- package/lib/network/RelayQueryResponseCache.js +20 -3
- package/lib/network/wrapNetworkWithLogObserver.js +78 -0
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +1 -1
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/store/DataChecker.js +132 -50
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +524 -187
- package/lib/store/RelayConcreteVariables.js +29 -4
- package/lib/store/RelayModernEnvironment.js +137 -220
- package/lib/store/RelayModernFragmentSpecResolver.js +49 -23
- package/lib/store/RelayModernRecord.js +36 -2
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +53 -22
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +30 -8
- package/lib/store/RelayReader.js +177 -29
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +53 -28
- package/lib/store/RelayResponseNormalizer.js +247 -108
- package/lib/store/RelayStoreReactFlightUtils.js +7 -11
- package/lib/store/RelayStoreSubscriptions.js +8 -5
- package/lib/store/RelayStoreUtils.js +10 -4
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createRelayContext.js +2 -2
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +32 -6
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayFeatureFlags.js +5 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +67 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +43 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +217 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +485 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +245 -0
- package/multi-actor-environment/index.js.flow +27 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
- package/mutations/commitMutation.js.flow +3 -1
- package/mutations/validateMutation.js.flow +42 -16
- package/network/RelayNetworkTypes.js.flow +17 -8
- package/network/RelayObservable.js.flow +2 -0
- package/network/RelayQueryResponseCache.js.flow +31 -17
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +3 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +5 -1
- package/store/DataChecker.js.flow +148 -44
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +578 -237
- package/store/RelayConcreteVariables.js.flow +31 -1
- package/store/RelayModernEnvironment.js.flow +132 -220
- package/store/RelayModernFragmentSpecResolver.js.flow +40 -14
- package/store/RelayModernOperationDescriptor.js.flow +9 -3
- package/store/RelayModernRecord.js.flow +49 -0
- package/store/RelayModernStore.js.flow +57 -17
- package/store/RelayOperationTracker.js.flow +56 -34
- package/store/RelayPublishQueue.js.flow +37 -11
- package/store/RelayReader.js.flow +186 -27
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +51 -21
- package/store/RelayResponseNormalizer.js.flow +251 -67
- package/store/RelayStoreReactFlightUtils.js.flow +6 -9
- package/store/RelayStoreSubscriptions.js.flow +10 -3
- package/store/RelayStoreTypes.js.flow +144 -21
- package/store/RelayStoreUtils.js.flow +19 -4
- package/store/ResolverCache.js.flow +247 -0
- package/store/ResolverFragments.js.flow +128 -0
- package/store/createRelayContext.js.flow +1 -1
- package/store/defaultGetDataID.js.flow +3 -1
- package/subscription/requestSubscription.js.flow +43 -8
- package/util/NormalizationNode.js.flow +16 -3
- package/util/ReaderNode.js.flow +29 -2
- package/util/RelayConcreteNode.js.flow +3 -0
- package/util/RelayFeatureFlags.js.flow +10 -6
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +7 -6
- package/util/RelayRuntimeTypes.js.flow +4 -2
- package/util/deepFreeze.js.flow +2 -1
- package/util/getPaginationMetadata.js.flow +74 -0
- package/util/getPaginationVariables.js.flow +112 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +80 -0
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var ErrorUtils
|
|
13
|
+
var _global$ErrorUtils$ap, _global, _global$ErrorUtils;
|
|
14
14
|
|
|
15
15
|
var RelayReader = require('./RelayReader');
|
|
16
16
|
|
|
@@ -22,10 +22,13 @@ var RelayRecordSourceProxy = require('../mutations/RelayRecordSourceProxy');
|
|
|
22
22
|
|
|
23
23
|
var RelayRecordSourceSelectorProxy = require('../mutations/RelayRecordSourceSelectorProxy');
|
|
24
24
|
|
|
25
|
-
var invariant = require(
|
|
25
|
+
var invariant = require('invariant');
|
|
26
26
|
|
|
27
27
|
var warning = require("fbjs/lib/warning");
|
|
28
28
|
|
|
29
|
+
var applyWithGuard = (_global$ErrorUtils$ap = (_global = global) === null || _global === void 0 ? void 0 : (_global$ErrorUtils = _global.ErrorUtils) === null || _global$ErrorUtils === void 0 ? void 0 : _global$ErrorUtils.applyWithGuard) !== null && _global$ErrorUtils$ap !== void 0 ? _global$ErrorUtils$ap : function (callback, context, args, onError, name) {
|
|
30
|
+
return callback.apply(context, args);
|
|
31
|
+
};
|
|
29
32
|
/**
|
|
30
33
|
* Coordinates the concurrent modification of a `Store` due to optimistic and
|
|
31
34
|
* non-revertable client updates and server payloads:
|
|
@@ -37,6 +40,7 @@ var warning = require("fbjs/lib/warning");
|
|
|
37
40
|
* - Executes handlers for "handle" fields.
|
|
38
41
|
* - Reverts and reapplies pending optimistic updates.
|
|
39
42
|
*/
|
|
43
|
+
|
|
40
44
|
var RelayPublishQueue = /*#__PURE__*/function () {
|
|
41
45
|
// True if the next `run()` should apply the backup and rerun all optimistic
|
|
42
46
|
// updates performing a rebase.
|
|
@@ -145,11 +149,25 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
145
149
|
;
|
|
146
150
|
|
|
147
151
|
_proto.run = function run(sourceOperation) {
|
|
152
|
+
var runWillClearGcHold = this._appliedOptimisticUpdates === 0 && !!this._gcHold;
|
|
153
|
+
var runIsANoop = // this._pendingBackupRebase is true if an applied optimistic
|
|
154
|
+
// update has potentially been reverted or if this._pendingData is not empty.
|
|
155
|
+
!this._pendingBackupRebase && this._pendingOptimisticUpdates.size === 0 && !runWillClearGcHold;
|
|
156
|
+
|
|
148
157
|
if (process.env.NODE_ENV !== "production") {
|
|
158
|
+
process.env.NODE_ENV !== "production" ? warning(!runIsANoop, 'RelayPublishQueue.run was called, but the call would have been a noop.') : void 0;
|
|
149
159
|
process.env.NODE_ENV !== "production" ? warning(this._isRunning !== true, 'A store update was detected within another store update. Please ' + "make sure new store updates aren't being executed within an " + 'updater function for a different update.') : void 0;
|
|
150
160
|
this._isRunning = true;
|
|
151
161
|
}
|
|
152
162
|
|
|
163
|
+
if (runIsANoop) {
|
|
164
|
+
if (process.env.NODE_ENV !== "production") {
|
|
165
|
+
this._isRunning = false;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
|
|
153
171
|
if (this._pendingBackupRebase) {
|
|
154
172
|
if (this._hasStoreSnapshot) {
|
|
155
173
|
this._store.restore();
|
|
@@ -259,7 +277,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
259
277
|
var sink = RelayRecordSource.create();
|
|
260
278
|
var mutator = new RelayRecordSourceMutator(_this2._store.getSource(), sink);
|
|
261
279
|
var recordSourceProxy = new RelayRecordSourceProxy(mutator, _this2._getDataID);
|
|
262
|
-
|
|
280
|
+
applyWithGuard(updater, null, [recordSourceProxy], null, 'RelayPublishQueue:commitData');
|
|
263
281
|
invalidatedStore = invalidatedStore || recordSourceProxy.isStoreMarkedForInvalidation();
|
|
264
282
|
var idsMarkedForInvalidation = recordSourceProxy.getIDsMarkedForInvalidation();
|
|
265
283
|
|
|
@@ -288,23 +306,27 @@ var RelayPublishQueue = /*#__PURE__*/function () {
|
|
|
288
306
|
var processUpdate = function processUpdate(optimisticUpdate) {
|
|
289
307
|
if (optimisticUpdate.storeUpdater) {
|
|
290
308
|
var storeUpdater = optimisticUpdate.storeUpdater;
|
|
291
|
-
|
|
309
|
+
applyWithGuard(storeUpdater, null, [recordSourceProxy], null, 'RelayPublishQueue:applyUpdates');
|
|
292
310
|
} else {
|
|
293
311
|
var operation = optimisticUpdate.operation,
|
|
294
312
|
payload = optimisticUpdate.payload,
|
|
295
313
|
updater = optimisticUpdate.updater;
|
|
296
314
|
var source = payload.source,
|
|
297
315
|
fieldPayloads = payload.fieldPayloads;
|
|
298
|
-
var recordSourceSelectorProxy = new RelayRecordSourceSelectorProxy(mutator, recordSourceProxy, operation.fragment);
|
|
299
|
-
var selectorData;
|
|
300
316
|
|
|
301
317
|
if (source) {
|
|
302
318
|
recordSourceProxy.publishSource(source, fieldPayloads);
|
|
303
|
-
selectorData = lookupSelector(source, operation.fragment);
|
|
304
319
|
}
|
|
305
320
|
|
|
306
321
|
if (updater) {
|
|
307
|
-
|
|
322
|
+
var selectorData;
|
|
323
|
+
|
|
324
|
+
if (source) {
|
|
325
|
+
selectorData = lookupSelector(source, operation.fragment);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
var recordSourceSelectorProxy = new RelayRecordSourceSelectorProxy(mutator, recordSourceProxy, operation.fragment);
|
|
329
|
+
applyWithGuard(updater, null, [recordSourceSelectorProxy, selectorData], null, 'RelayPublishQueue:applyUpdates');
|
|
308
330
|
}
|
|
309
331
|
}
|
|
310
332
|
}; // rerun all updaters in case we are running a rebase
|
package/lib/store/RelayReader.js
CHANGED
|
@@ -10,13 +10,20 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
|
+
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
|
|
17
|
+
var ClientID = require('./ClientID');
|
|
18
|
+
|
|
13
19
|
var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
14
20
|
|
|
15
21
|
var RelayModernRecord = require('./RelayModernRecord');
|
|
16
22
|
|
|
17
|
-
var invariant = require(
|
|
23
|
+
var invariant = require('invariant');
|
|
18
24
|
|
|
19
25
|
var _require = require('../util/RelayConcreteNode'),
|
|
26
|
+
ACTOR_CHANGE = _require.ACTOR_CHANGE,
|
|
20
27
|
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
21
28
|
CONDITION = _require.CONDITION,
|
|
22
29
|
DEFER = _require.DEFER,
|
|
@@ -27,6 +34,7 @@ var _require = require('../util/RelayConcreteNode'),
|
|
|
27
34
|
LINKED_FIELD = _require.LINKED_FIELD,
|
|
28
35
|
MODULE_IMPORT = _require.MODULE_IMPORT,
|
|
29
36
|
REQUIRED_FIELD = _require.REQUIRED_FIELD,
|
|
37
|
+
RELAY_RESOLVER = _require.RELAY_RESOLVER,
|
|
30
38
|
SCALAR_FIELD = _require.SCALAR_FIELD,
|
|
31
39
|
STREAM = _require.STREAM;
|
|
32
40
|
|
|
@@ -45,11 +53,17 @@ var _require3 = require('./RelayStoreUtils'),
|
|
|
45
53
|
getStorageKey = _require3.getStorageKey,
|
|
46
54
|
getModuleComponentKey = _require3.getModuleComponentKey;
|
|
47
55
|
|
|
48
|
-
var _require4 = require('./
|
|
49
|
-
|
|
56
|
+
var _require4 = require('./ResolverCache'),
|
|
57
|
+
NoopResolverCache = _require4.NoopResolverCache;
|
|
58
|
+
|
|
59
|
+
var _require5 = require('./ResolverFragments'),
|
|
60
|
+
withResolverContext = _require5.withResolverContext;
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
var _require6 = require('./TypeID'),
|
|
63
|
+
generateTypeID = _require6.generateTypeID;
|
|
64
|
+
|
|
65
|
+
function read(recordSource, selector, resolverCache) {
|
|
66
|
+
var reader = new RelayReader(recordSource, selector, resolverCache !== null && resolverCache !== void 0 ? resolverCache : new NoopResolverCache());
|
|
53
67
|
return reader.read();
|
|
54
68
|
}
|
|
55
69
|
/**
|
|
@@ -58,7 +72,7 @@ function read(recordSource, selector) {
|
|
|
58
72
|
|
|
59
73
|
|
|
60
74
|
var RelayReader = /*#__PURE__*/function () {
|
|
61
|
-
function RelayReader(recordSource, selector) {
|
|
75
|
+
function RelayReader(recordSource, selector, resolverCache) {
|
|
62
76
|
this._isMissingData = false;
|
|
63
77
|
this._isWithinUnmatchedTypeRefinement = false;
|
|
64
78
|
this._missingRequiredFields = null;
|
|
@@ -67,6 +81,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
67
81
|
this._seenRecords = new Set();
|
|
68
82
|
this._selector = selector;
|
|
69
83
|
this._variables = selector.variables;
|
|
84
|
+
this._resolverCache = resolverCache;
|
|
70
85
|
}
|
|
71
86
|
|
|
72
87
|
var _proto = RelayReader.prototype;
|
|
@@ -95,7 +110,15 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
95
110
|
if (isDataExpectedToBePresent && abstractKey == null && record != null) {
|
|
96
111
|
var recordType = RelayModernRecord.getType(record);
|
|
97
112
|
|
|
98
|
-
if (recordType !== node.type &&
|
|
113
|
+
if (recordType !== node.type && // The root record type is a special `__Root` type and may not match the
|
|
114
|
+
// type on the ast, so ignore type mismatches at the root.
|
|
115
|
+
// We currently detect whether we're at the root by checking against ROOT_ID,
|
|
116
|
+
// but this does not work for mutations/subscriptions which generate unique
|
|
117
|
+
// root ids. This is acceptable in practice as we don't read data for mutations/
|
|
118
|
+
// subscriptions in a situation where we would use isMissingData to decide whether
|
|
119
|
+
// to suspend or not.
|
|
120
|
+
// TODO T96653810: Correctly detect reading from root of mutation/subscription
|
|
121
|
+
dataID !== ROOT_ID) {
|
|
99
122
|
isDataExpectedToBePresent = false;
|
|
100
123
|
}
|
|
101
124
|
} // If this is an abstract fragment (and the precise refinement GK is enabled)
|
|
@@ -104,7 +127,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
104
127
|
// the interface, that itself constitutes "expected" data being missing.
|
|
105
128
|
|
|
106
129
|
|
|
107
|
-
if (isDataExpectedToBePresent && abstractKey != null && record != null
|
|
130
|
+
if (isDataExpectedToBePresent && abstractKey != null && record != null) {
|
|
108
131
|
var _recordType = RelayModernRecord.getType(record);
|
|
109
132
|
|
|
110
133
|
var typeID = generateTypeID(_recordType);
|
|
@@ -156,7 +179,8 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
156
179
|
};
|
|
157
180
|
|
|
158
181
|
_proto._getVariableValue = function _getVariableValue(name) {
|
|
159
|
-
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Undefined variable `%s`.', name) : invariant(false) : void 0;
|
|
182
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Undefined variable `%s`.', name) : invariant(false) : void 0; // $FlowFixMe[cannot-write]
|
|
183
|
+
|
|
160
184
|
return this._variables[name];
|
|
161
185
|
};
|
|
162
186
|
|
|
@@ -245,7 +269,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
245
269
|
break;
|
|
246
270
|
|
|
247
271
|
case CONDITION:
|
|
248
|
-
var conditionValue = this._getVariableValue(selection.condition);
|
|
272
|
+
var conditionValue = Boolean(this._getVariableValue(selection.condition));
|
|
249
273
|
|
|
250
274
|
if (conditionValue === selection.passingValue) {
|
|
251
275
|
var hasExpectedData = this._traverseSelections(selection.selections, record, data);
|
|
@@ -272,7 +296,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
272
296
|
return false;
|
|
273
297
|
}
|
|
274
298
|
}
|
|
275
|
-
} else
|
|
299
|
+
} else {
|
|
276
300
|
// Similar to the logic in read(): data is only expected to be present
|
|
277
301
|
// if the record is known to conform to the interface. If we don't know
|
|
278
302
|
// whether the type conforms or not, that constitutes missing data.
|
|
@@ -300,15 +324,22 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
300
324
|
// Don't know if the type implements the interface or not
|
|
301
325
|
this._isMissingData = true;
|
|
302
326
|
}
|
|
303
|
-
} else {
|
|
304
|
-
// legacy behavior for abstract refinements: always read even
|
|
305
|
-
// if the type doesn't conform and don't reset isMissingData
|
|
306
|
-
this._traverseSelections(selection.selections, record, data);
|
|
307
327
|
}
|
|
308
328
|
|
|
309
329
|
break;
|
|
310
330
|
}
|
|
311
331
|
|
|
332
|
+
case RELAY_RESOLVER:
|
|
333
|
+
{
|
|
334
|
+
if (!RelayFeatureFlags.ENABLE_RELAY_RESOLVERS) {
|
|
335
|
+
throw new Error('Relay Resolver fields are not yet supported.');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
this._readResolverField(selection, record, data);
|
|
339
|
+
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
|
|
312
343
|
case FRAGMENT_SPREAD:
|
|
313
344
|
this._createFragmentPointer(selection, record, data);
|
|
314
345
|
|
|
@@ -320,7 +351,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
320
351
|
break;
|
|
321
352
|
|
|
322
353
|
case INLINE_DATA_FRAGMENT_SPREAD:
|
|
323
|
-
this.
|
|
354
|
+
this._createInlineDataOrResolverFragmentPointer(selection, record, data);
|
|
324
355
|
|
|
325
356
|
break;
|
|
326
357
|
|
|
@@ -360,6 +391,11 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
360
391
|
|
|
361
392
|
break;
|
|
362
393
|
|
|
394
|
+
case ACTOR_CHANGE:
|
|
395
|
+
this._readActorChange(selection, record, data);
|
|
396
|
+
|
|
397
|
+
break;
|
|
398
|
+
|
|
363
399
|
default:
|
|
364
400
|
selection;
|
|
365
401
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
|
|
@@ -381,12 +417,95 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
381
417
|
return this._readLink(selection.field, record, data);
|
|
382
418
|
}
|
|
383
419
|
|
|
420
|
+
case RELAY_RESOLVER:
|
|
421
|
+
if (!RelayFeatureFlags.ENABLE_RELAY_RESOLVERS) {
|
|
422
|
+
throw new Error('Relay Resolver fields are not yet supported.');
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
this._readResolverField(selection.field, record, data);
|
|
426
|
+
|
|
427
|
+
break;
|
|
428
|
+
|
|
384
429
|
default:
|
|
385
430
|
selection.field.kind;
|
|
386
431
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
|
|
387
432
|
}
|
|
388
433
|
};
|
|
389
434
|
|
|
435
|
+
_proto._readResolverField = function _readResolverField(field, record, data) {
|
|
436
|
+
var _this = this;
|
|
437
|
+
|
|
438
|
+
var resolverModule = field.resolverModule,
|
|
439
|
+
fragment = field.fragment;
|
|
440
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
441
|
+
var resolverID = ClientID.generateClientID(RelayModernRecord.getDataID(record), storageKey); // Found when reading the resolver fragment, which can happen either when
|
|
442
|
+
// evaluating the resolver and it calls readFragment, or when checking if the
|
|
443
|
+
// inputs have changed since a previous evaluation:
|
|
444
|
+
|
|
445
|
+
var fragmentValue;
|
|
446
|
+
var fragmentReaderSelector;
|
|
447
|
+
var fragmentSeenRecordIDs = new Set();
|
|
448
|
+
|
|
449
|
+
var getDataForResolverFragment = function getDataForResolverFragment(singularReaderSelector) {
|
|
450
|
+
if (fragmentValue != null) {
|
|
451
|
+
// It was already read when checking for input staleness; no need to read it again.
|
|
452
|
+
// Note that the variables like fragmentSeenRecordIDs in the outer closure will have
|
|
453
|
+
// already been set and will still be used in this case.
|
|
454
|
+
return fragmentValue;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
fragmentReaderSelector = singularReaderSelector;
|
|
458
|
+
var existingSeenRecords = _this._seenRecords;
|
|
459
|
+
|
|
460
|
+
try {
|
|
461
|
+
var _resolverFragmentData;
|
|
462
|
+
|
|
463
|
+
_this._seenRecords = fragmentSeenRecordIDs;
|
|
464
|
+
var resolverFragmentData = {};
|
|
465
|
+
|
|
466
|
+
_this._createInlineDataOrResolverFragmentPointer(singularReaderSelector.node, record, resolverFragmentData);
|
|
467
|
+
|
|
468
|
+
fragmentValue = (_resolverFragmentData = resolverFragmentData[FRAGMENTS_KEY]) === null || _resolverFragmentData === void 0 ? void 0 : _resolverFragmentData[fragment.name];
|
|
469
|
+
!(typeof fragmentValue === 'object' && fragmentValue !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Expected reader data to contain a __fragments property with a property for the fragment named ".concat(fragment.name, ", but it is missing.")) : invariant(false) : void 0;
|
|
470
|
+
return fragmentValue;
|
|
471
|
+
} finally {
|
|
472
|
+
_this._seenRecords = existingSeenRecords;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
var resolverContext = {
|
|
477
|
+
getDataForResolverFragment: getDataForResolverFragment
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
var _this$_resolverCache$ = this._resolverCache.readFromCacheOrEvaluate(record, field, this._variables, function () {
|
|
481
|
+
var key = {
|
|
482
|
+
__id: RelayModernRecord.getDataID(record),
|
|
483
|
+
__fragmentOwner: _this._owner,
|
|
484
|
+
__fragments: (0, _defineProperty2["default"])({}, fragment.name, {})
|
|
485
|
+
};
|
|
486
|
+
return withResolverContext(resolverContext, function () {
|
|
487
|
+
// $FlowFixMe[prop-missing] - resolver module's type signature is a lie
|
|
488
|
+
var resolverResult = resolverModule(key);
|
|
489
|
+
return {
|
|
490
|
+
resolverResult: resolverResult,
|
|
491
|
+
fragmentValue: fragmentValue,
|
|
492
|
+
resolverID: resolverID,
|
|
493
|
+
seenRecordIDs: fragmentSeenRecordIDs,
|
|
494
|
+
readerSelector: fragmentReaderSelector
|
|
495
|
+
};
|
|
496
|
+
});
|
|
497
|
+
}, getDataForResolverFragment),
|
|
498
|
+
result = _this$_resolverCache$[0],
|
|
499
|
+
seenRecord = _this$_resolverCache$[1];
|
|
500
|
+
|
|
501
|
+
if (seenRecord != null) {
|
|
502
|
+
this._seenRecords.add(seenRecord);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
data[storageKey] = result;
|
|
506
|
+
return result;
|
|
507
|
+
};
|
|
508
|
+
|
|
390
509
|
_proto._readFlightField = function _readFlightField(field, record, data) {
|
|
391
510
|
var _field$alias;
|
|
392
511
|
|
|
@@ -464,13 +583,45 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
464
583
|
return value;
|
|
465
584
|
};
|
|
466
585
|
|
|
467
|
-
_proto.
|
|
468
|
-
var _this = this;
|
|
469
|
-
|
|
586
|
+
_proto._readActorChange = function _readActorChange(field, record, data) {
|
|
470
587
|
var _field$alias4;
|
|
471
588
|
|
|
472
589
|
var applicationName = (_field$alias4 = field.alias) !== null && _field$alias4 !== void 0 ? _field$alias4 : field.name;
|
|
473
590
|
var storageKey = getStorageKey(field, this._variables);
|
|
591
|
+
var externalRef = RelayModernRecord.getActorLinkedRecordID(record, storageKey);
|
|
592
|
+
|
|
593
|
+
if (externalRef == null) {
|
|
594
|
+
data[applicationName] = externalRef;
|
|
595
|
+
|
|
596
|
+
if (externalRef === undefined) {
|
|
597
|
+
this._isMissingData = true;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
return data[applicationName];
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
var actorIdentifier = externalRef[0],
|
|
604
|
+
dataID = externalRef[1];
|
|
605
|
+
var fragmentRef = {};
|
|
606
|
+
|
|
607
|
+
this._createFragmentPointer(field.fragmentSpread, {
|
|
608
|
+
__id: dataID
|
|
609
|
+
}, fragmentRef);
|
|
610
|
+
|
|
611
|
+
data[applicationName] = {
|
|
612
|
+
__fragmentRef: fragmentRef,
|
|
613
|
+
__viewer: actorIdentifier
|
|
614
|
+
};
|
|
615
|
+
return data[applicationName];
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
_proto._readPluralLink = function _readPluralLink(field, record, data) {
|
|
619
|
+
var _this2 = this;
|
|
620
|
+
|
|
621
|
+
var _field$alias5;
|
|
622
|
+
|
|
623
|
+
var applicationName = (_field$alias5 = field.alias) !== null && _field$alias5 !== void 0 ? _field$alias5 : field.name;
|
|
624
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
474
625
|
var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
|
|
475
626
|
|
|
476
627
|
if (linkedIDs == null) {
|
|
@@ -489,7 +640,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
489
640
|
linkedIDs.forEach(function (linkedID, nextIndex) {
|
|
490
641
|
if (linkedID == null) {
|
|
491
642
|
if (linkedID === undefined) {
|
|
492
|
-
|
|
643
|
+
_this2._isMissingData = true;
|
|
493
644
|
} // $FlowFixMe[cannot-write]
|
|
494
645
|
|
|
495
646
|
|
|
@@ -501,7 +652,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
501
652
|
!(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevItem) : invariant(false) : void 0; // $FlowFixMe[cannot-write]
|
|
502
653
|
// $FlowFixMe[incompatible-variance]
|
|
503
654
|
|
|
504
|
-
linkedArray[nextIndex] =
|
|
655
|
+
linkedArray[nextIndex] = _this2._traverse(field, linkedID, prevItem);
|
|
505
656
|
});
|
|
506
657
|
data[applicationName] = linkedArray;
|
|
507
658
|
return linkedArray;
|
|
@@ -534,7 +685,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
534
685
|
this._createFragmentPointer({
|
|
535
686
|
kind: 'FragmentSpread',
|
|
536
687
|
name: moduleImport.fragmentName,
|
|
537
|
-
args:
|
|
688
|
+
args: moduleImport.args
|
|
538
689
|
}, record, data);
|
|
539
690
|
|
|
540
691
|
data[FRAGMENT_PROP_NAME_KEY] = moduleImport.fragmentPropName;
|
|
@@ -557,13 +708,10 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
557
708
|
|
|
558
709
|
fragmentPointers[fragmentSpread.name] = fragmentSpread.args ? getArgumentValues(fragmentSpread.args, this._variables) : {};
|
|
559
710
|
data[FRAGMENT_OWNER_KEY] = this._owner;
|
|
560
|
-
|
|
561
|
-
if (RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
|
|
562
|
-
data[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] = this._isWithinUnmatchedTypeRefinement;
|
|
563
|
-
}
|
|
711
|
+
data[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] = this._isWithinUnmatchedTypeRefinement;
|
|
564
712
|
};
|
|
565
713
|
|
|
566
|
-
_proto.
|
|
714
|
+
_proto._createInlineDataOrResolverFragmentPointer = function _createInlineDataOrResolverFragmentPointer(fragmentSpreadOrFragment, record, data) {
|
|
567
715
|
var fragmentPointers = data[FRAGMENTS_KEY];
|
|
568
716
|
|
|
569
717
|
if (fragmentPointers == null) {
|
|
@@ -578,10 +726,10 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
578
726
|
|
|
579
727
|
var inlineData = {};
|
|
580
728
|
|
|
581
|
-
this._traverseSelections(
|
|
729
|
+
this._traverseSelections(fragmentSpreadOrFragment.selections, record, inlineData); // $FlowFixMe[cannot-write] - writing into read-only field
|
|
582
730
|
|
|
583
731
|
|
|
584
|
-
fragmentPointers[
|
|
732
|
+
fragmentPointers[fragmentSpreadOrFragment.name] = inlineData;
|
|
585
733
|
};
|
|
586
734
|
|
|
587
735
|
return RelayReader;
|
|
@@ -10,15 +10,99 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
|
+
|
|
15
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
16
|
+
|
|
17
|
+
var RelayRecordState = require('./RelayRecordState');
|
|
18
|
+
|
|
19
|
+
var EXISTENT = RelayRecordState.EXISTENT,
|
|
20
|
+
NONEXISTENT = RelayRecordState.NONEXISTENT,
|
|
21
|
+
UNKNOWN = RelayRecordState.UNKNOWN;
|
|
22
|
+
/**
|
|
23
|
+
* An implementation of the `MutableRecordSource` interface (defined in
|
|
24
|
+
* `RelayStoreTypes`) that holds all records in memory (JS Map).
|
|
25
|
+
*/
|
|
14
26
|
|
|
15
27
|
var RelayRecordSource = /*#__PURE__*/function () {
|
|
16
28
|
function RelayRecordSource(records) {
|
|
17
|
-
|
|
29
|
+
var _this = this;
|
|
30
|
+
|
|
31
|
+
this._records = new Map();
|
|
32
|
+
|
|
33
|
+
if (records != null) {
|
|
34
|
+
Object.keys(records).forEach(function (key) {
|
|
35
|
+
_this._records.set(key, records[key]);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
18
38
|
}
|
|
19
39
|
|
|
20
40
|
RelayRecordSource.create = function create(records) {
|
|
21
|
-
return new
|
|
41
|
+
return new RelayRecordSource(records);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var _proto = RelayRecordSource.prototype;
|
|
45
|
+
|
|
46
|
+
_proto.clear = function clear() {
|
|
47
|
+
this._records = new Map();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
_proto["delete"] = function _delete(dataID) {
|
|
51
|
+
this._records.set(dataID, null);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
_proto.get = function get(dataID) {
|
|
55
|
+
return this._records.get(dataID);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
_proto.getRecordIDs = function getRecordIDs() {
|
|
59
|
+
return Array.from(this._records.keys());
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
_proto.getStatus = function getStatus(dataID) {
|
|
63
|
+
if (!this._records.has(dataID)) {
|
|
64
|
+
return UNKNOWN;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return this._records.get(dataID) == null ? NONEXISTENT : EXISTENT;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
_proto.has = function has(dataID) {
|
|
71
|
+
return this._records.has(dataID);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
_proto.remove = function remove(dataID) {
|
|
75
|
+
this._records["delete"](dataID);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
_proto.set = function set(dataID, record) {
|
|
79
|
+
this._records.set(dataID, record);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
_proto.size = function size() {
|
|
83
|
+
return this._records.size;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
_proto.toJSON = function toJSON() {
|
|
87
|
+
var obj = {};
|
|
88
|
+
|
|
89
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(this._records),
|
|
90
|
+
_step;
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
94
|
+
var _step$value = _step.value,
|
|
95
|
+
key = _step$value[0],
|
|
96
|
+
value = _step$value[1];
|
|
97
|
+
obj[key] = value;
|
|
98
|
+
}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
_iterator.e(err);
|
|
101
|
+
} finally {
|
|
102
|
+
_iterator.f();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return obj;
|
|
22
106
|
};
|
|
23
107
|
|
|
24
108
|
return RelayRecordSource;
|