relay-runtime 10.1.3 → 11.0.2

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 (106) hide show
  1. package/handlers/connection/ConnectionHandler.js.flow +60 -0
  2. package/handlers/connection/MutationHandlers.js.flow +28 -0
  3. package/index.js +1 -1
  4. package/index.js.flow +9 -3
  5. package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
  6. package/lib/handlers/connection/ConnectionHandler.js +68 -6
  7. package/lib/handlers/connection/MutationHandlers.js +67 -8
  8. package/lib/index.js +3 -0
  9. package/lib/multi-actor-environment/ActorIdentifier.js +23 -0
  10. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +108 -0
  11. package/lib/multi-actor-environment/MultiActorEnvironment.js +156 -0
  12. package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
  13. package/lib/multi-actor-environment/index.js +17 -0
  14. package/lib/mutations/RelayRecordProxy.js +1 -1
  15. package/lib/mutations/RelayRecordSourceMutator.js +1 -1
  16. package/lib/mutations/RelayRecordSourceProxy.js +1 -1
  17. package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -1
  18. package/lib/mutations/applyOptimisticMutation.js +1 -1
  19. package/lib/mutations/commitMutation.js +1 -1
  20. package/lib/mutations/validateMutation.js +36 -15
  21. package/lib/network/RelayNetwork.js +1 -1
  22. package/lib/network/RelayQueryResponseCache.js +3 -2
  23. package/lib/query/GraphQLTag.js +1 -1
  24. package/lib/query/fetchQuery.js +129 -13
  25. package/lib/query/fetchQueryInternal.js +3 -4
  26. package/lib/query/fetchQuery_DEPRECATED.js +39 -0
  27. package/lib/store/DataChecker.js +26 -14
  28. package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +117 -47
  29. package/lib/store/RelayConcreteVariables.js +8 -4
  30. package/lib/store/RelayModernEnvironment.js +105 -136
  31. package/lib/store/RelayModernFragmentSpecResolver.js +16 -9
  32. package/lib/store/RelayModernRecord.js +1 -1
  33. package/lib/store/RelayModernSelector.js +1 -1
  34. package/lib/store/RelayModernStore.js +19 -20
  35. package/lib/store/RelayOperationTracker.js +55 -49
  36. package/lib/store/RelayPublishQueue.js +9 -5
  37. package/lib/store/RelayReader.js +68 -14
  38. package/lib/store/RelayReferenceMarker.js +28 -14
  39. package/lib/store/RelayResponseNormalizer.js +109 -15
  40. package/lib/store/RelayStoreReactFlightUtils.js +6 -4
  41. package/lib/store/RelayStoreSubscriptions.js +18 -8
  42. package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +90 -30
  43. package/lib/store/RelayStoreUtils.js +3 -2
  44. package/lib/store/ResolverFragments.js +57 -0
  45. package/lib/store/cloneRelayHandleSourceField.js +1 -1
  46. package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
  47. package/lib/store/createFragmentSpecResolver.js +2 -2
  48. package/lib/store/createRelayContext.js +1 -1
  49. package/lib/store/defaultGetDataID.js +3 -1
  50. package/lib/store/hasOverlappingIDs.js +11 -3
  51. package/lib/store/readInlineData.js +1 -1
  52. package/lib/subscription/requestSubscription.js +33 -5
  53. package/lib/util/RelayConcreteNode.js +2 -0
  54. package/lib/util/RelayFeatureFlags.js +8 -3
  55. package/lib/util/RelayProfiler.js +17 -187
  56. package/lib/util/RelayReplaySubject.js +1 -1
  57. package/lib/util/deepFreeze.js +1 -0
  58. package/lib/util/getRelayHandleKey.js +1 -1
  59. package/lib/util/getRequestIdentifier.js +1 -1
  60. package/multi-actor-environment/ActorIdentifier.js.flow +27 -0
  61. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +189 -0
  62. package/multi-actor-environment/MultiActorEnvironment.js.flow +233 -0
  63. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +196 -0
  64. package/multi-actor-environment/index.js.flow +24 -0
  65. package/mutations/RelayRecordSourceProxy.js.flow +3 -2
  66. package/mutations/commitMutation.js.flow +1 -1
  67. package/mutations/validateMutation.js.flow +40 -15
  68. package/network/RelayNetworkTypes.js.flow +31 -11
  69. package/network/RelayQueryResponseCache.js.flow +2 -1
  70. package/package.json +3 -2
  71. package/query/fetchQuery.js.flow +147 -20
  72. package/query/fetchQueryInternal.js.flow +2 -3
  73. package/query/fetchQuery_DEPRECATED.js.flow +47 -0
  74. package/relay-runtime.js +2 -2
  75. package/relay-runtime.min.js +2 -2
  76. package/store/DataChecker.js.flow +23 -15
  77. package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +128 -40
  78. package/store/RelayConcreteVariables.js.flow +5 -0
  79. package/store/RelayModernEnvironment.js.flow +100 -130
  80. package/store/RelayModernFragmentSpecResolver.js.flow +30 -8
  81. package/store/RelayModernStore.js.flow +28 -24
  82. package/store/RelayOperationTracker.js.flow +69 -56
  83. package/store/RelayPublishQueue.js.flow +7 -4
  84. package/store/RelayReader.js.flow +63 -11
  85. package/store/RelayRecordSource.js.flow +3 -3
  86. package/store/RelayRecordSourceMapImpl.js.flow +6 -2
  87. package/store/RelayReferenceMarker.js.flow +28 -18
  88. package/store/RelayResponseNormalizer.js.flow +134 -23
  89. package/store/RelayStoreReactFlightUtils.js.flow +9 -4
  90. package/store/RelayStoreSubscriptions.js.flow +22 -7
  91. package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +36 -12
  92. package/store/RelayStoreTypes.js.flow +51 -22
  93. package/store/RelayStoreUtils.js.flow +2 -1
  94. package/store/ResolverFragments.js.flow +125 -0
  95. package/store/createFragmentSpecResolver.js.flow +2 -0
  96. package/store/defaultGetDataID.js.flow +3 -1
  97. package/store/hasOverlappingIDs.js.flow +11 -9
  98. package/subscription/requestSubscription.js.flow +25 -2
  99. package/util/NormalizationNode.js.flow +13 -0
  100. package/util/ReaderNode.js.flow +14 -1
  101. package/util/RelayConcreteNode.js.flow +2 -0
  102. package/util/RelayFeatureFlags.js.flow +12 -2
  103. package/util/RelayProfiler.js.flow +22 -194
  104. package/util/RelayRuntimeTypes.js.flow +4 -5
  105. package/util/deepFreeze.js.flow +2 -1
  106. package/util/isEmptyObject.js.flow +1 -1
