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.
Files changed (100) hide show
  1. package/index.js +1 -1
  2. package/index.js.flow +16 -1
  3. package/lib/index.js +15 -0
  4. package/lib/multi-actor-environment/ActorIdentifier.js +11 -1
  5. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +59 -19
  6. package/lib/multi-actor-environment/ActorUtils.js +27 -0
  7. package/lib/multi-actor-environment/MultiActorEnvironment.js +305 -55
  8. package/lib/multi-actor-environment/index.js +5 -1
  9. package/lib/mutations/RelayRecordSourceSelectorProxy.js +6 -1
  10. package/lib/mutations/commitMutation.js +4 -1
  11. package/lib/mutations/validateMutation.js +6 -1
  12. package/lib/network/RelayObservable.js +3 -1
  13. package/lib/network/RelayQueryResponseCache.js +19 -3
  14. package/lib/network/wrapNetworkWithLogObserver.js +78 -0
  15. package/lib/store/DataChecker.js +110 -40
  16. package/lib/store/OperationExecutor.js +478 -204
  17. package/lib/store/RelayConcreteVariables.js +21 -0
  18. package/lib/store/RelayModernEnvironment.js +41 -85
  19. package/lib/store/RelayModernFragmentSpecResolver.js +48 -22
  20. package/lib/store/RelayModernRecord.js +35 -1
  21. package/lib/store/RelayModernStore.js +48 -14
  22. package/lib/store/RelayOperationTracker.js +33 -23
  23. package/lib/store/RelayPublishQueue.js +23 -5
  24. package/lib/store/RelayReader.js +138 -44
  25. package/lib/store/RelayRecordSource.js +87 -3
  26. package/lib/store/RelayReferenceMarker.js +28 -15
  27. package/lib/store/RelayResponseNormalizer.js +164 -91
  28. package/lib/store/RelayStoreReactFlightUtils.js +1 -7
  29. package/lib/store/RelayStoreSubscriptions.js +8 -5
  30. package/lib/store/RelayStoreUtils.js +7 -2
  31. package/lib/store/ResolverCache.js +213 -0
  32. package/lib/store/ResolverFragments.js +1 -1
  33. package/lib/store/createRelayContext.js +1 -1
  34. package/lib/subscription/requestSubscription.js +27 -29
  35. package/lib/util/RelayConcreteNode.js +1 -0
  36. package/lib/util/RelayFeatureFlags.js +3 -5
  37. package/lib/util/RelayReplaySubject.js +21 -6
  38. package/lib/util/getPaginationMetadata.js +41 -0
  39. package/lib/util/getPaginationVariables.js +67 -0
  40. package/lib/util/getPendingOperationsForFragment.js +55 -0
  41. package/lib/util/getRefetchMetadata.js +36 -0
  42. package/lib/util/getValueAtPath.js +51 -0
  43. package/lib/util/isEmptyObject.js +1 -1
  44. package/lib/util/registerEnvironmentWithDevTools.js +26 -0
  45. package/lib/util/withDuration.js +31 -0
  46. package/multi-actor-environment/ActorIdentifier.js.flow +17 -1
  47. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +72 -44
  48. package/multi-actor-environment/ActorUtils.js.flow +33 -0
  49. package/multi-actor-environment/MultiActorEnvironment.js.flow +332 -80
  50. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +61 -12
  51. package/multi-actor-environment/index.js.flow +3 -0
  52. package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
  53. package/mutations/commitMutation.js.flow +2 -0
  54. package/mutations/validateMutation.js.flow +8 -0
  55. package/network/RelayObservable.js.flow +2 -0
  56. package/network/RelayQueryResponseCache.js.flow +31 -18
  57. package/network/wrapNetworkWithLogObserver.js.flow +99 -0
  58. package/package.json +1 -1
  59. package/relay-runtime.js +2 -2
  60. package/relay-runtime.min.js +2 -2
  61. package/store/ClientID.js.flow +5 -1
  62. package/store/DataChecker.js.flow +126 -35
  63. package/store/OperationExecutor.js.flow +528 -265
  64. package/store/RelayConcreteVariables.js.flow +26 -1
  65. package/store/RelayModernEnvironment.js.flow +41 -94
  66. package/store/RelayModernFragmentSpecResolver.js.flow +40 -14
  67. package/store/RelayModernOperationDescriptor.js.flow +9 -3
  68. package/store/RelayModernRecord.js.flow +49 -0
  69. package/store/RelayModernStore.js.flow +50 -12
  70. package/store/RelayOperationTracker.js.flow +56 -34
  71. package/store/RelayPublishQueue.js.flow +31 -8
  72. package/store/RelayReader.js.flow +148 -42
  73. package/store/RelayRecordSource.js.flow +72 -6
  74. package/store/RelayReferenceMarker.js.flow +29 -12
  75. package/store/RelayResponseNormalizer.js.flow +164 -48
  76. package/store/RelayStoreReactFlightUtils.js.flow +1 -7
  77. package/store/RelayStoreSubscriptions.js.flow +10 -3
  78. package/store/RelayStoreTypes.js.flow +128 -12
  79. package/store/RelayStoreUtils.js.flow +17 -3
  80. package/store/ResolverCache.js.flow +247 -0
  81. package/store/ResolverFragments.js.flow +6 -3
  82. package/store/createRelayContext.js.flow +1 -1
  83. package/subscription/requestSubscription.js.flow +41 -29
  84. package/util/NormalizationNode.js.flow +10 -3
  85. package/util/ReaderNode.js.flow +15 -1
  86. package/util/RelayConcreteNode.js.flow +1 -0
  87. package/util/RelayFeatureFlags.js.flow +8 -10
  88. package/util/RelayReplaySubject.js.flow +7 -6
  89. package/util/getPaginationMetadata.js.flow +74 -0
  90. package/util/getPaginationVariables.js.flow +112 -0
  91. package/util/getPendingOperationsForFragment.js.flow +62 -0
  92. package/util/getRefetchMetadata.js.flow +80 -0
  93. package/util/getValueAtPath.js.flow +46 -0
  94. package/util/isEmptyObject.js.flow +1 -0
  95. package/util/registerEnvironmentWithDevTools.js.flow +33 -0
  96. package/util/withDuration.js.flow +32 -0
  97. package/lib/store/RelayRecordSourceMapImpl.js +0 -107
  98. package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
  99. package/store/RelayRecordSourceMapImpl.js.flow +0 -91
  100. package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
@@ -17,6 +17,8 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
17
17
 
18
18
  var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
19
19
 
20
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
21
+
20
22
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
21
23
 
22
24
  var RelayError = require('../util/RelayError');
@@ -31,6 +33,8 @@ var RelayRecordSource = require('./RelayRecordSource');
31
33
 
32
34
  var RelayResponseNormalizer = require('./RelayResponseNormalizer');
33
35
 
36
+ var generateID = require('../util/generateID');
37
+
34
38
  var getOperation = require('../util/getOperation');
35
39
 
36
40
  var invariant = require('invariant');
@@ -39,18 +43,23 @@ var stableCopy = require('../util/stableCopy');
39
43
 
40
44
  var warning = require("fbjs/lib/warning");
41
45
 
46
+ var withDuration = require('../util/withDuration');
47
+
42
48
  var _require = require('./ClientID'),
43
49
  generateClientID = _require.generateClientID,
44
50
  generateUniqueClientID = _require.generateUniqueClientID;
45
51
 
46
- var _require2 = require('./RelayModernSelector'),
47
- createNormalizationSelector = _require2.createNormalizationSelector,
48
- createReaderSelector = _require2.createReaderSelector;
52
+ var _require2 = require('./RelayConcreteVariables'),
53
+ getLocalVariables = _require2.getLocalVariables;
49
54
 
