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.
- package/handlers/connection/ConnectionHandler.js.flow +60 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +9 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +68 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +3 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +23 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +108 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +156 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +17 -0
- package/lib/mutations/RelayRecordProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceMutator.js +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -1
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +1 -1
- package/lib/mutations/validateMutation.js +36 -15
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayQueryResponseCache.js +3 -2
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +129 -13
- package/lib/query/fetchQueryInternal.js +3 -4
- package/lib/query/fetchQuery_DEPRECATED.js +39 -0
- package/lib/store/DataChecker.js +26 -14
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +117 -47
- package/lib/store/RelayConcreteVariables.js +8 -4
- package/lib/store/RelayModernEnvironment.js +105 -136
- package/lib/store/RelayModernFragmentSpecResolver.js +16 -9
- package/lib/store/RelayModernRecord.js +1 -1
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +19 -20
- package/lib/store/RelayOperationTracker.js +55 -49
- package/lib/store/RelayPublishQueue.js +9 -5
- package/lib/store/RelayReader.js +68 -14
- package/lib/store/RelayReferenceMarker.js +28 -14
- package/lib/store/RelayResponseNormalizer.js +109 -15
- package/lib/store/RelayStoreReactFlightUtils.js +6 -4
- package/lib/store/RelayStoreSubscriptions.js +18 -8
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +90 -30
- package/lib/store/RelayStoreUtils.js +3 -2
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createFragmentSpecResolver.js +2 -2
- package/lib/store/createRelayContext.js +1 -1
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/hasOverlappingIDs.js +11 -3
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +33 -5
- package/lib/util/RelayConcreteNode.js +2 -0
- package/lib/util/RelayFeatureFlags.js +8 -3
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +1 -1
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/multi-actor-environment/ActorIdentifier.js.flow +27 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +189 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +233 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +196 -0
- package/multi-actor-environment/index.js.flow +24 -0
- package/mutations/RelayRecordSourceProxy.js.flow +3 -2
- package/mutations/commitMutation.js.flow +1 -1
- package/mutations/validateMutation.js.flow +40 -15
- package/network/RelayNetworkTypes.js.flow +31 -11
- package/network/RelayQueryResponseCache.js.flow +2 -1
- package/package.json +3 -2
- package/query/fetchQuery.js.flow +147 -20
- package/query/fetchQueryInternal.js.flow +2 -3
- package/query/fetchQuery_DEPRECATED.js.flow +47 -0
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/DataChecker.js.flow +23 -15
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +128 -40
- package/store/RelayConcreteVariables.js.flow +5 -0
- package/store/RelayModernEnvironment.js.flow +100 -130
- package/store/RelayModernFragmentSpecResolver.js.flow +30 -8
- package/store/RelayModernStore.js.flow +28 -24
- package/store/RelayOperationTracker.js.flow +69 -56
- package/store/RelayPublishQueue.js.flow +7 -4
- package/store/RelayReader.js.flow +63 -11
- package/store/RelayRecordSource.js.flow +3 -3
- package/store/RelayRecordSourceMapImpl.js.flow +6 -2
- package/store/RelayReferenceMarker.js.flow +28 -18
- package/store/RelayResponseNormalizer.js.flow +134 -23
- package/store/RelayStoreReactFlightUtils.js.flow +9 -4
- package/store/RelayStoreSubscriptions.js.flow +22 -7
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +36 -12
- package/store/RelayStoreTypes.js.flow +51 -22
- package/store/RelayStoreUtils.js.flow +2 -1
- package/store/ResolverFragments.js.flow +125 -0
- package/store/createFragmentSpecResolver.js.flow +2 -0
- package/store/defaultGetDataID.js.flow +3 -1
- package/store/hasOverlappingIDs.js.flow +11 -9
- package/subscription/requestSubscription.js.flow +25 -2
- package/util/NormalizationNode.js.flow +13 -0
- package/util/ReaderNode.js.flow +14 -1
- package/util/RelayConcreteNode.js.flow +2 -0
- package/util/RelayFeatureFlags.js.flow +12 -2
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayRuntimeTypes.js.flow +4 -5
- package/util/deepFreeze.js.flow +2 -1
- 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(
|
|
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,
|
|
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
|
|
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;
|
package/lib/store/DataChecker.js
CHANGED
|
@@ -35,7 +35,7 @@ var cloneRelayScalarHandleSourceField = require('./cloneRelayScalarHandleSourceF
|
|
|
35
35
|
|
|
36
36
|
var getOperation = require('../util/getOperation');
|
|
37
37
|
|
|
38
|
-
var invariant = require(
|
|
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
|
-
|
|
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
|
|
535
|
+
var reachableExecutableDefinitions = this._mutator.getValue(linkedID, RelayStoreReactFlightUtils.REACT_FLIGHT_EXECUTABLE_DEFINITIONS_STORAGE_KEY);
|
|
524
536
|
|
|
525
|
-
if (tree == null || !Array.isArray(
|
|
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
|
|
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"])(
|
|
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
|
|
543
|
-
this._variables =
|
|
544
|
-
var normalizationRootNode = operationLoader.get(
|
|
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(
|
|
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, '
|
|
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, '
|
|
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];
|
|
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
|
-
|
|
400
|
-
|
|
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
|
-
|
|
415
|
+
this._updateOperationTracker(updatedOwners);
|
|
416
|
+
}
|
|
408
417
|
|
|
409
418
|
this._processPayloadFollowups(payloadFollowups);
|
|
410
419
|
|
|
411
|
-
if (
|
|
412
|
-
this.
|
|
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);
|
|
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
|
-
|
|
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
|
-
|
|
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, '
|
|
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
|
-
|
|
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
|
-
|
|
705
|
+
if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
|
|
706
|
+
var updatedOwners = _this9._publishQueue.run();
|
|
656
707
|
|
|
657
|
-
|
|
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
|
-
|
|
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
|
-
|
|
809
|
+
if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
|
|
810
|
+
var updatedOwners = this._publishQueue.run();
|
|
746
811
|
|
|
747
|
-
|
|
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
|
-
|
|
912
|
+
if (!RelayFeatureFlags.ENABLE_BATCHED_STORE_UPDATES) {
|
|
913
|
+
var updatedOwners = this._publishQueue.run();
|
|
847
914
|
|
|
848
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
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, '
|
|
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, '
|
|
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(
|
|
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];
|