@@ -14,7 +14,7 @@ var Observable = require('../network/RelayObservable');
14
14
 
15
15
  var RelayReplaySubject = require('../util/RelayReplaySubject');
16
16
 
17
- var invariant = require("fbjs/lib/invariant");
17
+ var invariant = require('invariant');
18
18
 
19
19
  var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
20
20
  var requestCachesByEnvironment = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
@@ -71,8 +71,7 @@ var requestCachesByEnvironment = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
71
71
  * Cancelling requests:
72
72
  * ====================
73
73
  * If the subscription returned by subscribe is called while the
74
- * request is in-flight, apart from releasing retained data, the request will
75
- * also be cancelled.
74
+ * request is in-flight, the request will be cancelled.
76
75
  *
77
76
  * ```
78
77
  * const subscription = fetchQuery(...).subscribe(...);
@@ -193,7 +192,7 @@ function getActiveStatusObservableForCachedRequest(environment, requestCache, ca
193
192
  }
194
193
  /**
195
194
  * If a request is active for the given query, variables and environment,
196
- * this function will return a Promise that will resolve when that request has
195
+ * this function will return a Promise that will resolve when that request
197
196
  * stops being active (receives a final payload), and the data has been saved
198
197
  * to the store.
199
198
  * If no request is active, null will be returned
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+ // flowlint ambiguous-object-type:error
11
+ 'use strict';
12
+
13
+ var _require = require('../store/RelayModernOperationDescriptor'),
14
+ createOperationDescriptor = _require.createOperationDescriptor;
15
+
16
+ var _require2 = require('./GraphQLTag'),
17
+ getRequest = _require2.getRequest;
18
+
19
+ /**
20
+ * A helper function to fetch the results of a query. Note that results for
21
+ * fragment spreads are masked: fields must be explicitly listed in the query in
22
+ * order to be accessible in the result object.
23
+ */
24
+ function fetchQuery_DEPRECATED(environment, taggedNode, variables, cacheConfig) {
25
+ var query = getRequest(taggedNode);
26
+
27
+ if (query.params.operationKind !== 'query') {
28
+ throw new Error('fetchQuery: Expected query operation');
29
+ }
30
+
31
+ var operation = createOperationDescriptor(query, variables, cacheConfig);
32
+ return environment.execute({
33
+ operation: operation
34
+ }).map(function () {
35
+ return environment.lookup(operation.fragment).data;
36
+ }).toPromise();
37
+ }
38
+
39
+ module.exports = fetchQuery_DEPRECATED;
@@ -35,7 +35,7 @@ var cloneRelayScalarHandleSourceField = require('./cloneRelayScalarHandleSourceF
35
35
 
36
36
  var getOperation = require('../util/getOperation');
37
37
 
38
- var invariant = require("fbjs/lib/invariant");
38
+ var invariant = require('invariant');
39
39
 
40
40
  var _require = require('./ClientID'),
41
41
  isClientID = _require.isClientID;
@@ -48,6 +48,7 @@ var _require3 = require('./TypeID'),
48
48
  generateTypeID = _require3.generateTypeID;
49
49
 
50
50
  var CONDITION = RelayConcreteNode.CONDITION,
51
+ CLIENT_COMPONENT = RelayConcreteNode.CLIENT_COMPONENT,
51
52
  CLIENT_EXTENSION = RelayConcreteNode.CLIENT_EXTENSION,
52
53
  DEFER = RelayConcreteNode.DEFER,
53
54
  FLIGHT_FIELD = RelayConcreteNode.FLIGHT_FIELD,
@@ -75,11 +76,11 @@ var ROOT_ID = RelayStoreUtils.ROOT_ID,
75
76
  * If all records are present, returns `true`, otherwise `false`.
76
77
  */
77
78
 
78
- function check(source, target, selector, handlers, operationLoader, getDataID) {
79
+ function check(source, target, selector, handlers, operationLoader, getDataID, shouldProcessClientComponents) {
79
80
  var dataID = selector.dataID,
80
81
  node = selector.node,
81
82
  variables = selector.variables;
82
- var checker = new DataChecker(source, target, variables, handlers, operationLoader, getDataID);
83
+ var checker = new DataChecker(source, target, variables, handlers, operationLoader, getDataID, shouldProcessClientComponents);
83
84
  return checker.check(node, dataID);
84
85
  }
85
86
  /**
@@ -88,7 +89,7 @@ function check(source, target, selector, handlers, operationLoader, getDataID) {
88
89
 
89
90
 
90
91
  var DataChecker = /*#__PURE__*/function () {
91
- function DataChecker(source, target, variables, handlers, operationLoader, getDataID) {
92
+ function DataChecker(source, target, variables, handlers, operationLoader, getDataID, shouldProcessClientComponents) {
92
93
  var mutator = new RelayRecordSourceMutator(source, target);
93
94
  this._mostRecentlyInvalidatedAt = null;
94
95
  this._handlers = handlers;
@@ -98,6 +99,7 @@ var DataChecker = /*#__PURE__*/function () {
98
99
  this._recordWasMissing = false;
99
100
  this._source = source;
100
101
  this._variables = variables;
102
+ this._shouldProcessClientComponents = shouldProcessClientComponents;
101
103
  }
102
104
 
103
105
  var _proto = DataChecker.prototype;
@@ -115,7 +117,8 @@ var DataChecker = /*#__PURE__*/function () {
115
117
  };
116
118
 
117
119
  _proto._getVariableValue = function _getVariableValue(name) {
118
- !this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayAsyncLoader(): Undefined variable `%s`.', name) : invariant(false) : void 0;
120
+ !this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayAsyncLoader(): Undefined variable `%s`.', name) : invariant(false) : void 0; // $FlowFixMe[cannot-write]
121
+
119
122
  return this._variables[name];
120
123
  };
121
124
 
@@ -365,7 +368,7 @@ var DataChecker = /*#__PURE__*/function () {
365
368
  // $FlowFixMe[incompatible-type]
366
369
 
367
370
  case FRAGMENT_SPREAD:
368
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayAsyncLoader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0; // $FlowExpectedError[unreachable-code] - we need the break; for OSS linter
371
+ _this2._traverseSelections(selection.fragment.selections, dataID);
369
372
 
370
373
  break;
371
374
 
@@ -408,6 +411,15 @@ var DataChecker = /*#__PURE__*/function () {
408
411
 
409
412
  break;
410
413
 
414
+ case CLIENT_COMPONENT:
415
+ if (_this2._shouldProcessClientComponents === false) {
416
+ break;
417
+ }
418
+
419
+ _this2._traverseSelections(selection.fragment.selections, dataID);
420
+
421
+ break;
422
+
411
423
  default:
412
424
  selection;
413
425
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayAsyncLoader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
@@ -520,28 +532,28 @@ var DataChecker = /*#__PURE__*/function () {
520
532
 
521
533
  var tree = this._mutator.getValue(linkedID, RelayStoreReactFlightUtils.REACT_FLIGHT_TREE_STORAGE_KEY);
522
534
 
523
- var reachableQueries = this._mutator.getValue(linkedID, RelayStoreReactFlightUtils.REACT_FLIGHT_QUERIES_STORAGE_KEY);
535
+ var reachableExecutableDefinitions = this._mutator.getValue(linkedID, RelayStoreReactFlightUtils.REACT_FLIGHT_EXECUTABLE_DEFINITIONS_STORAGE_KEY);
524
536
 
525
- if (tree == null || !Array.isArray(reachableQueries)) {
537
+ if (tree == null || !Array.isArray(reachableExecutableDefinitions)) {
526
538
  this._handleMissing();
527
539
 
528
540
  return;
529
541
  }
530
542
 
531
543
  var operationLoader = this._operationLoader;
532
- !(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DataChecker: Expected an operationLoader to be configured when using ' + 'React Flight.') : invariant(false) : void 0; // In Flight, the variables that are in scope for reachable queries aren't
533
- // the same as what's in scope for the outer query.
544
+ !(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DataChecker: Expected an operationLoader to be configured when using ' + 'React Flight.') : invariant(false) : void 0; // In Flight, the variables that are in scope for reachable executable
545
+ // definitions aren't the same as what's in scope for the outer query.
534
546
 
535
547
  var prevVariables = this._variables; // $FlowFixMe[incompatible-cast]
536
548
 
537
- var _iterator4 = (0, _createForOfIteratorHelper2["default"])(reachableQueries),
549
+ var _iterator4 = (0, _createForOfIteratorHelper2["default"])(reachableExecutableDefinitions),
538
550
  _step4;
539
551
 
540
552
  try {
541
553
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
542
- var query = _step4.value;
543
- this._variables = query.variables;
544
- var normalizationRootNode = operationLoader.get(query.module);
554
+ var definition = _step4.value;
555
+ this._variables = definition.variables;
556
+ var normalizationRootNode = operationLoader.get(definition.module);
545
557
 
546
558
  if (normalizationRootNode != null) {
547
559
  var operation = getOperation(normalizationRootNode);
@@ -21,6 +21,8 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
21
21
 
22
22
  var RelayError = require('../util/RelayError');
23
23
 
24
+ var RelayFeatureFlags = require('../util/RelayFeatureFlags');
25
+
24
26
  var RelayModernRecord = require('./RelayModernRecord');
25
27
 
26
28
  var RelayObservable = require('../network/RelayObservable');
@@ -31,17 +33,19 @@ var RelayResponseNormalizer = require('./RelayResponseNormalizer');
31
33
 
32
34
  var getOperation = require('../util/getOperation');
33
35
 
34
- var invariant = require("fbjs/lib/invariant");
36
+ var invariant = require('invariant');
35
37
 
36
38
  var stableCopy = require('../util/stableCopy');
37
39
 
38
40
  var warning = require("fbjs/lib/warning");
39
41
 
40
42
  var _require = require('./ClientID'),
41
- generateClientID = _require.generateClientID;
43
+ generateClientID = _require.generateClientID,
44
+ generateUniqueClientID = _require.generateUniqueClientID;
42
45
 
43
46
  var _require2 = require('./RelayModernSelector'),
44
- createNormalizationSelector = _require2.createNormalizationSelector;
47
+ createNormalizationSelector = _require2.createNormalizationSelector,
48
+ createReaderSelector = _require2.createReaderSelector;
45
49
 
46
50
  var _require3 = require('./RelayStoreUtils'),
47
51
  ROOT_TYPE = _require3.ROOT_TYPE,
@@ -76,7 +80,9 @@ var Executor = /*#__PURE__*/function () {
76
80
  treatMissingFieldsAsNull = _ref.treatMissingFieldsAsNull,
77
81
  getDataID = _ref.getDataID,
78
82
  isClientPayload = _ref.isClientPayload,
79
- reactFlightPayloadDeserializer = _ref.reactFlightPayloadDeserializer;
83
+ reactFlightPayloadDeserializer = _ref.reactFlightPayloadDeserializer,
84
+ reactFlightServerErrorHandler = _ref.reactFlightServerErrorHandler,
85
+ shouldProcessClientComponents = _ref.shouldProcessClientComponents;
80
86
  this._getDataID = getDataID;
81
87
  this._treatMissingFieldsAsNull = treatMissingFieldsAsNull;
82
88
  this._incrementalPayloadsPending = false;
@@ -99,6 +105,9 @@ var Executor = /*#__PURE__*/function () {
99
105
  this._updater = updater;
100
106
  this._isClientPayload = isClientPayload === true;
101
107
  this._reactFlightPayloadDeserializer = reactFlightPayloadDeserializer;
108
+ this._reactFlightServerErrorHandler = reactFlightServerErrorHandler;
109
+ this._isSubscriptionOperation = this._operation.request.node.params.operationKind === 'subscription';
110
+ this._shouldProcessClientComponents = shouldProcessClientComponents;
102
111
  var id = this._nextSubscriptionId++;
103
112
  source.subscribe({
104
113
  complete: function complete() {
@@ -154,7 +163,7 @@ var Executor = /*#__PURE__*/function () {
154
163
  this._optimisticUpdates = null;
155
164
  optimisticUpdates.forEach(function (update) {
156
165
  return _this2._publishQueue.revertUpdate(update);
157
- });
166
+ }); // OK: run revert on cancel
158
167
 
159
168
  this._publishQueue.run();
160
169
  }
@@ -200,7 +209,7 @@ var Executor = /*#__PURE__*/function () {
200
209
 
201
210
  default:
202
211
  this._state;
203
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernQueryExecutor: invalid executor state.') : invariant(false) : void 0;
212
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: invalid executor state.') : invariant(false) : void 0;
204
213
  }
205
214
 
206
215
  this._operationExecutions.set(this._operation.request.identifier, activeState);
@@ -333,7 +342,7 @@ var Executor = /*#__PURE__*/function () {
333
342
  var isOptimistic = ((_response$extensions = response.extensions) === null || _response$extensions === void 0 ? void 0 : _response$extensions.isOptimistic) === true;
334
343
 
335
344
  if (isOptimistic && this._state !== 'started') {
336
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernQueryExecutor: optimistic payload received after server payload.') : invariant(false) : void 0;
345
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: optimistic payload received after server payload.') : invariant(false) : void 0;
337
346
  }
338
347
 
339
348
  if (isOptimistic) {
@@ -387,7 +396,9 @@ var Executor = /*#__PURE__*/function () {
387
396
 
388
397
  var _partitionGraphQLResp = partitionGraphQLResponses(responsesWithData),
389
398
  nonIncrementalResponses = _partitionGraphQLResp[0],
390
- incrementalResponses = _partitionGraphQLResp[1]; // In theory this doesn't preserve the ordering of the batch.
399
+ incrementalResponses = _partitionGraphQLResp[1];
400
+
401
+ var hasNonIncrementalResponses = nonIncrementalResponses.length > 0; // In theory this doesn't preserve the ordering of the batch.
391
402
  // The idea is that a batch is always:
392
403
  // * at most one non-incremental payload
393
404
  // * followed by zero or more incremental payloads
@@ -395,37 +406,68 @@ var Executor = /*#__PURE__*/function () {
395
406
  // with the initial payload followed by some early-to-resolve incremental
396
407
  // payloads (although, can that even happen?)
397
408
 
409
+ if (hasNonIncrementalResponses) {
410
+ var payloadFollowups = this._processResponses(nonIncrementalResponses);
398
411
 
399
- if (nonIncrementalResponses.length > 0) {
400
- var payloadFollowups = this._processResponses(nonIncrementalResponses); // Please note that we're passing `this._operation` to the publish
401
- // queue here, which will later passed to the store (via notify)
402
- // to indicate that this is an operation that caused the store to update
403
-
404
-
405
- var updatedOwners = this._publishQueue.run(this._operation);
412
+ if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
413
+ var updatedOwners = this._publishQueue.run(this._operation);
406
414
 
407
- this._updateOperationTracker(updatedOwners);
415
+ this._updateOperationTracker(updatedOwners);
416
+ }
408
417
 
409
418
  this._processPayloadFollowups(payloadFollowups);
410
419
 
411
- if (this._incrementalPayloadsPending && !this._retainDisposable) {
412
- this._retainDisposable = this._store.retain(this._operation);
420
+ if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
421
+ if (this._incrementalPayloadsPending && !this._retainDisposable) {
422
+ this._retainDisposable = this._store.retain(this._operation);
423
+ }
413
424
  }
414
425
  }
415
426
 
416
427
  if (incrementalResponses.length > 0) {
417
- var _payloadFollowups = this._processIncrementalResponses(incrementalResponses); // For the incremental case, we're only handling follow-up responses
418
- // for already initiated operation (and we're not passing it to
419
- // the run(...) call)
428
+ var _payloadFollowups = this._processIncrementalResponses(incrementalResponses);
420
429
 
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();
421
435
 
422
- var _updatedOwners = this._publishQueue.run();
423
-
424
- this._updateOperationTracker(_updatedOwners);
436
+ this._updateOperationTracker(_updatedOwners);
437
+ }
425
438
 
426
439
  this._processPayloadFollowups(_payloadFollowups);
427
440
  }
428
441
 
442
+ if (this._isSubscriptionOperation && RelayFeatureFlags.ENABLE_UNIQUE_SUBSCRIPTION_ROOT) {
443
+ // We attach the id to allow the `requestSubscription` to read from the store using
444
+ // the current id in its `onNext` callback
445
+ if (responsesWithData[0].extensions == null) {
446
+ // $FlowFixMe[cannot-write]
447
+ responsesWithData[0].extensions = {
448
+ __relay_subscription_root_id: this._operation.fragment.dataID
449
+ };
450
+ } else {
451
+ responsesWithData[0].extensions.__relay_subscription_root_id = this._operation.fragment.dataID;
452
+ }
453
+ }
454
+
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
+
462
+ if (hasNonIncrementalResponses) {
463
+ if (this._incrementalPayloadsPending && !this._retainDisposable) {
464
+ this._retainDisposable = this._store.retain(this._operation);
465
+ }
466
+ }
467
+
468
+ this._updateOperationTracker(_updatedOwners2);
469
+ }
470
+
429
471
  this._sink.next(response);
430
472
  };
431
473
 
@@ -445,6 +487,8 @@ var Executor = /*#__PURE__*/function () {
445
487
  getDataID: this._getDataID,
446
488
  path: [],
447
489
  reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
490
+ reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
491
+ shouldProcessClientComponents: this._shouldProcessClientComponents,
448
492
  treatMissingFieldsAsNull: treatMissingFieldsAsNull
449
493
  });
450
494
  validateOptimisticResponsePayload(payload);
@@ -473,7 +517,8 @@ var Executor = /*#__PURE__*/function () {
473
517
  this._optimisticUpdates = optimisticUpdates;
474
518
  optimisticUpdates.forEach(function (update) {
475
519
  return _this6._publishQueue.applyUpdate(update);
476
- });
520
+ }); // OK: only called on construction and when receiving an optimistic payload from network,
521
+ // which doesn't fall-through to the regular next() handling
477
522
 
478
523
  this._publishQueue.run();
479
524
  };
@@ -516,7 +561,9 @@ var Executor = /*#__PURE__*/function () {
516
561
  getDataID: this._getDataID,
517
562
  path: moduleImportPayload.path,
518
563
  reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
519
- treatMissingFieldsAsNull: this._treatMissingFieldsAsNull
564
+ reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
565
+ treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
566
+ shouldProcessClientComponents: this._shouldProcessClientComponents
520
567
  });
521
568
  };
522
569
 
@@ -553,11 +600,12 @@ var Executor = /*#__PURE__*/function () {
553
600
  });
554
601
 
555
602
  if (_this7._optimisticUpdates == null) {
556
- process.env.NODE_ENV !== "production" ? warning(false, 'RelayModernQueryExecutor: Unexpected ModuleImport optimistic ' + 'update in operation %s.' + _this7._operation.request.node.params.name) : void 0;
603
+ process.env.NODE_ENV !== "production" ? warning(false, 'OperationExecutor: Unexpected ModuleImport optimistic ' + 'update in operation %s.' + _this7._operation.request.node.params.name) : void 0;
557
604
  } else {
558
605
  var _this$_optimisticUpda;
559
606
 
560
- (_this$_optimisticUpda = _this7._optimisticUpdates).push.apply(_this$_optimisticUpda, (0, _toConsumableArray2["default"])(moduleImportOptimisticUpdates));
607
+ (_this$_optimisticUpda = _this7._optimisticUpdates).push.apply(_this$_optimisticUpda, (0, _toConsumableArray2["default"])(moduleImportOptimisticUpdates)); // OK: always have to run() after an module import resolves async
608
+
561
609
 
562
610
  _this7._publishQueue.run();
563
611
  }
@@ -586,7 +634,9 @@ var Executor = /*#__PURE__*/function () {
586
634
  getDataID: _this8._getDataID,
587
635
  path: [],
588
636
  reactFlightPayloadDeserializer: _this8._reactFlightPayloadDeserializer,
589
- treatMissingFieldsAsNull: _this8._treatMissingFieldsAsNull
637
+ reactFlightServerErrorHandler: _this8._reactFlightServerErrorHandler,
638
+ treatMissingFieldsAsNull: _this8._treatMissingFieldsAsNull,
639
+ shouldProcessClientComponents: _this8._shouldProcessClientComponents
590
640
  });
591
641
 
592
642
  _this8._publishQueue.commitPayload(_this8._operation, relayPayload, _this8._updater);
@@ -652,9 +702,11 @@ var Executor = /*#__PURE__*/function () {
652
702
  });
653
703
 
654
704
  if (relayPayloads.length > 0) {
655
- var updatedOwners = _this9._publishQueue.run();
705
+ if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
706
+ var updatedOwners = _this9._publishQueue.run();
656
707
 
657
- _this9._updateOperationTracker(updatedOwners);
708
+ _this9._updateOperationTracker(updatedOwners);
709
+ }
658
710
 
659
711
  _this9._processPayloadFollowups(relayPayloads);
660
712
  }
@@ -664,15 +716,22 @@ var Executor = /*#__PURE__*/function () {
664
716
  };
665
717
 
666
718
  _proto._maybeCompleteSubscriptionOperationTracking = function _maybeCompleteSubscriptionOperationTracking() {
667
- var isSubscriptionOperation = this._operation.request.node.params.operationKind === 'subscription';
668
-
669
- if (!isSubscriptionOperation) {
719
+ if (!this._isSubscriptionOperation) {
670
720
  return;
671
721
  }
672
722
 
673
723
  if (this._pendingModulePayloadsCount === 0 && this._incrementalPayloadsPending === false) {
674
724
  this._completeOperationTracker();
675
725
  }
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
+ }
676
735
  }
677
736
  /**
678
737
  * Processes a ModuleImportPayload, asynchronously resolving the normalization
@@ -716,7 +775,12 @@ var Executor = /*#__PURE__*/function () {
716
775
  })).map(function (operation) {
717
776
  if (operation != null) {
718
777
  _this10._schedule(function () {
719
- _this10._handleModuleImportPayload(moduleImportPayload, getOperation(operation));
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);
720
784
  });
721
785
  }
722
786
  }).subscribe({
@@ -742,9 +806,11 @@ var Executor = /*#__PURE__*/function () {
742
806
 
743
807
  this._publishQueue.commitPayload(this._operation, relayPayload);
744
808
 
745
- var updatedOwners = this._publishQueue.run();
809
+ if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
810
+ var updatedOwners = this._publishQueue.run();
746
811
 
747
- this._updateOperationTracker(updatedOwners);
812
+ this._updateOperationTracker(updatedOwners);
813
+ }
748
814
 
749
815
  this._processPayloadFollowups([relayPayload]);
750
816
  }
@@ -843,9 +909,11 @@ var Executor = /*#__PURE__*/function () {
843
909
  if (pendingResponses != null) {
844
910
  var payloadFollowups = this._processIncrementalResponses(pendingResponses);
845
911
 
846
- var updatedOwners = this._publishQueue.run();
912
+ if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
913
+ var updatedOwners = this._publishQueue.run();
847
914
 
848
- this._updateOperationTracker(updatedOwners);
915
+ this._updateOperationTracker(updatedOwners);
916
+ }
849
917
 
850
918
  this._processPayloadFollowups(payloadFollowups);
851
919
  }
@@ -929,7 +997,9 @@ var Executor = /*#__PURE__*/function () {
929
997
  getDataID: this._getDataID,
930
998
  path: placeholder.path,
931
999
  reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
932
- treatMissingFieldsAsNull: this._treatMissingFieldsAsNull
1000
+ reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
1001
+ treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
1002
+ shouldProcessClientComponents: this._shouldProcessClientComponents
933
1003
  });
934
1004
 
935
1005
  this._publishQueue.commitPayload(this._operation, relayPayload); // Load the version of the parent record from which this incremental data
@@ -1081,7 +1151,9 @@ var Executor = /*#__PURE__*/function () {
1081
1151
  getDataID: this._getDataID,
1082
1152
  path: [].concat((0, _toConsumableArray2["default"])(normalizationPath), [responseKey, String(itemIndex)]),
1083
1153
  reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
1084
- treatMissingFieldsAsNull: this._treatMissingFieldsAsNull
1154
+ reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
1155
+ treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
1156
+ shouldProcessClientComponents: this._shouldProcessClientComponents
1085
1157
  });
1086
1158
  return {
1087
1159
  fieldPayloads: fieldPayloads,
@@ -1094,15 +1166,13 @@ var Executor = /*#__PURE__*/function () {
1094
1166
  };
1095
1167
 
1096
1168
  _proto._updateOperationTracker = function _updateOperationTracker(updatedOwners) {
1097
- if (this._operationTracker != null && updatedOwners != null && updatedOwners.length > 0) {
1169
+ if (updatedOwners != null && updatedOwners.length > 0) {
1098
1170
  this._operationTracker.update(this._operation.request, new Set(updatedOwners));
1099
1171
  }
1100
1172
  };
1101
1173
 
1102
1174
  _proto._completeOperationTracker = function _completeOperationTracker() {
1103
- if (this._operationTracker != null) {
1104
- this._operationTracker.complete(this._operation.request);
1105
- }
1175
+ this._operationTracker.complete(this._operation.request);
1106
1176
  };
1107
1177
 
1108
1178
  return Executor;
@@ -1117,7 +1187,7 @@ function partitionGraphQLResponses(responses) {
1117
1187
  path = response.path;
1118
1188
 
1119
1189
  if (label == null || path == null) {
1120
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernQueryExecutor: invalid incremental payload, expected ' + '`path` and `label` to either both be null/undefined, or ' + '`path` to be an `Array<string | number>` and `label` to be a ' + '`string`.') : invariant(false) : void 0;
1190
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: invalid incremental payload, expected ' + '`path` and `label` to either both be null/undefined, or ' + '`path` to be an `Array<string | number>` and `label` to be a ' + '`string`.') : invariant(false) : void 0;
1121
1191
  }
1122
1192
 
1123
1193
  incrementalResponses.push({
@@ -1157,7 +1227,7 @@ function validateOptimisticResponsePayload(payload) {
1157
1227
  var incrementalPlaceholders = payload.incrementalPlaceholders;
1158
1228
 
1159
1229
  if (incrementalPlaceholders != null && incrementalPlaceholders.length !== 0) {
1160
- !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernQueryExecutor: optimistic responses cannot be returned ' + 'for operations that use incremental data delivery (@defer, ' + '@stream, and @stream_connection).') : invariant(false) : void 0;
1230
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'OperationExecutor: optimistic responses cannot be returned ' + 'for operations that use incremental data delivery (@defer, ' + '@stream, and @stream_connection).') : invariant(false) : void 0;
1161
1231
  }
1162
1232
  }
1163
1233
 
@@ -14,7 +14,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
14
14
 
15
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
16
 
17
- var invariant = require("fbjs/lib/invariant");
17
+ var invariant = require('invariant');
18
18
 
19
19
  /**
20
20
  * Determines the variables that are in scope for a fragment given the variables
@@ -28,7 +28,8 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
28
28
  fragment.argumentDefinitions.forEach(function (definition) {
29
29
  if (argumentVariables.hasOwnProperty(definition.name)) {
30
30
  return;
31
- }
31
+ } // $FlowFixMe[cannot-spread-interface]
32
+
32
33
 
33
34
  variables = variables || (0, _objectSpread2["default"])({}, argumentVariables);
34
35
 
@@ -48,9 +49,12 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
48
49
  * RelayStoreUtils.getStableVariableValue() that variable keys are all
49
50
  * present.
50
51
  */
52
+ // $FlowFixMe[incompatible-use]
51
53
  variables[definition.name] = undefined;
52
54
  break;
53
- }
55
+ } // $FlowFixMe[incompatible-use]
56
+ // $FlowFixMe[cannot-write]
57
+
54
58
 
55
59
  variables[definition.name] = rootVariables[definition.name];
56
60
  break;
@@ -73,7 +77,7 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
73
77
  function getOperationVariables(operation, variables) {
74
78
  var operationVariables = {};
75
79
  operation.argumentDefinitions.forEach(function (def) {
76
- var value = def.defaultValue;
80
+ var value = def.defaultValue; // $FlowFixMe[cannot-write]
77
81
 
78
82
  if (variables[def.name] != null) {
79
83
  value = variables[def.name];