50
- var _require3 = require('./RelayStoreUtils'),
51
- ROOT_TYPE = _require3.ROOT_TYPE,
52
- TYPENAME_KEY = _require3.TYPENAME_KEY,
53
- getStorageKey = _require3.getStorageKey;
55
+ var _require3 = require('./RelayModernSelector'),
56
+ createNormalizationSelector = _require3.createNormalizationSelector,
57
+ createReaderSelector = _require3.createReaderSelector;
58
+
59
+ var _require4 = require('./RelayStoreUtils'),
60
+ ROOT_TYPE = _require4.ROOT_TYPE,
61
+ TYPENAME_KEY = _require4.TYPENAME_KEY,
62
+ getStorageKey = _require4.getStorageKey;
54
63
 
55
64
  function execute(config) {
56
65
  return new Executor(config);
@@ -66,27 +75,51 @@ var Executor = /*#__PURE__*/function () {
66
75
  function Executor(_ref) {
67
76
  var _this = this;
68
77
 
69
- var operation = _ref.operation,
78
+ var actorIdentifier = _ref.actorIdentifier,
79
+ getDataID = _ref.getDataID,
80
+ getPublishQueue = _ref.getPublishQueue,
81
+ getStore = _ref.getStore,
82
+ isClientPayload = _ref.isClientPayload,
83
+ operation = _ref.operation,
70
84
  operationExecutions = _ref.operationExecutions,
71
85
  operationLoader = _ref.operationLoader,
86
+ operationTracker = _ref.operationTracker,
72
87
  optimisticConfig = _ref.optimisticConfig,
73
- publishQueue = _ref.publishQueue,
88
+ _reactFlightPayloadDeserializer = _ref.reactFlightPayloadDeserializer,
89
+ reactFlightServerErrorHandler = _ref.reactFlightServerErrorHandler,
74
90
  scheduler = _ref.scheduler,
91
+ shouldProcessClientComponents = _ref.shouldProcessClientComponents,
75
92
  sink = _ref.sink,
76
93
  source = _ref.source,
77
- store = _ref.store,
78
- updater = _ref.updater,
79
- operationTracker = _ref.operationTracker,
80
94
  treatMissingFieldsAsNull = _ref.treatMissingFieldsAsNull,
81
- getDataID = _ref.getDataID,
82
- isClientPayload = _ref.isClientPayload,
83
- reactFlightPayloadDeserializer = _ref.reactFlightPayloadDeserializer,
84
- reactFlightServerErrorHandler = _ref.reactFlightServerErrorHandler,
85
- shouldProcessClientComponents = _ref.shouldProcessClientComponents;
95
+ updater = _ref.updater,
96
+ log = _ref.log;
97
+ (0, _defineProperty2["default"])(this, "_deserializeReactFlightPayloadWithLogging", function (tree) {
98
+ var reactFlightPayloadDeserializer = _this._reactFlightPayloadDeserializer;
99
+ !(typeof reactFlightPayloadDeserializer === 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected reactFlightPayloadDeserializer to be available when calling _deserializeReactFlightPayloadWithLogging.') : invariant(false) : void 0;
100
+
101
+ var _withDuration = withDuration(function () {
102
+ return reactFlightPayloadDeserializer(tree);
103
+ }),
104
+ duration = _withDuration[0],
105
+ result = _withDuration[1];
106
+
107
+ _this._log({
108
+ name: 'execute.flight.payload_deserialize',
109
+ executeId: _this._executeId,
110
+ operationName: _this._operation.request.node.params.name,
111
+ duration: duration
112
+ });
113
+
114
+ return result;
115
+ });
116
+ this._actorIdentifier = actorIdentifier;
86
117
  this._getDataID = getDataID;
87
118
  this._treatMissingFieldsAsNull = treatMissingFieldsAsNull;
88
119
  this._incrementalPayloadsPending = false;
89
120
  this._incrementalResults = new Map();
121
+ this._log = log;
122
+ this._executeId = generateID();
90
123
  this._nextSubscriptionId = 0;
91
124
  this._operation = operation;
92
125
  this._operationExecutions = operationExecutions;
@@ -95,19 +128,22 @@ var Executor = /*#__PURE__*/function () {
95
128
  this._operationUpdateEpochs = new Map();
96
129
  this._optimisticUpdates = null;
97
130
  this._pendingModulePayloadsCount = 0;
98
- this._publishQueue = publishQueue;
131
+ this._getPublishQueue = getPublishQueue;
99
132
  this._scheduler = scheduler;
100
133
  this._sink = sink;
101
134
  this._source = new Map();
102
135
  this._state = 'started';
103
- this._store = store;
136
+ this._getStore = getStore;
104
137
  this._subscriptions = new Map();
105
138
  this._updater = updater;
106
139
  this._isClientPayload = isClientPayload === true;
107
- this._reactFlightPayloadDeserializer = reactFlightPayloadDeserializer;
140
+ this._reactFlightPayloadDeserializer = _reactFlightPayloadDeserializer;
108
141
  this._reactFlightServerErrorHandler = reactFlightServerErrorHandler;
109
142
  this._isSubscriptionOperation = this._operation.request.node.params.operationKind === 'subscription';
110
143
  this._shouldProcessClientComponents = shouldProcessClientComponents;
144
+ this._retainDisposables = new Map();
145
+ this._seenActors = new Set();
146
+ this._completeFns = [];
111
147
  var id = this._nextSubscriptionId++;
112
148
  source.subscribe({
113
149
  complete: function complete() {
@@ -124,7 +160,17 @@ var Executor = /*#__PURE__*/function () {
124
160
  }
125
161
  },
126
162
  start: function start(subscription) {
127
- return _this._start(id, subscription);
163
+ var _this$_operation$requ;
164
+
165
+ _this._start(id, subscription);
166
+
167
+ _this._log({
168
+ name: 'execute.start',
169
+ executeId: _this._executeId,
170
+ params: _this._operation.request.node.params,
171
+ variables: _this._operation.request.variables,
172
+ cacheConfig: (_this$_operation$requ = _this._operation.request.cacheConfig) !== null && _this$_operation$requ !== void 0 ? _this$_operation$requ : {}
173
+ });
128
174
  }
129
175
  });
130
176
 
@@ -162,21 +208,25 @@ var Executor = /*#__PURE__*/function () {
162
208
  if (optimisticUpdates !== null) {
163
209
  this._optimisticUpdates = null;
164
210
  optimisticUpdates.forEach(function (update) {
165
- return _this2._publishQueue.revertUpdate(update);
211
+ return _this2._getPublishQueueAndSaveActor().revertUpdate(update);
166
212
  }); // OK: run revert on cancel
167
213
 
168
- this._publishQueue.run();
214
+ this._runPublishQueue();
169
215
  }
170
216
 
171
217
  this._incrementalResults.clear();
172
218
 
173
- this._completeOperationTracker();
174
-
175
- if (this._retainDisposable) {
176
- this._retainDisposable.dispose();
219
+ if (this._asyncStoreUpdateDisposable != null) {
220
+ this._asyncStoreUpdateDisposable.dispose();
177
221
 
178
- this._retainDisposable = null;
222
+ this._asyncStoreUpdateDisposable = null;
179
223
  }
224
+
225
+ this._completeFns = [];
226
+
227
+ this._completeOperationTracker();
228
+
229
+ this._disposeRetainedData();
180
230
  };
181
231
 
182
232
  _proto._updateActiveState = function _updateActiveState() {
@@ -258,6 +308,11 @@ var Executor = /*#__PURE__*/function () {
258
308
  this.cancel();
259
309
 
260
310
  this._sink.complete();
311
+
312
+ this._log({
313
+ name: 'execute.complete',
314
+ executeId: this._executeId
315
+ });
261
316
  }
262
317
  };
263
318
 
@@ -265,6 +320,12 @@ var Executor = /*#__PURE__*/function () {
265
320
  this.cancel();
266
321
 
267
322
  this._sink.error(error);
323
+
324
+ this._log({
325
+ name: 'execute.error',
326
+ executeId: this._executeId,
327
+ error: error
328
+ });
268
329
  };
269
330
 
270
331
  _proto._start = function _start(id, subscription) {
@@ -278,9 +339,19 @@ var Executor = /*#__PURE__*/function () {
278
339
  var _this4 = this;
279
340
 
280
341
  this._schedule(function () {
281
- _this4._handleNext(response);
282
-
283
- _this4._maybeCompleteSubscriptionOperationTracking();
342
+ var _withDuration2 = withDuration(function () {
343
+ _this4._handleNext(response);
344
+
345
+ _this4._maybeCompleteSubscriptionOperationTracking();
346
+ }),
347
+ duration = _withDuration2[0];
348
+
349
+ _this4._log({
350
+ name: 'execute.next',
351
+ executeId: _this4._executeId,
352
+ response: response,
353
+ duration: duration
354
+ });
284
355
  });
285
356
  };
286
357
 
@@ -332,7 +403,7 @@ var Executor = /*#__PURE__*/function () {
332
403
 
333
404
  return ((_responsePart$extensi = responsePart.extensions) === null || _responsePart$extensi === void 0 ? void 0 : _responsePart$extensi.isOptimistic) === true;
334
405
  })) {
335
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Optimistic responses cannot be batched.') : invariant(false) : void 0;
406
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Optimistic responses cannot be batched.') : invariant(false) : void 0;
336
407
  }
337
408
 
338
409
  return false;
@@ -361,6 +432,8 @@ var Executor = /*#__PURE__*/function () {
361
432
  return;
362
433
  }
363
434
 
435
+ this._seenActors.clear();
436
+
364
437
  var responses = Array.isArray(response) ? response : [response];
365
438
 
366
439
  var responsesWithData = this._handleErrorResponse(responses);
@@ -407,39 +480,30 @@ var Executor = /*#__PURE__*/function () {
407
480
  // payloads (although, can that even happen?)
408
481
 
409
482
  if (hasNonIncrementalResponses) {
410
- var payloadFollowups = this._processResponses(nonIncrementalResponses);
411
-
412
- if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
413
- var updatedOwners = this._publishQueue.run(this._operation);
414
-
415
- this._updateOperationTracker(updatedOwners);
483
+ // For subscriptions, to avoid every new payload from overwriting existing
484
+ // data from previous payloads, assign a unique rootID for every new
485
+ // non-incremental payload.
486
+ if (this._isSubscriptionOperation) {
487
+ var nextID = generateUniqueClientID();
488
+ this._operation = {
489
+ request: this._operation.request,
490
+ fragment: createReaderSelector(this._operation.fragment.node, nextID, this._operation.fragment.variables, this._operation.fragment.owner),
491
+ root: createNormalizationSelector(this._operation.root.node, nextID, this._operation.root.variables)
492
+ };
416
493
  }
417
494
 
418
- this._processPayloadFollowups(payloadFollowups);
495
+ var payloadFollowups = this._processResponses(nonIncrementalResponses);
419
496
 
420
- if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
421
- if (this._incrementalPayloadsPending && !this._retainDisposable) {
422
- this._retainDisposable = this._store.retain(this._operation);
423
- }
424
- }
497
+ this._processPayloadFollowups(payloadFollowups);
425
498
  }
426
499
 
427
500
  if (incrementalResponses.length > 0) {
428
501
  var _payloadFollowups = this._processIncrementalResponses(incrementalResponses);
429
502
 
430
- if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
431
- // For the incremental case, we're only handling follow-up responses
432
- // for already initiated operation (and we're not passing it to
433
- // the run(...) call)
434
- var _updatedOwners = this._publishQueue.run();
435
-
436
- this._updateOperationTracker(_updatedOwners);
437
- }
438
-
439
503
  this._processPayloadFollowups(_payloadFollowups);
440
504
  }
441
505
 
442
- if (this._isSubscriptionOperation && RelayFeatureFlags.ENABLE_UNIQUE_SUBSCRIPTION_ROOT) {
506
+ if (this._isSubscriptionOperation) {
443
507
  // We attach the id to allow the `requestSubscription` to read from the store using
444
508
  // the current id in its `onNext` callback
445
509
  if (responsesWithData[0].extensions == null) {
@@ -450,31 +514,29 @@ var Executor = /*#__PURE__*/function () {
450
514
  } else {
451
515
  responsesWithData[0].extensions.__relay_subscription_root_id = this._operation.fragment.dataID;
452
516
  }
453
- }
517
+ } // OK: run once after each new payload
518
+ // If we have non-incremental responses, we passing `this._operation` to
519
+ // the publish queue here, which will later be passed to the store (via
520
+ // notify) to indicate that this operation caused the store to update
454
521
 
455
- if (RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
456
- // OK: run once after each new payload
457
- // If we have non-incremental responses, we passing `this._operation` to
458
- // the publish queue here, which will later be passed to the store (via
459
- // notify) to indicate that this operation caused the store to update
460
- var _updatedOwners2 = this._publishQueue.run(hasNonIncrementalResponses ? this._operation : undefined);
461
522
 
462
- if (hasNonIncrementalResponses) {
463
- if (this._incrementalPayloadsPending && !this._retainDisposable) {
464
- this._retainDisposable = this._store.retain(this._operation);
465
- }
466
- }
523
+ var updatedOwners = this._runPublishQueue(hasNonIncrementalResponses ? this._operation : undefined);
467
524
 
468
- this._updateOperationTracker(_updatedOwners2);
525
+ if (hasNonIncrementalResponses) {
526
+ if (this._incrementalPayloadsPending) {
527
+ this._retainData();
528
+ }
469
529
  }
470
530
 
531
+ this._updateOperationTracker(updatedOwners);
532
+
471
533
  this._sink.next(response);
472
534
  };
473
535
 
474
536
  _proto._processOptimisticResponse = function _processOptimisticResponse(response, updater, treatMissingFieldsAsNull) {
475
537
  var _this6 = this;
476
538
 
477
- !(this._optimisticUpdates === null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'environment.execute: only support one optimistic response per ' + 'execute.') : invariant(false) : void 0;
539
+ !(this._optimisticUpdates === null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: environment.execute: only support one optimistic response per ' + 'execute.') : invariant(false) : void 0;
478
540
 
479
541
  if (response == null && updater == null) {
480
542
  return;
@@ -484,9 +546,10 @@ var Executor = /*#__PURE__*/function () {
484
546
 
485
547
  if (response) {
486
548
  var payload = normalizeResponse(response, this._operation.root, ROOT_TYPE, {
549
+ actorIdentifier: this._actorIdentifier,
487
550
  getDataID: this._getDataID,
488
551
  path: [],
489
- reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
552
+ reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer != null ? this._deserializeReactFlightPayloadWithLogging : null,
490
553
  reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
491
554
  shouldProcessClientComponents: this._shouldProcessClientComponents,
492
555
  treatMissingFieldsAsNull: treatMissingFieldsAsNull
@@ -506,7 +569,7 @@ var Executor = /*#__PURE__*/function () {
506
569
  errors: null,
507
570
  fieldPayloads: null,
508
571
  incrementalPlaceholders: null,
509
- moduleImportPayloads: null,
572
+ followupPayloads: null,
510
573
  source: RelayRecordSource.create(),
511
574
  isFinal: false
512
575
  },
@@ -516,33 +579,47 @@ var Executor = /*#__PURE__*/function () {
516
579
 
517
580
  this._optimisticUpdates = optimisticUpdates;
518
581
  optimisticUpdates.forEach(function (update) {
519
- return _this6._publishQueue.applyUpdate(update);
582
+ return _this6._getPublishQueueAndSaveActor().applyUpdate(update);
520
583
  }); // OK: only called on construction and when receiving an optimistic payload from network,
521
584
  // which doesn't fall-through to the regular next() handling
522
585
 
523
- this._publishQueue.run();
586
+ this._runPublishQueue();
524
587
  };
525
588
 
526
589
  _proto._processOptimisticFollowups = function _processOptimisticFollowups(payload, optimisticUpdates) {
527
- if (payload.moduleImportPayloads && payload.moduleImportPayloads.length) {
528
- var moduleImportPayloads = payload.moduleImportPayloads;
529
- var operationLoader = this._operationLoader;
530
- !operationLoader ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected an operationLoader to be ' + 'configured when using `@match`.') : invariant(false) : void 0;
590
+ if (payload.followupPayloads && payload.followupPayloads.length) {
591
+ var followupPayloads = payload.followupPayloads;
531
592
 
532
- var _iterator = (0, _createForOfIteratorHelper2["default"])(moduleImportPayloads),
593
+ var _iterator = (0, _createForOfIteratorHelper2["default"])(followupPayloads),
533
594
  _step;
534
595
 
535
596
  try {
536
597
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
537
- var moduleImportPayload = _step.value;
538
- var operation = operationLoader.get(moduleImportPayload.operationReference);
598
+ var followupPayload = _step.value;
599
+
600
+ switch (followupPayload.kind) {
601
+ case 'ModuleImportPayload':
602
+ var operationLoader = this._expectOperationLoader();
603
+
604
+ var operation = operationLoader.get(followupPayload.operationReference);
605
+
606
+ if (operation == null) {
607
+ this._processAsyncOptimisticModuleImport(followupPayload);
608
+ } else {
609
+ var moduleImportOptimisticUpdates = this._processOptimisticModuleImport(operation, followupPayload);
539
610
 
540
- if (operation == null) {
541
- this._processAsyncOptimisticModuleImport(operationLoader, moduleImportPayload);
542
- } else {
543
- var moduleImportOptimisticUpdates = this._processOptimisticModuleImport(operation, moduleImportPayload);
611
+ optimisticUpdates.push.apply(optimisticUpdates, (0, _toConsumableArray2["default"])(moduleImportOptimisticUpdates));
612
+ }
544
613
 
545
- optimisticUpdates.push.apply(optimisticUpdates, (0, _toConsumableArray2["default"])(moduleImportOptimisticUpdates));
614
+ break;
615
+
616
+ case 'ActorPayload':
617
+ process.env.NODE_ENV !== "production" ? warning(false, 'OperationExecutor: Unexpected optimistic ActorPayload. These updates are not supported.') : void 0;
618
+ break;
619
+
620
+ default:
621
+ followupPayload;
622
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Unexpected followup kind `%s`. when processing optimistic updates.', followupPayload.kind) : invariant(false) : void 0;
546
623
  }
547
624
  }
548
625
  } catch (err) {
@@ -551,16 +628,29 @@ var Executor = /*#__PURE__*/function () {
551
628
  _iterator.f();
552
629
  }
553
630
  }
554
- };
631
+ }
632
+ /**
633
+ * Normalize Data for @module payload, and actor-specific payload
634
+ */
635
+ ;
636
+
637
+ _proto._normalizeFollowupPayload = function _normalizeFollowupPayload(followupPayload, normalizationNode) {
638
+ var variables;
639
+
640
+ if (normalizationNode.kind === 'SplitOperation' && followupPayload.kind === 'ModuleImportPayload') {
641
+ variables = getLocalVariables(followupPayload.variables, normalizationNode.argumentDefinitions, followupPayload.args);
642
+ } else {
643
+ variables = followupPayload.variables;
644
+ }
555
645
 
556
- _proto._normalizeModuleImport = function _normalizeModuleImport(moduleImportPayload, operation) {
557
- var selector = createNormalizationSelector(operation, moduleImportPayload.dataID, moduleImportPayload.variables);
646
+ var selector = createNormalizationSelector(normalizationNode, followupPayload.dataID, variables);
558
647
  return normalizeResponse({
559
- data: moduleImportPayload.data
560
- }, selector, moduleImportPayload.typeName, {
648
+ data: followupPayload.data
649
+ }, selector, followupPayload.typeName, {
650
+ actorIdentifier: this._actorIdentifier,
561
651
  getDataID: this._getDataID,
562
- path: moduleImportPayload.path,
563
- reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
652
+ path: followupPayload.path,
653
+ reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer != null ? this._deserializeReactFlightPayloadWithLogging : null,
564
654
  reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
565
655
  treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
566
656
  shouldProcessClientComponents: this._shouldProcessClientComponents
@@ -571,7 +661,7 @@ var Executor = /*#__PURE__*/function () {
571
661
  var operation = getOperation(normalizationRootNode);
572
662
  var optimisticUpdates = [];
573
663
 
574
- var modulePayload = this._normalizeModuleImport(moduleImportPayload, operation);
664
+ var modulePayload = this._normalizeFollowupPayload(moduleImportPayload, operation);
575
665
 
576
666
  validateOptimisticResponsePayload(modulePayload);
577
667
  optimisticUpdates.push({
@@ -585,10 +675,10 @@ var Executor = /*#__PURE__*/function () {
585
675
  return optimisticUpdates;
586
676
  };
587
677
 
588
- _proto._processAsyncOptimisticModuleImport = function _processAsyncOptimisticModuleImport(operationLoader, moduleImportPayload) {
678
+ _proto._processAsyncOptimisticModuleImport = function _processAsyncOptimisticModuleImport(moduleImportPayload) {
589
679
  var _this7 = this;
590
680
 
591
- operationLoader.load(moduleImportPayload.operationReference).then(function (operation) {
681
+ this._expectOperationLoader().load(moduleImportPayload.operationReference).then(function (operation) {
592
682
  if (operation == null || _this7._state !== 'started') {
593
683
  return;
594
684
  }
@@ -596,7 +686,7 @@ var Executor = /*#__PURE__*/function () {
596
686
  var moduleImportOptimisticUpdates = _this7._processOptimisticModuleImport(operation, moduleImportPayload);
597
687
 
598
688
  moduleImportOptimisticUpdates.forEach(function (update) {
599
- return _this7._publishQueue.applyUpdate(update);
689
+ return _this7._getPublishQueueAndSaveActor().applyUpdate(update);
600
690
  });
601
691
 
602
692
  if (_this7._optimisticUpdates == null) {
@@ -607,7 +697,7 @@ var Executor = /*#__PURE__*/function () {
607
697
  (_this$_optimisticUpda = _this7._optimisticUpdates).push.apply(_this$_optimisticUpda, (0, _toConsumableArray2["default"])(moduleImportOptimisticUpdates)); // OK: always have to run() after an module import resolves async
608
698
 
609
699
 
610
- _this7._publishQueue.run();
700
+ _this7._runPublishQueue();
611
701
  }
612
702
  });
613
703
  };
@@ -617,7 +707,7 @@ var Executor = /*#__PURE__*/function () {
617
707
 
618
708
  if (this._optimisticUpdates !== null) {
619
709
  this._optimisticUpdates.forEach(function (update) {
620
- return _this8._publishQueue.revertUpdate(update);
710
+ _this8._getPublishQueueAndSaveActor().revertUpdate(update);
621
711
  });
622
712
 
623
713
  this._optimisticUpdates = null;
@@ -631,15 +721,16 @@ var Executor = /*#__PURE__*/function () {
631
721
 
632
722
  return responses.map(function (payloadPart) {
633
723
  var relayPayload = normalizeResponse(payloadPart, _this8._operation.root, ROOT_TYPE, {
724
+ actorIdentifier: _this8._actorIdentifier,
634
725
  getDataID: _this8._getDataID,
635
726
  path: [],
636
- reactFlightPayloadDeserializer: _this8._reactFlightPayloadDeserializer,
727
+ reactFlightPayloadDeserializer: _this8._reactFlightPayloadDeserializer != null ? _this8._deserializeReactFlightPayloadWithLogging : null,
637
728
  reactFlightServerErrorHandler: _this8._reactFlightServerErrorHandler,
638
729
  treatMissingFieldsAsNull: _this8._treatMissingFieldsAsNull,
639
730
  shouldProcessClientComponents: _this8._shouldProcessClientComponents
640
731
  });
641
732
 
642
- _this8._publishQueue.commitPayload(_this8._operation, relayPayload, _this8._updater);
733
+ _this8._getPublishQueueAndSaveActor().commitPayload(_this8._operation, relayPayload, _this8._updater);
643
734
 
644
735
  return relayPayload;
645
736
  });
@@ -659,7 +750,7 @@ var Executor = /*#__PURE__*/function () {
659
750
 
660
751
  payloads.forEach(function (payload) {
661
752
  var incrementalPlaceholders = payload.incrementalPlaceholders,
662
- moduleImportPayloads = payload.moduleImportPayloads,
753
+ followupPayloads = payload.followupPayloads,
663
754
  isFinal = payload.isFinal;
664
755
  _this9._state = isFinal ? 'loading_final' : 'loading_incremental';
665
756
 
@@ -669,18 +760,30 @@ var Executor = /*#__PURE__*/function () {
669
760
  _this9._incrementalPayloadsPending = false;
670
761
  }
671
762
 
672
- if (moduleImportPayloads && moduleImportPayloads.length !== 0) {
673
- var operationLoader = _this9._operationLoader;
674
- !operationLoader ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected an operationLoader to be ' + 'configured when using `@match`.') : invariant(false) : void 0;
675
- moduleImportPayloads.forEach(function (moduleImportPayload) {
676
- _this9._processModuleImportPayload(moduleImportPayload, operationLoader);
763
+ if (followupPayloads && followupPayloads.length !== 0) {
764
+ followupPayloads.forEach(function (followupPayload) {
765
+ var _followupPayload$acto;
766
+
767
+ var prevActorIdentifier = _this9._actorIdentifier;
768
+ _this9._actorIdentifier = (_followupPayload$acto = followupPayload.actorIdentifier) !== null && _followupPayload$acto !== void 0 ? _followupPayload$acto : _this9._actorIdentifier;
769
+
770
+ _this9._processFollowupPayload(followupPayload);
771
+
772
+ _this9._actorIdentifier = prevActorIdentifier;
677
773
  });
678
774
  }
679
775
 
680
776
  if (incrementalPlaceholders && incrementalPlaceholders.length !== 0) {
681
777
  _this9._incrementalPayloadsPending = _this9._state !== 'loading_final';
682
778
  incrementalPlaceholders.forEach(function (incrementalPlaceholder) {
779
+ var _incrementalPlacehold;
780
+
781
+ var prevActorIdentifier = _this9._actorIdentifier;
782
+ _this9._actorIdentifier = (_incrementalPlacehold = incrementalPlaceholder.actorIdentifier) !== null && _incrementalPlacehold !== void 0 ? _incrementalPlacehold : _this9._actorIdentifier;
783
+
683
784
  _this9._processIncrementalPlaceholder(payload, incrementalPlaceholder);
785
+
786
+ _this9._actorIdentifier = prevActorIdentifier;
684
787
  });
685
788
 
686
789
  if (_this9._isClientPayload || _this9._state === 'loading_final') {
@@ -702,12 +805,6 @@ var Executor = /*#__PURE__*/function () {
702
805
  });
703
806
 
704
807
  if (relayPayloads.length > 0) {
705
- if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
706
- var updatedOwners = _this9._publishQueue.run();
707
-
708
- _this9._updateOperationTracker(updatedOwners);
709
- }
710
-
711
808
  _this9._processPayloadFollowups(relayPayloads);
712
809
  }
713
810
  }
@@ -723,15 +820,6 @@ var Executor = /*#__PURE__*/function () {
723
820
  if (this._pendingModulePayloadsCount === 0 && this._incrementalPayloadsPending === false) {
724
821
  this._completeOperationTracker();
725
822
  }
726
-
727
- if (RelayFeatureFlags.ENABLE_UNIQUE_SUBSCRIPTION_ROOT) {
728
- var nextID = generateUniqueClientID();
729
- this._operation = {
730
- request: this._operation.request,
731
- fragment: createReaderSelector(this._operation.fragment.node, nextID, this._operation.fragment.variables, this._operation.fragment.owner),
732
- root: createNormalizationSelector(this._operation.root.node, nextID, this._operation.root.variables)
733
- };
734
- }
735
823
  }
736
824
  /**
737
825
  * Processes a ModuleImportPayload, asynchronously resolving the normalization
@@ -742,75 +830,140 @@ var Executor = /*#__PURE__*/function () {
742
830
  */
743
831
  ;
744
832
 
745
- _proto._processModuleImportPayload = function _processModuleImportPayload(moduleImportPayload, operationLoader) {
833
+ _proto._processFollowupPayload = function _processFollowupPayload(followupPayload) {
746
834
  var _this10 = this;
747
835
 
748
- var node = operationLoader.get(moduleImportPayload.operationReference);
749
-
750
- if (node != null) {
751
- var operation = getOperation(node); // If the operation module is available synchronously, normalize the
752
- // data synchronously.
753
-
754
- this._handleModuleImportPayload(moduleImportPayload, operation);
755
-
756
- this._maybeCompleteSubscriptionOperationTracking();
757
- } else {
758
- // Otherwise load the operation module and schedule a task to normalize
759
- // the data when the module is available.
760
- var _id3 = this._nextSubscriptionId++;
761
-
762
- this._pendingModulePayloadsCount++;
763
-
764
- var decrementPendingCount = function decrementPendingCount() {
765
- _this10._pendingModulePayloadsCount--;
766
-
767
- _this10._maybeCompleteSubscriptionOperationTracking();
768
- }; // Observable.from(operationLoader.load()) wouldn't catch synchronous
769
- // errors thrown by the load function, which is user-defined. Guard
770
- // against that with Observable.from(new Promise(<work>)).
771
-
772
-
773
- RelayObservable.from(new Promise(function (resolve, reject) {
774
- operationLoader.load(moduleImportPayload.operationReference).then(resolve, reject);
775
- })).map(function (operation) {
776
- if (operation != null) {
777
- _this10._schedule(function () {
778
- _this10._handleModuleImportPayload(moduleImportPayload, getOperation(operation)); // OK: always have to run after an async module import resolves
779
-
780
-
781
- var updatedOwners = _this10._publishQueue.run();
782
-
783
- _this10._updateOperationTracker(updatedOwners);
836
+ switch (followupPayload.kind) {
837
+ case 'ModuleImportPayload':
838
+ var operationLoader = this._expectOperationLoader();
839
+
840
+ var node = operationLoader.get(followupPayload.operationReference);
841
+
842
+ if (node != null) {
843
+ // If the operation module is available synchronously, normalize the
844
+ // data synchronously.
845
+ this._processFollowupPayloadWithNormalizationNode(followupPayload, getOperation(node));
846
+ } else {
847
+ // Otherwise load the operation module and schedule a task to normalize
848
+ // the data when the module is available.
849
+ var _id3 = this._nextSubscriptionId++;
850
+
851
+ this._pendingModulePayloadsCount++;
852
+
853
+ var decrementPendingCount = function decrementPendingCount() {
854
+ _this10._pendingModulePayloadsCount--;
855
+
856
+ _this10._maybeCompleteSubscriptionOperationTracking();
857
+ }; // Observable.from(operationLoader.load()) wouldn't catch synchronous
858
+ // errors thrown by the load function, which is user-defined. Guard
859
+ // against that with Observable.from(new Promise(<work>)).
860
+
861
+
862
+ var networkObservable = RelayObservable.from(new Promise(function (resolve, reject) {
863
+ operationLoader.load(followupPayload.operationReference).then(resolve, reject);
864
+ }));
865
+ RelayObservable.create(function (sink) {
866
+ var cancellationToken;
867
+ var subscription = networkObservable.subscribe({
868
+ next: function next(loadedNode) {
869
+ if (loadedNode != null) {
870
+ var publishModuleImportPayload = function publishModuleImportPayload() {
871
+ try {
872
+ var operation = getOperation(loadedNode);
873
+ var batchAsyncModuleUpdatesFN = RelayFeatureFlags.BATCH_ASYNC_MODULE_UPDATES_FN;
874
+ var shouldScheduleAsyncStoreUpdate = batchAsyncModuleUpdatesFN != null && _this10._pendingModulePayloadsCount > 1;
875
+
876
+ var _withDuration3 = withDuration(function () {
877
+ _this10._handleFollowupPayload(followupPayload, operation); // OK: always have to run after an async module import resolves
878
+
879
+
880
+ // OK: always have to run after an async module import resolves
881
+ if (shouldScheduleAsyncStoreUpdate) {
882
+ _this10._scheduleAsyncStoreUpdate( // $FlowFixMe[incompatible-call] `shouldScheduleAsyncStoreUpdate` check should cover `null` case
883
+ batchAsyncModuleUpdatesFN, sink.complete);
884
+ } else {
885
+ var updatedOwners = _this10._runPublishQueue();
886
+
887
+ _this10._updateOperationTracker(updatedOwners);
888
+ }
889
+ }),
890
+ duration = _withDuration3[0];
891
+
892
+ _this10._log({
893
+ name: 'execute.async.module',
894
+ executeId: _this10._executeId,
895
+ operationName: operation.name,
896
+ duration: duration
897
+ });
898
+
899
+ if (!shouldScheduleAsyncStoreUpdate) {
900
+ sink.complete();
901
+ }
902
+ } catch (error) {
903
+ sink.error(error);
904
+ }
905
+ };
906
+
907
+ var scheduler = _this10._scheduler;
908
+
909
+ if (scheduler == null) {
910
+ publishModuleImportPayload();
911
+ } else {
912
+ cancellationToken = scheduler.schedule(publishModuleImportPayload);
913
+ }
914
+ } else {
915
+ sink.complete();
916
+ }
917
+ },
918
+ error: sink.error
919
+ });
920
+ return function () {
921
+ subscription.unsubscribe();
922
+
923
+ if (_this10._scheduler != null && cancellationToken != null) {
924
+ _this10._scheduler.cancel(cancellationToken);
925
+ }
926
+ };
927
+ }).subscribe({
928
+ complete: function complete() {
929
+ _this10._complete(_id3);
930
+
931
+ decrementPendingCount();
932
+ },
933
+ error: function error(_error4) {
934
+ _this10._error(_error4);
935
+
936
+ decrementPendingCount();
937
+ },
938
+ start: function start(subscription) {
939
+ return _this10._start(_id3, subscription);
940
+ }
784
941
  });
785
942
  }
786
- }).subscribe({
787
- complete: function complete() {
788
- _this10._complete(_id3);
789
943
 
790
- decrementPendingCount();
791
- },
792
- error: function error(_error4) {
793
- _this10._error(_error4);
944
+ break;
794
945
 
795
- decrementPendingCount();
796
- },
797
- start: function start(subscription) {
798
- return _this10._start(_id3, subscription);
799
- }
800
- });
946
+ case 'ActorPayload':
947
+ this._processFollowupPayloadWithNormalizationNode(followupPayload, followupPayload.node);
948
+
949
+ break;
950
+
951
+ default:
952
+ followupPayload;
953
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Unexpected followup kind `%s`.', followupPayload.kind) : invariant(false) : void 0;
801
954
  }
802
955
  };
803
956
 
804
- _proto._handleModuleImportPayload = function _handleModuleImportPayload(moduleImportPayload, operation) {
805
- var relayPayload = this._normalizeModuleImport(moduleImportPayload, operation);
957
+ _proto._processFollowupPayloadWithNormalizationNode = function _processFollowupPayloadWithNormalizationNode(followupPayload, normalizationNode) {
958
+ this._handleFollowupPayload(followupPayload, normalizationNode);
806
959
 
807
- this._publishQueue.commitPayload(this._operation, relayPayload);
960
+ this._maybeCompleteSubscriptionOperationTracking();
961
+ };
808
962
 
809
- if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
810
- var updatedOwners = this._publishQueue.run();
963
+ _proto._handleFollowupPayload = function _handleFollowupPayload(followupPayload, normalizationNode) {
964
+ var relayPayload = this._normalizeFollowupPayload(followupPayload, normalizationNode);
811
965
 
812
- this._updateOperationTracker(updatedOwners);
813
- }
966
+ this._getPublishQueueAndSaveActor().commitPayload(this._operation, relayPayload);
814
967
 
815
968
  this._processPayloadFollowups([relayPayload]);
816
969
  }
@@ -860,7 +1013,7 @@ var Executor = /*#__PURE__*/function () {
860
1013
  parentID = placeholder.selector.dataID;
861
1014
  } else {
862
1015
  placeholder;
863
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Unsupported incremental placeholder kind `%s`.', placeholder.kind) : invariant(false) : void 0;
1016
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Unsupported incremental placeholder kind `%s`.', placeholder.kind) : invariant(false) : void 0;
864
1017
  }
865
1018
 
866
1019
  var parentRecord = relayPayload.source.get(parentID);
@@ -874,7 +1027,7 @@ var Executor = /*#__PURE__*/function () {
874
1027
  }); // If an incremental payload exists for some id that record should also
875
1028
  // exist.
876
1029
 
877
- !(parentRecord != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected record `%s` to exist.', parentID) : invariant(false) : void 0;
1030
+ !(parentRecord != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected record `%s` to exist.', parentID) : invariant(false) : void 0;
878
1031
  var nextParentRecord;
879
1032
  var nextParentPayloads;
880
1033
 
@@ -909,12 +1062,6 @@ var Executor = /*#__PURE__*/function () {
909
1062
  if (pendingResponses != null) {
910
1063
  var payloadFollowups = this._processIncrementalResponses(pendingResponses);
911
1064
 
912
- if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
913
- var updatedOwners = this._publishQueue.run();
914
-
915
- this._updateOperationTracker(updatedOwners);
916
- }
917
-
918
1065
  this._processPayloadFollowups(payloadFollowups);
919
1066
  }
920
1067
  }
@@ -959,7 +1106,7 @@ var Executor = /*#__PURE__*/function () {
959
1106
  }
960
1107
 
961
1108
  var placeholder = resultForPath.placeholder;
962
- !(placeholder.kind === 'defer') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected data for path `%s` for label `%s` ' + 'to be data for @defer, was `@%s`.', pathKey, label, placeholder.kind) : invariant(false) : void 0;
1109
+ !(placeholder.kind === 'defer') ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected data for path `%s` for label `%s` ' + 'to be data for @defer, was `@%s`.', pathKey, label, placeholder.kind) : invariant(false) : void 0;
963
1110
  relayPayloads.push(_this11._processDeferResponse(label, path, placeholder, response));
964
1111
  } else {
965
1112
  // @stream payload path values end in the field name and item index,
@@ -984,7 +1131,7 @@ var Executor = /*#__PURE__*/function () {
984
1131
  }
985
1132
 
986
1133
  var _placeholder = _resultForPath.placeholder;
987
- !(_placeholder.kind === 'stream') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected data for path `%s` for label `%s` ' + 'to be data for @stream, was `@%s`.', _pathKey, label, _placeholder.kind) : invariant(false) : void 0;
1134
+ !(_placeholder.kind === 'stream') ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected data for path `%s` for label `%s` ' + 'to be data for @stream, was `@%s`.', _pathKey, label, _placeholder.kind) : invariant(false) : void 0;
988
1135
  relayPayloads.push(_this11._processStreamResponse(label, path, _placeholder, response));
989
1136
  }
990
1137
  });
@@ -992,23 +1139,28 @@ var Executor = /*#__PURE__*/function () {
992
1139
  };
993
1140
 
994
1141
  _proto._processDeferResponse = function _processDeferResponse(label, path, placeholder, response) {
1142
+ var _placeholder$actorIde;
1143
+
995
1144
  var parentID = placeholder.selector.dataID;
1145
+ var prevActorIdentifier = this._actorIdentifier;
1146
+ this._actorIdentifier = (_placeholder$actorIde = placeholder.actorIdentifier) !== null && _placeholder$actorIde !== void 0 ? _placeholder$actorIde : this._actorIdentifier;
996
1147
  var relayPayload = normalizeResponse(response, placeholder.selector, placeholder.typeName, {
1148
+ actorIdentifier: this._actorIdentifier,
997
1149
  getDataID: this._getDataID,
998
1150
  path: placeholder.path,
999
- reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
1151
+ reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer != null ? this._deserializeReactFlightPayloadWithLogging : null,
1000
1152
  reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
1001
1153
  treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
1002
1154
  shouldProcessClientComponents: this._shouldProcessClientComponents
1003
1155
  });
1004
1156
 
1005
- this._publishQueue.commitPayload(this._operation, relayPayload); // Load the version of the parent record from which this incremental data
1157
+ this._getPublishQueueAndSaveActor().commitPayload(this._operation, relayPayload); // Load the version of the parent record from which this incremental data
1006
1158
  // was derived
1007
1159
 
1008
1160
 
1009
1161
  var parentEntry = this._source.get(parentID);
1010
1162
 
1011
- !(parentEntry != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected the parent record `%s` for @defer ' + 'data to exist.', parentID) : invariant(false) : void 0;
1163
+ !(parentEntry != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected the parent record `%s` for @defer ' + 'data to exist.', parentID) : invariant(false) : void 0;
1012
1164
  var fieldPayloads = parentEntry.fieldPayloads;
1013
1165
 
1014
1166
  if (fieldPayloads.length !== 0) {
@@ -1018,14 +1170,15 @@ var Executor = /*#__PURE__*/function () {
1018
1170
  errors: null,
1019
1171
  fieldPayloads: fieldPayloads,
1020
1172
  incrementalPlaceholders: null,
1021
- moduleImportPayloads: null,
1173
+ followupPayloads: null,
1022
1174
  source: RelayRecordSource.create(),
1023
1175
  isFinal: ((_response$extensions2 = response.extensions) === null || _response$extensions2 === void 0 ? void 0 : _response$extensions2.is_final) === true
1024
1176
  };
1025
1177
 
1026
- this._publishQueue.commitPayload(this._operation, handleFieldsRelayPayload);
1178
+ this._getPublishQueueAndSaveActor().commitPayload(this._operation, handleFieldsRelayPayload);
1027
1179
  }
1028
1180
 
1181
+ this._actorIdentifier = prevActorIdentifier;
1029
1182
  return relayPayload;
1030
1183
  }
1031
1184
  /**
@@ -1036,10 +1189,13 @@ var Executor = /*#__PURE__*/function () {
1036
1189
  _proto._processStreamResponse = function _processStreamResponse(label, path, placeholder, response) {
1037
1190
  var parentID = placeholder.parentID,
1038
1191
  node = placeholder.node,
1039
- variables = placeholder.variables; // Find the LinkedField where @stream was applied
1192
+ variables = placeholder.variables,
1193
+ actorIdentifier = placeholder.actorIdentifier;
1194
+ var prevActorIdentifier = this._actorIdentifier;
1195
+ this._actorIdentifier = actorIdentifier !== null && actorIdentifier !== void 0 ? actorIdentifier : this._actorIdentifier; // Find the LinkedField where @stream was applied
1040
1196
 
1041
1197
  var field = node.selections[0];
1042
- !(field != null && field.kind === 'LinkedField' && field.plural === true) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected @stream to be used on a plural field.') : invariant(false) : void 0;
1198
+ !(field != null && field.kind === 'LinkedField' && field.plural === true) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected @stream to be used on a plural field.') : invariant(false) : void 0;
1043
1199
 
1044
1200
  var _this$_normalizeStrea = this._normalizeStreamItem(response, parentID, field, variables, path, placeholder.path),
1045
1201
  fieldPayloads = _this$_normalizeStrea.fieldPayloads,
@@ -1052,7 +1208,7 @@ var Executor = /*#__PURE__*/function () {
1052
1208
  // modified.
1053
1209
 
1054
1210
 
1055
- this._publishQueue.commitPayload(this._operation, relayPayload, function (store) {
1211
+ this._getPublishQueueAndSaveActor().commitPayload(this._operation, relayPayload, function (store) {
1056
1212
  var currentParentRecord = store.get(parentID);
1057
1213
 
1058
1214
  if (currentParentRecord == null) {
@@ -1089,14 +1245,15 @@ var Executor = /*#__PURE__*/function () {
1089
1245
  errors: null,
1090
1246
  fieldPayloads: fieldPayloads,
1091
1247
  incrementalPlaceholders: null,
1092
- moduleImportPayloads: null,
1248
+ followupPayloads: null,
1093
1249
  source: RelayRecordSource.create(),
1094
1250
  isFinal: false
1095
1251
  };
1096
1252
 
1097
- this._publishQueue.commitPayload(this._operation, handleFieldsRelayPayload);
1253
+ this._getPublishQueueAndSaveActor().commitPayload(this._operation, handleFieldsRelayPayload);
1098
1254
  }
1099
1255
 
1256
+ this._actorIdentifier = prevActorIdentifier;
1100
1257
  return relayPayload;
1101
1258
  };
1102
1259
 
@@ -1104,34 +1261,34 @@ var Executor = /*#__PURE__*/function () {
1104
1261
  var _field$alias, _field$concreteType, _this$_getDataID;
1105
1262
 
1106
1263
  var data = response.data;
1107
- !(typeof data === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected the GraphQL @stream payload `data` ' + 'value to be an object.') : invariant(false) : void 0;
1264
+ !(typeof data === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected the GraphQL @stream payload `data` ' + 'value to be an object.') : invariant(false) : void 0;
1108
1265
  var responseKey = (_field$alias = field.alias) !== null && _field$alias !== void 0 ? _field$alias : field.name;
1109
1266
  var storageKey = getStorageKey(field, variables); // Load the version of the parent record from which this incremental data
1110
1267
  // was derived
1111
1268
 
1112
1269
  var parentEntry = this._source.get(parentID);
1113
1270
 
1114
- !(parentEntry != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected the parent record `%s` for @stream ' + 'data to exist.', parentID) : invariant(false) : void 0;
1271
+ !(parentEntry != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected the parent record `%s` for @stream ' + 'data to exist.', parentID) : invariant(false) : void 0;
1115
1272
  var parentRecord = parentEntry.record,
1116
1273
  fieldPayloads = parentEntry.fieldPayloads; // Load the field value (items) that were created by *this* query executor
1117
1274
  // in order to check if there has been any concurrent modifications by some
1118
1275
  // other operation.
1119
1276
 
1120
1277
  var prevIDs = RelayModernRecord.getLinkedRecordIDs(parentRecord, storageKey);
1121
- !(prevIDs != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected record `%s` to have fetched field ' + '`%s` with @stream.', parentID, field.name) : invariant(false) : void 0; // Determine the index in the field of the new item
1278
+ !(prevIDs != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected record `%s` to have fetched field ' + '`%s` with @stream.', parentID, field.name) : invariant(false) : void 0; // Determine the index in the field of the new item
1122
1279
 
1123
1280
  var finalPathEntry = path[path.length - 1];
1124
1281
  var itemIndex = parseInt(finalPathEntry, 10);
1125
- !(itemIndex === finalPathEntry && itemIndex >= 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected path for @stream to end in a ' + 'positive integer index, got `%s`', finalPathEntry) : invariant(false) : void 0;
1282
+ !(itemIndex === finalPathEntry && itemIndex >= 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected path for @stream to end in a ' + 'positive integer index, got `%s`', finalPathEntry) : invariant(false) : void 0;
1126
1283
  var typeName = (_field$concreteType = field.concreteType) !== null && _field$concreteType !== void 0 ? _field$concreteType : data[TYPENAME_KEY];
1127
- !(typeof typeName === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected @stream field `%s` to have a ' + '__typename.', field.name) : invariant(false) : void 0; // Determine the __id of the new item: this must equal the value that would
1284
+ !(typeof typeName === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected @stream field `%s` to have a ' + '__typename.', field.name) : invariant(false) : void 0; // Determine the __id of the new item: this must equal the value that would
1128
1285
  // be assigned had the item not been streamed
1129
1286
 
1130
1287
  var itemID = // https://github.com/prettier/prettier/issues/6403
1131
1288
  // prettier-ignore
1132
1289
  ((_this$_getDataID = this._getDataID(data, typeName)) !== null && _this$_getDataID !== void 0 ? _this$_getDataID : prevIDs && prevIDs[itemIndex]) || // Reuse previously generated client IDs
1133
1290
  generateClientID(parentID, storageKey, itemIndex);
1134
- !(typeof itemID === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected id of elements of field `%s` to ' + 'be strings.', storageKey) : invariant(false) : void 0; // Build a selector to normalize the item data with
1291
+ !(typeof itemID === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected id of elements of field `%s` to ' + 'be strings.', storageKey) : invariant(false) : void 0; // Build a selector to normalize the item data with
1135
1292
 
1136
1293
  var selector = createNormalizationSelector(field, itemID, variables); // Update the cached version of the parent record to reflect the new item:
1137
1294
  // this is used when subsequent stream payloads arrive to see if there
@@ -1148,9 +1305,10 @@ var Executor = /*#__PURE__*/function () {
1148
1305
  });
1149
1306
 
1150
1307
  var relayPayload = normalizeResponse(response, selector, typeName, {
1308
+ actorIdentifier: this._actorIdentifier,
1151
1309
  getDataID: this._getDataID,
1152
1310
  path: [].concat((0, _toConsumableArray2["default"])(normalizationPath), [responseKey, String(itemIndex)]),
1153
- reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
1311
+ reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer != null ? this._deserializeReactFlightPayloadWithLogging : null,
1154
1312
  reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
1155
1313
  treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
1156
1314
  shouldProcessClientComponents: this._shouldProcessClientComponents
@@ -1165,6 +1323,40 @@ var Executor = /*#__PURE__*/function () {
1165
1323
  };
1166
1324
  };
1167
1325
 
1326
+ _proto._scheduleAsyncStoreUpdate = function _scheduleAsyncStoreUpdate(scheduleFn, completeFn) {
1327
+ var _this12 = this;
1328
+
1329
+ this._completeFns.push(completeFn);
1330
+
1331
+ if (this._asyncStoreUpdateDisposable != null) {
1332
+ return;
1333
+ }
1334
+
1335
+ this._asyncStoreUpdateDisposable = scheduleFn(function () {
1336
+ _this12._asyncStoreUpdateDisposable = null;
1337
+
1338
+ var updatedOwners = _this12._runPublishQueue();
1339
+
1340
+ _this12._updateOperationTracker(updatedOwners);
1341
+
1342
+ var _iterator2 = (0, _createForOfIteratorHelper2["default"])(_this12._completeFns),
1343
+ _step2;
1344
+
1345
+ try {
1346
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1347
+ var complete = _step2.value;
1348
+ complete();
1349
+ }
1350
+ } catch (err) {
1351
+ _iterator2.e(err);
1352
+ } finally {
1353
+ _iterator2.f();
1354
+ }
1355
+
1356
+ _this12._completeFns = [];
1357
+ });
1358
+ };
1359
+
1168
1360
  _proto._updateOperationTracker = function _updateOperationTracker(updatedOwners) {
1169
1361
  if (updatedOwners != null && updatedOwners.length > 0) {
1170
1362
  this._operationTracker.update(this._operation.request, new Set(updatedOwners));
@@ -1175,6 +1367,88 @@ var Executor = /*#__PURE__*/function () {
1175
1367
  this._operationTracker.complete(this._operation.request);
1176
1368
  };
1177
1369
 
1370
+ _proto._getPublishQueueAndSaveActor = function _getPublishQueueAndSaveActor() {
1371
+ this._seenActors.add(this._actorIdentifier);
1372
+
1373
+ return this._getPublishQueue(this._actorIdentifier);
1374
+ };
1375
+
1376
+ _proto._getActorsToVisit = function _getActorsToVisit() {
1377
+ if (this._seenActors.size === 0) {
1378
+ return new Set([this._actorIdentifier]);
1379
+ } else {
1380
+ return this._seenActors;
1381
+ }
1382
+ };
1383
+
1384
+ _proto._runPublishQueue = function _runPublishQueue(operation) {
1385
+ var updatedOwners = new Set();
1386
+
1387
+ var _iterator3 = (0, _createForOfIteratorHelper2["default"])(this._getActorsToVisit()),
1388
+ _step3;
1389
+
1390
+ try {
1391
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1392
+ var _actorIdentifier = _step3.value;
1393
+
1394
+ var owners = this._getPublishQueue(_actorIdentifier).run(operation);
1395
+
1396
+ owners.forEach(function (owner) {
1397
+ return updatedOwners.add(owner);
1398
+ });
1399
+ }
1400
+ } catch (err) {
1401
+ _iterator3.e(err);
1402
+ } finally {
1403
+ _iterator3.f();
1404
+ }
1405
+
1406
+ return Array.from(updatedOwners);
1407
+ };
1408
+
1409
+ _proto._retainData = function _retainData() {
1410
+ var _iterator4 = (0, _createForOfIteratorHelper2["default"])(this._getActorsToVisit()),
1411
+ _step4;
1412
+
1413
+ try {
1414
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1415
+ var _actorIdentifier2 = _step4.value;
1416
+
1417
+ if (!this._retainDisposables.has(_actorIdentifier2)) {
1418
+ this._retainDisposables.set(_actorIdentifier2, this._getStore(_actorIdentifier2).retain(this._operation));
1419
+ }
1420
+ }
1421
+ } catch (err) {
1422
+ _iterator4.e(err);
1423
+ } finally {
1424
+ _iterator4.f();
1425
+ }
1426
+ };
1427
+
1428
+ _proto._disposeRetainedData = function _disposeRetainedData() {
1429
+ var _iterator5 = (0, _createForOfIteratorHelper2["default"])(this._retainDisposables.values()),
1430
+ _step5;
1431
+
1432
+ try {
1433
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1434
+ var disposable = _step5.value;
1435
+ disposable.dispose();
1436
+ }
1437
+ } catch (err) {
1438
+ _iterator5.e(err);
1439
+ } finally {
1440
+ _iterator5.f();
1441
+ }
1442
+
1443
+ this._retainDisposables.clear();
1444
+ };
1445
+
1446
+ _proto._expectOperationLoader = function _expectOperationLoader() {
1447
+ var operationLoader = this._operationLoader;
1448
+ !operationLoader ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: Expected an operationLoader to be ' + 'configured when using `@match`.') : invariant(false) : void 0;
1449
+ return operationLoader;
1450
+ };
1451
+
1178
1452
  return Executor;
1179
1453
  }();
1180
1454