relay-runtime 11.0.2 → 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/index.js +1 -1
- package/index.js.flow +16 -1
- package/lib/index.js +15 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +11 -1
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +59 -19
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +305 -55
- package/lib/multi-actor-environment/index.js +5 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +6 -1
- package/lib/mutations/commitMutation.js +4 -1
- package/lib/mutations/validateMutation.js +6 -1
- package/lib/network/RelayObservable.js +3 -1
- package/lib/network/RelayQueryResponseCache.js +19 -3
- package/lib/network/wrapNetworkWithLogObserver.js +78 -0
- package/lib/store/DataChecker.js +110 -40
- package/lib/store/OperationExecutor.js +478 -204
- package/lib/store/RelayConcreteVariables.js +21 -0
- package/lib/store/RelayModernEnvironment.js +41 -85
- package/lib/store/RelayModernFragmentSpecResolver.js +48 -22
- package/lib/store/RelayModernRecord.js +35 -1
- package/lib/store/RelayModernStore.js +48 -14
- package/lib/store/RelayOperationTracker.js +33 -23
- package/lib/store/RelayPublishQueue.js +23 -5
- package/lib/store/RelayReader.js +138 -44
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +28 -15
- package/lib/store/RelayResponseNormalizer.js +164 -91
- package/lib/store/RelayStoreReactFlightUtils.js +1 -7
- package/lib/store/RelayStoreSubscriptions.js +8 -5
- package/lib/store/RelayStoreUtils.js +7 -2
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +1 -1
- package/lib/store/createRelayContext.js +1 -1
- package/lib/subscription/requestSubscription.js +27 -29
- package/lib/util/RelayConcreteNode.js +1 -0
- package/lib/util/RelayFeatureFlags.js +3 -5
- package/lib/util/RelayReplaySubject.js +21 -6
- 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/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 +17 -1
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +72 -44
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +332 -80
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +61 -12
- package/multi-actor-environment/index.js.flow +3 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
- package/mutations/commitMutation.js.flow +2 -0
- package/mutations/validateMutation.js.flow +8 -0
- package/network/RelayObservable.js.flow +2 -0
- package/network/RelayQueryResponseCache.js.flow +31 -18
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +1 -1
- 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 +126 -35
- package/store/OperationExecutor.js.flow +528 -265
- package/store/RelayConcreteVariables.js.flow +26 -1
- package/store/RelayModernEnvironment.js.flow +41 -94
- 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 +50 -12
- package/store/RelayOperationTracker.js.flow +56 -34
- package/store/RelayPublishQueue.js.flow +31 -8
- package/store/RelayReader.js.flow +148 -42
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +29 -12
- package/store/RelayResponseNormalizer.js.flow +164 -48
- package/store/RelayStoreReactFlightUtils.js.flow +1 -7
- package/store/RelayStoreSubscriptions.js.flow +10 -3
- package/store/RelayStoreTypes.js.flow +128 -12
- package/store/RelayStoreUtils.js.flow +17 -3
- package/store/ResolverCache.js.flow +247 -0
- package/store/ResolverFragments.js.flow +6 -3
- package/store/createRelayContext.js.flow +1 -1
- package/subscription/requestSubscription.js.flow +41 -29
- package/util/NormalizationNode.js.flow +10 -3
- package/util/ReaderNode.js.flow +15 -1
- package/util/RelayConcreteNode.js.flow +1 -0
- package/util/RelayFeatureFlags.js.flow +8 -10
- package/util/RelayReplaySubject.js.flow +7 -6
- 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 +1 -0
- 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
package/lib/store/DataChecker.js
CHANGED
|
@@ -40,14 +40,18 @@ var invariant = require('invariant');
|
|
|
40
40
|
var _require = require('./ClientID'),
|
|
41
41
|
isClientID = _require.isClientID;
|
|
42
42
|
|
|
43
|
-
var _require2 = require('./
|
|
44
|
-
|
|
45
|
-
UNKNOWN = _require2.UNKNOWN;
|
|
43
|
+
var _require2 = require('./RelayConcreteVariables'),
|
|
44
|
+
getLocalVariables = _require2.getLocalVariables;
|
|
46
45
|
|
|
47
|
-
var _require3 = require('./
|
|
48
|
-
|
|
46
|
+
var _require3 = require('./RelayRecordState'),
|
|
47
|
+
EXISTENT = _require3.EXISTENT,
|
|
48
|
+
UNKNOWN = _require3.UNKNOWN;
|
|
49
49
|
|
|
50
|
-
var
|
|
50
|
+
var _require4 = require('./TypeID'),
|
|
51
|
+
generateTypeID = _require4.generateTypeID;
|
|
52
|
+
|
|
53
|
+
var ACTOR_CHANGE = RelayConcreteNode.ACTOR_CHANGE,
|
|
54
|
+
CONDITION = RelayConcreteNode.CONDITION,
|
|
51
55
|
CLIENT_COMPONENT = RelayConcreteNode.CLIENT_COMPONENT,
|
|
52
56
|
CLIENT_EXTENSION = RelayConcreteNode.CLIENT_EXTENSION,
|
|
53
57
|
DEFER = RelayConcreteNode.DEFER,
|
|
@@ -76,11 +80,11 @@ var ROOT_ID = RelayStoreUtils.ROOT_ID,
|
|
|
76
80
|
* If all records are present, returns `true`, otherwise `false`.
|
|
77
81
|
*/
|
|
78
82
|
|
|
79
|
-
function check(
|
|
83
|
+
function check(getSourceForActor, getTargetForActor, defaultActorIdentifier, selector, handlers, operationLoader, getDataID, shouldProcessClientComponents) {
|
|
80
84
|
var dataID = selector.dataID,
|
|
81
85
|
node = selector.node,
|
|
82
86
|
variables = selector.variables;
|
|
83
|
-
var checker = new DataChecker(
|
|
87
|
+
var checker = new DataChecker(getSourceForActor, getTargetForActor, defaultActorIdentifier, variables, handlers, operationLoader, getDataID, shouldProcessClientComponents);
|
|
84
88
|
return checker.check(node, dataID);
|
|
85
89
|
}
|
|
86
90
|
/**
|
|
@@ -89,21 +93,45 @@ function check(source, target, selector, handlers, operationLoader, getDataID, s
|
|
|
89
93
|
|
|
90
94
|
|
|
91
95
|
var DataChecker = /*#__PURE__*/function () {
|
|
92
|
-
function DataChecker(
|
|
93
|
-
|
|
96
|
+
function DataChecker(getSourceForActor, getTargetForActor, defaultActorIdentifier, variables, handlers, operationLoader, getDataID, shouldProcessClientComponents) {
|
|
97
|
+
this._getSourceForActor = getSourceForActor;
|
|
98
|
+
this._getTargetForActor = getTargetForActor;
|
|
99
|
+
this._getDataID = getDataID;
|
|
100
|
+
this._source = getSourceForActor(defaultActorIdentifier);
|
|
101
|
+
this._mutatorRecordSourceProxyCache = new Map();
|
|
102
|
+
|
|
103
|
+
var _this$_getMutatorAndR = this._getMutatorAndRecordProxyForActor(defaultActorIdentifier),
|
|
104
|
+
mutator = _this$_getMutatorAndR[0],
|
|
105
|
+
recordSourceProxy = _this$_getMutatorAndR[1];
|
|
106
|
+
|
|
94
107
|
this._mostRecentlyInvalidatedAt = null;
|
|
95
108
|
this._handlers = handlers;
|
|
96
109
|
this._mutator = mutator;
|
|
97
110
|
this._operationLoader = operationLoader !== null && operationLoader !== void 0 ? operationLoader : null;
|
|
98
|
-
this._recordSourceProxy =
|
|
111
|
+
this._recordSourceProxy = recordSourceProxy;
|
|
99
112
|
this._recordWasMissing = false;
|
|
100
|
-
this._source = source;
|
|
101
113
|
this._variables = variables;
|
|
102
114
|
this._shouldProcessClientComponents = shouldProcessClientComponents;
|
|
103
115
|
}
|
|
104
116
|
|
|
105
117
|
var _proto = DataChecker.prototype;
|
|
106
118
|
|
|
119
|
+
_proto._getMutatorAndRecordProxyForActor = function _getMutatorAndRecordProxyForActor(actorIdentifier) {
|
|
120
|
+
var tuple = this._mutatorRecordSourceProxyCache.get(actorIdentifier);
|
|
121
|
+
|
|
122
|
+
if (tuple == null) {
|
|
123
|
+
var target = this._getTargetForActor(actorIdentifier);
|
|
124
|
+
|
|
125
|
+
var mutator = new RelayRecordSourceMutator(this._getSourceForActor(actorIdentifier), target);
|
|
126
|
+
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID);
|
|
127
|
+
tuple = [mutator, recordSourceProxy];
|
|
128
|
+
|
|
129
|
+
this._mutatorRecordSourceProxyCache.set(actorIdentifier, tuple);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return tuple;
|
|
133
|
+
};
|
|
134
|
+
|
|
107
135
|
_proto.check = function check(node, dataID) {
|
|
108
136
|
this._traverse(node, dataID);
|
|
109
137
|
|
|
@@ -128,6 +156,8 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
128
156
|
|
|
129
157
|
_proto._getDataForHandlers = function _getDataForHandlers(field, dataID) {
|
|
130
158
|
return {
|
|
159
|
+
/* $FlowFixMe[class-object-subtyping] added when improving typing for
|
|
160
|
+
* this parameters */
|
|
131
161
|
args: field.args ? getArgumentValues(field.args, this._variables) : {},
|
|
132
162
|
// Getting a snapshot of the record state is potentially expensive since
|
|
133
163
|
// we will need to merge the sink and source records. Since we do not create
|
|
@@ -279,8 +309,13 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
279
309
|
|
|
280
310
|
break;
|
|
281
311
|
|
|
312
|
+
case ACTOR_CHANGE:
|
|
313
|
+
_this2._checkActorChange(selection.linkedField, dataID);
|
|
314
|
+
|
|
315
|
+
break;
|
|
316
|
+
|
|
282
317
|
case CONDITION:
|
|
283
|
-
var conditionValue = _this2._getVariableValue(selection.condition);
|
|
318
|
+
var conditionValue = Boolean(_this2._getVariableValue(selection.condition));
|
|
284
319
|
|
|
285
320
|
if (conditionValue === selection.passingValue) {
|
|
286
321
|
_this2._traverseSelections(selection.selections, dataID);
|
|
@@ -290,16 +325,16 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
290
325
|
|
|
291
326
|
case INLINE_FRAGMENT:
|
|
292
327
|
{
|
|
293
|
-
var
|
|
328
|
+
var _abstractKey = selection.abstractKey;
|
|
294
329
|
|
|
295
|
-
if (
|
|
330
|
+
if (_abstractKey == null) {
|
|
296
331
|
// concrete type refinement: only check data if the type exactly matches
|
|
297
332
|
var typeName = _this2._mutator.getType(dataID);
|
|
298
333
|
|
|
299
334
|
if (typeName === selection.type) {
|
|
300
335
|
_this2._traverseSelections(selection.selections, dataID);
|
|
301
336
|
}
|
|
302
|
-
} else
|
|
337
|
+
} else {
|
|
303
338
|
// Abstract refinement: check data depending on whether the type
|
|
304
339
|
// conforms to the interface/union or not:
|
|
305
340
|
// - Type known to _not_ implement the interface: don't check the selections.
|
|
@@ -307,25 +342,22 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
307
342
|
// - Unknown whether the type implements the interface: don't check the selections
|
|
308
343
|
// and treat the data as missing; we do this because the Relay Compiler
|
|
309
344
|
// guarantees that the type discriminator will always be fetched.
|
|
310
|
-
var
|
|
345
|
+
var _recordType = _this2._mutator.getType(dataID);
|
|
311
346
|
|
|
312
|
-
!(
|
|
313
|
-
var typeID = generateTypeID(recordType);
|
|
347
|
+
!(_recordType != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DataChecker: Expected record `%s` to have a known type', dataID) : invariant(false) : void 0;
|
|
314
348
|
|
|
315
|
-
var
|
|
349
|
+
var _typeID = generateTypeID(_recordType);
|
|
316
350
|
|
|
317
|
-
|
|
351
|
+
var _implementsInterface = _this2._mutator.getValue(_typeID, _abstractKey);
|
|
352
|
+
|
|
353
|
+
if (_implementsInterface === true) {
|
|
318
354
|
_this2._traverseSelections(selection.selections, dataID);
|
|
319
|
-
} else if (
|
|
355
|
+
} else if (_implementsInterface == null) {
|
|
320
356
|
// unsure if the type implements the interface: data is
|
|
321
357
|
// missing so don't bother reading the fragment
|
|
322
358
|
_this2._handleMissing();
|
|
323
359
|
} // else false: known to not implement the interface
|
|
324
360
|
|
|
325
|
-
} else {
|
|
326
|
-
// legacy behavior for abstract refinements: always check even
|
|
327
|
-
// if the type doesn't conform
|
|
328
|
-
_this2._traverseSelections(selection.selections, dataID);
|
|
329
361
|
}
|
|
330
362
|
|
|
331
363
|
break;
|
|
@@ -365,11 +397,14 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
365
397
|
_this2._traverseSelections(selection.selections, dataID);
|
|
366
398
|
|
|
367
399
|
break;
|
|
368
|
-
// $FlowFixMe[incompatible-type]
|
|
369
400
|
|
|
370
401
|
case FRAGMENT_SPREAD:
|
|
402
|
+
var prevVariables = _this2._variables;
|
|
403
|
+
_this2._variables = getLocalVariables(_this2._variables, selection.fragment.argumentDefinitions, selection.args);
|
|
404
|
+
|
|
371
405
|
_this2._traverseSelections(selection.fragment.selections, dataID);
|
|
372
406
|
|
|
407
|
+
_this2._variables = prevVariables;
|
|
373
408
|
break;
|
|
374
409
|
|
|
375
410
|
case CLIENT_EXTENSION:
|
|
@@ -381,24 +416,21 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
381
416
|
break;
|
|
382
417
|
|
|
383
418
|
case TYPE_DISCRIMINATOR:
|
|
384
|
-
|
|
385
|
-
var _abstractKey = selection.abstractKey;
|
|
419
|
+
var abstractKey = selection.abstractKey;
|
|
386
420
|
|
|
387
|
-
|
|
421
|
+
var recordType = _this2._mutator.getType(dataID);
|
|
388
422
|
|
|
389
|
-
|
|
423
|
+
!(recordType != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DataChecker: Expected record `%s` to have a known type', dataID) : invariant(false) : void 0;
|
|
424
|
+
var typeID = generateTypeID(recordType);
|
|
390
425
|
|
|
391
|
-
|
|
426
|
+
var implementsInterface = _this2._mutator.getValue(typeID, abstractKey);
|
|
392
427
|
|
|
393
|
-
|
|
428
|
+
if (implementsInterface == null) {
|
|
429
|
+
// unsure if the type implements the interface: data is
|
|
430
|
+
// missing
|
|
431
|
+
_this2._handleMissing();
|
|
432
|
+
} // else: if it does or doesn't implement, we don't need to check or skip anything else
|
|
394
433
|
|
|
395
|
-
if (_implementsInterface == null) {
|
|
396
|
-
// unsure if the type implements the interface: data is
|
|
397
|
-
// missing
|
|
398
|
-
_this2._handleMissing();
|
|
399
|
-
} // else: if it does or doesn't implement, we don't need to check or skip anything else
|
|
400
|
-
|
|
401
|
-
}
|
|
402
434
|
|
|
403
435
|
break;
|
|
404
436
|
|
|
@@ -446,8 +478,12 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
446
478
|
|
|
447
479
|
if (normalizationRootNode != null) {
|
|
448
480
|
var operation = getOperation(normalizationRootNode);
|
|
481
|
+
var prevVariables = this._variables;
|
|
482
|
+
this._variables = getLocalVariables(this._variables, operation.argumentDefinitions, moduleImport.args);
|
|
449
483
|
|
|
450
484
|
this._traverse(operation, dataID);
|
|
485
|
+
|
|
486
|
+
this._variables = prevVariables;
|
|
451
487
|
} else {
|
|
452
488
|
// If the fragment is not available, we assume that the data cannot have been
|
|
453
489
|
// processed yet and must therefore be missing.
|
|
@@ -515,6 +551,40 @@ var DataChecker = /*#__PURE__*/function () {
|
|
|
515
551
|
}
|
|
516
552
|
};
|
|
517
553
|
|
|
554
|
+
_proto._checkActorChange = function _checkActorChange(field, dataID) {
|
|
555
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
556
|
+
|
|
557
|
+
var record = this._source.get(dataID);
|
|
558
|
+
|
|
559
|
+
var tuple = record != null ? RelayModernRecord.getActorLinkedRecordID(record, storageKey) : record;
|
|
560
|
+
|
|
561
|
+
if (tuple == null) {
|
|
562
|
+
if (tuple === undefined) {
|
|
563
|
+
this._handleMissing();
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
var _actorIdentifier = tuple[0],
|
|
567
|
+
linkedID = tuple[1];
|
|
568
|
+
var prevSource = this._source;
|
|
569
|
+
var prevMutator = this._mutator;
|
|
570
|
+
var prevRecordSourceProxy = this._recordSourceProxy;
|
|
571
|
+
|
|
572
|
+
var _this$_getMutatorAndR2 = this._getMutatorAndRecordProxyForActor(_actorIdentifier),
|
|
573
|
+
mutator = _this$_getMutatorAndR2[0],
|
|
574
|
+
recordSourceProxy = _this$_getMutatorAndR2[1];
|
|
575
|
+
|
|
576
|
+
this._source = this._getSourceForActor(_actorIdentifier);
|
|
577
|
+
this._mutator = mutator;
|
|
578
|
+
this._recordSourceProxy = recordSourceProxy;
|
|
579
|
+
|
|
580
|
+
this._traverse(field, linkedID);
|
|
581
|
+
|
|
582
|
+
this._source = prevSource;
|
|
583
|
+
this._mutator = prevMutator;
|
|
584
|
+
this._recordSourceProxy = prevRecordSourceProxy;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
|
|
518
588
|
_proto._checkFlightField = function _checkFlightField(field, dataID) {
|
|
519
589
|
var storageKey = getStorageKey(field, this._variables);
|
|
520
590
|
|