relay-runtime 11.0.1 → 13.0.0-rc.1
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/RelayDefaultHandlerProvider.js.flow +2 -2
- package/handlers/connection/ConnectionHandler.js.flow +8 -17
- package/handlers/connection/MutationHandlers.js.flow +7 -11
- package/index.js +1 -1
- package/index.js.flow +60 -36
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +13 -19
- package/lib/handlers/connection/MutationHandlers.js +4 -7
- package/lib/index.js +58 -43
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +152 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +419 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -0
- package/lib/mutations/RelayDeclarativeMutationConfig.js +4 -1
- package/lib/mutations/RelayRecordProxy.js +3 -2
- package/lib/mutations/RelayRecordSourceMutator.js +3 -2
- package/lib/mutations/RelayRecordSourceProxy.js +12 -4
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +18 -5
- package/lib/mutations/applyOptimisticMutation.js +6 -6
- package/lib/mutations/commitMutation.js +14 -10
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +238 -0
- package/lib/mutations/validateMutation.js +10 -5
- package/lib/network/ConvertToExecuteFunction.js +2 -1
- package/lib/network/RelayNetwork.js +3 -2
- package/lib/network/RelayQueryResponseCache.js +21 -5
- package/lib/network/wrapNetworkWithLogObserver.js +79 -0
- package/lib/query/GraphQLTag.js +3 -2
- package/lib/query/fetchQuery.js +6 -5
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +2 -1
- package/lib/store/ClientID.js +7 -1
- package/lib/store/DataChecker.js +123 -54
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +518 -200
- package/lib/store/RelayConcreteVariables.js +26 -8
- package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
- package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
- package/lib/store/RelayModernEnvironment.js +175 -240
- package/lib/store/RelayModernFragmentSpecResolver.js +52 -26
- package/lib/store/RelayModernOperationDescriptor.js +2 -1
- package/lib/store/RelayModernRecord.js +47 -12
- package/lib/store/RelayModernSelector.js +14 -8
- package/lib/store/RelayModernStore.js +56 -28
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +41 -13
- package/lib/store/RelayReader.js +288 -48
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +34 -22
- package/lib/store/RelayResponseNormalizer.js +211 -110
- package/lib/store/RelayStoreReactFlightUtils.js +4 -10
- package/lib/store/RelayStoreSubscriptions.js +14 -9
- package/lib/store/RelayStoreUtils.js +12 -7
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +61 -0
- package/lib/store/cloneRelayHandleSourceField.js +5 -4
- package/lib/store/cloneRelayScalarHandleSourceField.js +5 -4
- package/lib/store/createRelayContext.js +4 -2
- package/lib/store/readInlineData.js +6 -2
- package/lib/subscription/requestSubscription.js +34 -25
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayFeatureFlags.js +10 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/RelayRuntimeTypes.js +0 -6
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/getFragmentIdentifier.js +15 -7
- package/lib/util/getOperation.js +2 -1
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +66 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +2 -2
- package/lib/util/getRequestIdentifier.js +2 -2
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +43 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +225 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +506 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +261 -0
- package/multi-actor-environment/index.js.flow +26 -0
- package/mutations/RelayDeclarativeMutationConfig.js.flow +32 -26
- package/mutations/RelayRecordProxy.js.flow +4 -5
- package/mutations/RelayRecordSourceMutator.js.flow +4 -6
- package/mutations/RelayRecordSourceProxy.js.flow +19 -10
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +22 -7
- package/mutations/applyOptimisticMutation.js.flow +13 -14
- package/mutations/commitLocalUpdate.js.flow +1 -1
- package/mutations/commitMutation.js.flow +35 -46
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +309 -0
- package/mutations/validateMutation.js.flow +26 -16
- package/network/ConvertToExecuteFunction.js.flow +2 -2
- package/network/RelayNetwork.js.flow +4 -5
- package/network/RelayNetworkTypes.js.flow +5 -4
- package/network/RelayObservable.js.flow +1 -1
- package/network/RelayQueryResponseCache.js.flow +34 -21
- package/network/wrapNetworkWithLogObserver.js.flow +100 -0
- package/package.json +3 -2
- package/query/GraphQLTag.js.flow +9 -9
- package/query/PreloadableQueryRegistry.js.flow +2 -1
- package/query/fetchQuery.js.flow +11 -13
- package/query/fetchQueryInternal.js.flow +6 -9
- package/query/fetchQuery_DEPRECATED.js.flow +6 -6
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +14 -3
- package/store/DataChecker.js.flow +141 -59
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +605 -303
- package/store/RelayConcreteVariables.js.flow +27 -8
- package/store/RelayExperimentalGraphResponseHandler.js.flow +124 -0
- package/store/RelayExperimentalGraphResponseTransform.js.flow +475 -0
- package/store/RelayModernEnvironment.js.flow +173 -240
- package/store/RelayModernFragmentSpecResolver.js.flow +55 -31
- package/store/RelayModernOperationDescriptor.js.flow +12 -7
- package/store/RelayModernRecord.js.flow +67 -11
- package/store/RelayModernSelector.js.flow +24 -14
- package/store/RelayModernStore.js.flow +66 -36
- package/store/RelayOperationTracker.js.flow +59 -43
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +79 -34
- package/store/RelayReader.js.flow +351 -73
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +40 -26
- package/store/RelayResponseNormalizer.js.flow +258 -99
- package/store/RelayStoreReactFlightUtils.js.flow +4 -11
- package/store/RelayStoreSubscriptions.js.flow +19 -11
- package/store/RelayStoreTypes.js.flow +209 -43
- package/store/RelayStoreUtils.js.flow +24 -11
- package/store/ResolverCache.js.flow +249 -0
- package/store/ResolverFragments.js.flow +121 -0
- package/store/StoreInspector.js.flow +2 -2
- package/store/TypeID.js.flow +1 -1
- package/store/ViewerPattern.js.flow +2 -2
- package/store/cloneRelayHandleSourceField.js.flow +5 -6
- package/store/cloneRelayScalarHandleSourceField.js.flow +5 -6
- package/store/createFragmentSpecResolver.js.flow +3 -4
- package/store/createRelayContext.js.flow +3 -3
- package/store/normalizeRelayPayload.js.flow +6 -7
- package/store/readInlineData.js.flow +7 -8
- package/subscription/requestSubscription.js.flow +53 -41
- package/util/NormalizationNode.js.flow +10 -3
- package/util/ReaderNode.js.flow +38 -2
- package/util/RelayConcreteNode.js.flow +5 -0
- package/util/RelayFeatureFlags.js.flow +24 -10
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +9 -9
- package/util/RelayRuntimeTypes.js.flow +72 -3
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +3 -3
- package/util/getFragmentIdentifier.js.flow +27 -15
- package/util/getOperation.js.flow +2 -2
- package/util/getPaginationMetadata.js.flow +72 -0
- package/util/getPaginationVariables.js.flow +108 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +79 -0
- package/util/getRelayHandleKey.js.flow +1 -2
- package/util/getRequestIdentifier.js.flow +3 -3
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +1 -0
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/resolveImmediate.js.flow +1 -1
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
/**
|
|
13
|
+
* A unique identifier of the current actor.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
var invariant = require('invariant');
|
|
17
|
+
|
|
18
|
+
var INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE = 'INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE';
|
|
19
|
+
|
|
20
|
+
function assertInternalActorIndentifier(actorIdentifier) {
|
|
21
|
+
!(actorIdentifier === INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected to use only internal version of the `actorIdentifier`. "%s" was provided.', actorIdentifier) : invariant(false) : void 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
assertInternalActorIndentifier: assertInternalActorIndentifier,
|
|
26
|
+
getActorIdentifier: function getActorIdentifier(actorID) {
|
|
27
|
+
return actorID;
|
|
28
|
+
},
|
|
29
|
+
getDefaultActorIdentifier: function getDefaultActorIdentifier() {
|
|
30
|
+
throw new Error('Not Implemented');
|
|
31
|
+
},
|
|
32
|
+
INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE: INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE
|
|
33
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var wrapNetworkWithLogObserver = require('../network/wrapNetworkWithLogObserver');
|
|
14
|
+
|
|
15
|
+
var defaultGetDataID = require('../store/defaultGetDataID');
|
|
16
|
+
|
|
17
|
+
var RelayOperationTracker = require('../store/RelayOperationTracker');
|
|
18
|
+
|
|
19
|
+
var RelayPublishQueue = require('../store/RelayPublishQueue');
|
|
20
|
+
|
|
21
|
+
var registerEnvironmentWithDevTools = require('../util/registerEnvironmentWithDevTools');
|
|
22
|
+
|
|
23
|
+
var ActorSpecificEnvironment = /*#__PURE__*/function () {
|
|
24
|
+
function ActorSpecificEnvironment(config) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
|
|
27
|
+
this.configName = config.configName;
|
|
28
|
+
this.actorIdentifier = config.actorIdentifier;
|
|
29
|
+
this.multiActorEnvironment = config.multiActorEnvironment;
|
|
30
|
+
this.__log = config.logFn;
|
|
31
|
+
this.requiredFieldLogger = config.requiredFieldLogger;
|
|
32
|
+
this._operationTracker = new RelayOperationTracker();
|
|
33
|
+
this._store = config.store;
|
|
34
|
+
this._network = wrapNetworkWithLogObserver(this, config.network);
|
|
35
|
+
this._publishQueue = new RelayPublishQueue(config.store, config.handlerProvider, defaultGetDataID);
|
|
36
|
+
this._defaultRenderPolicy = config.defaultRenderPolicy; // TODO:T92305692 Remove `options` in favor of directly using `actorIdentifier` on the environment
|
|
37
|
+
|
|
38
|
+
this.options = {
|
|
39
|
+
actorID: this.actorIdentifier
|
|
40
|
+
}; // We need to add this here to pass `isRelayModernEnvironment` check
|
|
41
|
+
// $FlowFixMe[prop-missing]
|
|
42
|
+
|
|
43
|
+
this['@@RelayModernEnvironment'] = true;
|
|
44
|
+
|
|
45
|
+
if (process.env.NODE_ENV !== "production") {
|
|
46
|
+
var _require = require('../store/StoreInspector'),
|
|
47
|
+
inspect = _require.inspect;
|
|
48
|
+
|
|
49
|
+
this.DEBUG_inspect = function (dataID) {
|
|
50
|
+
return inspect(_this, dataID);
|
|
51
|
+
};
|
|
52
|
+
} // Register this Relay Environment with Relay DevTools if it exists.
|
|
53
|
+
// Note: this must always be the last step in the constructor.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
registerEnvironmentWithDevTools(this);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var _proto = ActorSpecificEnvironment.prototype;
|
|
60
|
+
|
|
61
|
+
_proto.getPublishQueue = function getPublishQueue() {
|
|
62
|
+
return this._publishQueue;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
_proto.UNSTABLE_getDefaultRenderPolicy = function UNSTABLE_getDefaultRenderPolicy() {
|
|
66
|
+
return this._defaultRenderPolicy;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
_proto.applyMutation = function applyMutation(optimisticConfig) {
|
|
70
|
+
return this.multiActorEnvironment.applyMutation(this, optimisticConfig);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
_proto.applyUpdate = function applyUpdate(optimisticUpdate) {
|
|
74
|
+
return this.multiActorEnvironment.applyUpdate(this, optimisticUpdate);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
_proto.revertUpdate = function revertUpdate(optimisticUpdate) {
|
|
78
|
+
return this.multiActorEnvironment.revertUpdate(this, optimisticUpdate);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
_proto.replaceUpdate = function replaceUpdate(optimisticUpdate, replacementUpdate) {
|
|
82
|
+
return this.multiActorEnvironment.replaceUpdate(this, optimisticUpdate, replacementUpdate);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
_proto.check = function check(operation) {
|
|
86
|
+
return this.multiActorEnvironment.check(this, operation);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
_proto.subscribe = function subscribe(snapshot, callback) {
|
|
90
|
+
return this.multiActorEnvironment.subscribe(this, snapshot, callback);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
_proto.retain = function retain(operation) {
|
|
94
|
+
return this.multiActorEnvironment.retain(this, operation);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
_proto.commitUpdate = function commitUpdate(updater) {
|
|
98
|
+
return this.multiActorEnvironment.commitUpdate(this, updater);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Commit a payload to the environment using the given operation selector.
|
|
102
|
+
*/
|
|
103
|
+
;
|
|
104
|
+
|
|
105
|
+
_proto.commitPayload = function commitPayload(operationDescriptor, payload) {
|
|
106
|
+
return this.multiActorEnvironment.commitPayload(this, operationDescriptor, payload);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
_proto.getNetwork = function getNetwork() {
|
|
110
|
+
return this._network;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
_proto.getStore = function getStore() {
|
|
114
|
+
return this._store;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
_proto.getOperationTracker = function getOperationTracker() {
|
|
118
|
+
return this._operationTracker;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
_proto.lookup = function lookup(selector) {
|
|
122
|
+
return this.multiActorEnvironment.lookup(this, selector);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
_proto.execute = function execute(config) {
|
|
126
|
+
return this.multiActorEnvironment.execute(this, config);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
_proto.executeSubscription = function executeSubscription(config) {
|
|
130
|
+
return this.multiActorEnvironment.executeSubscription(this, config);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
_proto.executeMutation = function executeMutation(options) {
|
|
134
|
+
return this.multiActorEnvironment.executeMutation(this, options);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
_proto.executeWithSource = function executeWithSource(options) {
|
|
138
|
+
return this.multiActorEnvironment.executeWithSource(this, options);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
_proto.isRequestActive = function isRequestActive(requestIdentifier) {
|
|
142
|
+
return this.multiActorEnvironment.isRequestActive(this, requestIdentifier);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
_proto.isServer = function isServer() {
|
|
146
|
+
return this.multiActorEnvironment.isServer();
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return ActorSpecificEnvironment;
|
|
150
|
+
}();
|
|
151
|
+
|
|
152
|
+
module.exports = ActorSpecificEnvironment;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var ACTOR_IDENTIFIER_FIELD_NAME = 'actor_key';
|
|
14
|
+
|
|
15
|
+
var _require = require('./ActorIdentifier'),
|
|
16
|
+
getActorIdentifier = _require.getActorIdentifier;
|
|
17
|
+
|
|
18
|
+
function getActorIdentifierFromPayload(payload) {
|
|
19
|
+
if (payload != null && typeof payload === 'object' && typeof payload[ACTOR_IDENTIFIER_FIELD_NAME] === 'string') {
|
|
20
|
+
return getActorIdentifier(payload[ACTOR_IDENTIFIER_FIELD_NAME]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
ACTOR_IDENTIFIER_FIELD_NAME: ACTOR_IDENTIFIER_FIELD_NAME,
|
|
26
|
+
getActorIdentifierFromPayload: getActorIdentifierFromPayload
|
|
27
|
+
};
|
|
@@ -0,0 +1,419 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
|
+
|
|
15
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
16
|
+
|
|
17
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
18
|
+
|
|
19
|
+
var RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
20
|
+
|
|
21
|
+
var RelayObservable = require('../network/RelayObservable');
|
|
22
|
+
|
|
23
|
+
var defaultGetDataID = require('../store/defaultGetDataID');
|
|
24
|
+
|
|
25
|
+
var defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
|
|
26
|
+
|
|
27
|
+
var OperationExecutor = require('../store/OperationExecutor');
|
|
28
|
+
|
|
29
|
+
var RelayModernStore = require('../store/RelayModernStore');
|
|
30
|
+
|
|
31
|
+
var RelayRecordSource = require('../store/RelayRecordSource');
|
|
32
|
+
|
|
33
|
+
var ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
34
|
+
|
|
35
|
+
var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
36
|
+
function MultiActorEnvironment(config) {
|
|
37
|
+
var _config$getDataID, _config$logFn, _config$requiredField, _config$treatMissingF, _config$isServer, _config$defaultRender;
|
|
38
|
+
|
|
39
|
+
this._actorEnvironments = new Map();
|
|
40
|
+
this._operationLoader = config.operationLoader;
|
|
41
|
+
this._createNetworkForActor = config.createNetworkForActor;
|
|
42
|
+
this._scheduler = config.scheduler;
|
|
43
|
+
this._getDataID = (_config$getDataID = config.getDataID) !== null && _config$getDataID !== void 0 ? _config$getDataID : defaultGetDataID;
|
|
44
|
+
this._handlerProvider = config.handlerProvider ? config.handlerProvider : RelayDefaultHandlerProvider;
|
|
45
|
+
this._logFn = (_config$logFn = config.logFn) !== null && _config$logFn !== void 0 ? _config$logFn : emptyFunction;
|
|
46
|
+
this._operationExecutions = new Map();
|
|
47
|
+
this._requiredFieldLogger = (_config$requiredField = config.requiredFieldLogger) !== null && _config$requiredField !== void 0 ? _config$requiredField : defaultRequiredFieldLogger;
|
|
48
|
+
this._shouldProcessClientComponents = config.shouldProcessClientComponents;
|
|
49
|
+
this._treatMissingFieldsAsNull = (_config$treatMissingF = config.treatMissingFieldsAsNull) !== null && _config$treatMissingF !== void 0 ? _config$treatMissingF : false;
|
|
50
|
+
this._isServer = (_config$isServer = config.isServer) !== null && _config$isServer !== void 0 ? _config$isServer : false;
|
|
51
|
+
this._missingFieldHandlers = config.missingFieldHandlers;
|
|
52
|
+
this._createStoreForActor = config.createStoreForActor;
|
|
53
|
+
this._reactFlightPayloadDeserializer = config.reactFlightPayloadDeserializer;
|
|
54
|
+
this._reactFlightServerErrorHandler = config.reactFlightServerErrorHandler;
|
|
55
|
+
this._createConfigNameForActor = config.createConfigNameForActor;
|
|
56
|
+
this._defaultRenderPolicy = (_config$defaultRender = config.defaultRenderPolicy) !== null && _config$defaultRender !== void 0 ? _config$defaultRender : 'partial';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* This method will create an actor specific environment. It will create a new instance
|
|
60
|
+
* and store it in the internal maps. If will return a memoized version
|
|
61
|
+
* of the environment if we already created one for actor.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
var _proto = MultiActorEnvironment.prototype;
|
|
66
|
+
|
|
67
|
+
_proto.forActor = function forActor(actorIdentifier) {
|
|
68
|
+
var environment = this._actorEnvironments.get(actorIdentifier);
|
|
69
|
+
|
|
70
|
+
if (environment == null) {
|
|
71
|
+
var newEnvironment = new ActorSpecificEnvironment({
|
|
72
|
+
configName: this._createConfigNameForActor ? this._createConfigNameForActor(actorIdentifier) : null,
|
|
73
|
+
actorIdentifier: actorIdentifier,
|
|
74
|
+
multiActorEnvironment: this,
|
|
75
|
+
logFn: this._logFn,
|
|
76
|
+
requiredFieldLogger: this._requiredFieldLogger,
|
|
77
|
+
store: this._createStoreForActor != null ? this._createStoreForActor(actorIdentifier) : new RelayModernStore(RelayRecordSource.create()),
|
|
78
|
+
network: this._createNetworkForActor(actorIdentifier),
|
|
79
|
+
handlerProvider: this._handlerProvider,
|
|
80
|
+
defaultRenderPolicy: this._defaultRenderPolicy
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
this._actorEnvironments.set(actorIdentifier, newEnvironment);
|
|
84
|
+
|
|
85
|
+
return newEnvironment;
|
|
86
|
+
} else {
|
|
87
|
+
return environment;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
_proto.check = function check(actorEnvironment, operation) {
|
|
92
|
+
var _this = this;
|
|
93
|
+
|
|
94
|
+
if (this._missingFieldHandlers == null || this._missingFieldHandlers.length === 0) {
|
|
95
|
+
return actorEnvironment.getStore().check(operation, {
|
|
96
|
+
handlers: [],
|
|
97
|
+
defaultActorIdentifier: actorEnvironment.actorIdentifier,
|
|
98
|
+
getSourceForActor: function getSourceForActor(actorIdentifier) {
|
|
99
|
+
return _this.forActor(actorIdentifier).getStore().getSource();
|
|
100
|
+
},
|
|
101
|
+
getTargetForActor: function getTargetForActor() {
|
|
102
|
+
return RelayRecordSource.create();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return this._checkSelectorAndHandleMissingFields(actorEnvironment, operation, this._missingFieldHandlers);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
_proto._checkSelectorAndHandleMissingFields = function _checkSelectorAndHandleMissingFields(actorEnvironment, operation, handlers) {
|
|
111
|
+
var _this2 = this;
|
|
112
|
+
|
|
113
|
+
var targets = new Map([[actorEnvironment.actorIdentifier, RelayRecordSource.create()]]);
|
|
114
|
+
var result = actorEnvironment.getStore().check(operation, {
|
|
115
|
+
handlers: handlers,
|
|
116
|
+
defaultActorIdentifier: actorEnvironment.actorIdentifier,
|
|
117
|
+
getSourceForActor: function getSourceForActor(actorIdentifier) {
|
|
118
|
+
return _this2.forActor(actorIdentifier).getStore().getSource();
|
|
119
|
+
},
|
|
120
|
+
getTargetForActor: function getTargetForActor(actorIdentifier) {
|
|
121
|
+
var target = targets.get(actorIdentifier);
|
|
122
|
+
|
|
123
|
+
if (target == null) {
|
|
124
|
+
target = RelayRecordSource.create();
|
|
125
|
+
targets.set(actorIdentifier, target);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return target;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(targets),
|
|
133
|
+
_step;
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
var _loop = function _loop() {
|
|
137
|
+
var _step$value = _step.value,
|
|
138
|
+
actorIdentifier = _step$value[0],
|
|
139
|
+
target = _step$value[1];
|
|
140
|
+
|
|
141
|
+
if (target.size() > 0) {
|
|
142
|
+
_this2._scheduleUpdates(function () {
|
|
143
|
+
var publishQueue = _this2.forActor(actorIdentifier).getPublishQueue();
|
|
144
|
+
|
|
145
|
+
publishQueue.commitSource(target);
|
|
146
|
+
publishQueue.run();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
152
|
+
_loop();
|
|
153
|
+
}
|
|
154
|
+
} catch (err) {
|
|
155
|
+
_iterator.e(err);
|
|
156
|
+
} finally {
|
|
157
|
+
_iterator.f();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return result;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
_proto.subscribe = function subscribe(actorEnvironment, snapshot, callback) {
|
|
164
|
+
// TODO: make actor aware
|
|
165
|
+
return actorEnvironment.getStore().subscribe(snapshot, callback);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
_proto.retain = function retain(actorEnvironment, operation) {
|
|
169
|
+
// TODO: make actor aware
|
|
170
|
+
return actorEnvironment.getStore().retain(operation);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
_proto.applyUpdate = function applyUpdate(actorEnvironment, optimisticUpdate) {
|
|
174
|
+
var _this3 = this;
|
|
175
|
+
|
|
176
|
+
var publishQueue = actorEnvironment.getPublishQueue();
|
|
177
|
+
|
|
178
|
+
var dispose = function dispose() {
|
|
179
|
+
_this3._scheduleUpdates(function () {
|
|
180
|
+
publishQueue.revertUpdate(optimisticUpdate);
|
|
181
|
+
publishQueue.run();
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
this._scheduleUpdates(function () {
|
|
186
|
+
publishQueue.applyUpdate(optimisticUpdate);
|
|
187
|
+
publishQueue.run();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
dispose: dispose
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
_proto.revertUpdate = function revertUpdate(actorEnvironment, update) {
|
|
196
|
+
var publishQueue = actorEnvironment.getPublishQueue();
|
|
197
|
+
|
|
198
|
+
this._scheduleUpdates(function () {
|
|
199
|
+
publishQueue.revertUpdate(update);
|
|
200
|
+
publishQueue.run();
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
_proto.replaceUpdate = function replaceUpdate(actorEnvironment, update, replacement) {
|
|
205
|
+
var publishQueue = actorEnvironment.getPublishQueue();
|
|
206
|
+
|
|
207
|
+
this._scheduleUpdates(function () {
|
|
208
|
+
publishQueue.revertUpdate(update);
|
|
209
|
+
publishQueue.applyUpdate(replacement);
|
|
210
|
+
publishQueue.run();
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
_proto.applyMutation = function applyMutation(actorEnvironment, optimisticConfig) {
|
|
215
|
+
var subscription = this._execute(actorEnvironment, {
|
|
216
|
+
createSource: function createSource() {
|
|
217
|
+
return RelayObservable.create(function (_sink) {});
|
|
218
|
+
},
|
|
219
|
+
isClientPayload: false,
|
|
220
|
+
operation: optimisticConfig.operation,
|
|
221
|
+
optimisticConfig: optimisticConfig,
|
|
222
|
+
updater: null
|
|
223
|
+
}).subscribe({});
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
dispose: function dispose() {
|
|
227
|
+
return subscription.unsubscribe();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
_proto.commitUpdate = function commitUpdate(actorEnvironment, updater) {
|
|
233
|
+
var publishQueue = actorEnvironment.getPublishQueue();
|
|
234
|
+
|
|
235
|
+
this._scheduleUpdates(function () {
|
|
236
|
+
publishQueue.commitUpdate(updater);
|
|
237
|
+
publishQueue.run();
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
_proto.commitPayload = function commitPayload(actorEnvironment, operationDescriptor, payload) {
|
|
242
|
+
this._execute(actorEnvironment, {
|
|
243
|
+
createSource: function createSource() {
|
|
244
|
+
return RelayObservable.from({
|
|
245
|
+
data: payload
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
isClientPayload: true,
|
|
249
|
+
operation: operationDescriptor,
|
|
250
|
+
optimisticConfig: null,
|
|
251
|
+
updater: null
|
|
252
|
+
}).subscribe({});
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
_proto.lookup = function lookup(actorEnvironment, selector) {
|
|
256
|
+
// TODO: make actor aware
|
|
257
|
+
return actorEnvironment.getStore().lookup(selector);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
_proto.execute = function execute(actorEnvironment, _ref) {
|
|
261
|
+
var operation = _ref.operation;
|
|
262
|
+
return this._execute(actorEnvironment, {
|
|
263
|
+
createSource: function createSource() {
|
|
264
|
+
return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
|
|
265
|
+
},
|
|
266
|
+
isClientPayload: false,
|
|
267
|
+
operation: operation,
|
|
268
|
+
optimisticConfig: null,
|
|
269
|
+
updater: null
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
_proto.executeSubscription = function executeSubscription(actorEnvironment, _ref2) {
|
|
274
|
+
var operation = _ref2.operation,
|
|
275
|
+
updater = _ref2.updater;
|
|
276
|
+
return this._execute(actorEnvironment, {
|
|
277
|
+
createSource: function createSource() {
|
|
278
|
+
return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
|
|
279
|
+
},
|
|
280
|
+
isClientPayload: false,
|
|
281
|
+
operation: operation,
|
|
282
|
+
optimisticConfig: null,
|
|
283
|
+
updater: updater
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
_proto.executeMutation = function executeMutation(actorEnvironment, _ref3) {
|
|
288
|
+
var operation = _ref3.operation,
|
|
289
|
+
optimisticResponse = _ref3.optimisticResponse,
|
|
290
|
+
optimisticUpdater = _ref3.optimisticUpdater,
|
|
291
|
+
updater = _ref3.updater,
|
|
292
|
+
uploadables = _ref3.uploadables;
|
|
293
|
+
var optimisticConfig;
|
|
294
|
+
|
|
295
|
+
if (optimisticResponse || optimisticUpdater) {
|
|
296
|
+
optimisticConfig = {
|
|
297
|
+
operation: operation,
|
|
298
|
+
response: optimisticResponse,
|
|
299
|
+
updater: optimisticUpdater
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return this._execute(actorEnvironment, {
|
|
304
|
+
createSource: function createSource() {
|
|
305
|
+
return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, operation.request.cacheConfig), {}, {
|
|
306
|
+
force: true
|
|
307
|
+
}), uploadables);
|
|
308
|
+
},
|
|
309
|
+
isClientPayload: false,
|
|
310
|
+
operation: operation,
|
|
311
|
+
optimisticConfig: optimisticConfig,
|
|
312
|
+
updater: updater
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
_proto.executeWithSource = function executeWithSource(actorEnvironment, config) {
|
|
317
|
+
return this._execute(actorEnvironment, {
|
|
318
|
+
createSource: function createSource() {
|
|
319
|
+
return config.source;
|
|
320
|
+
},
|
|
321
|
+
isClientPayload: false,
|
|
322
|
+
operation: config.operation,
|
|
323
|
+
optimisticConfig: null,
|
|
324
|
+
updater: null
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
_proto.isRequestActive = function isRequestActive(_actorEnvironment, requestIdentifier) {
|
|
329
|
+
var activeState = this._operationExecutions.get(requestIdentifier);
|
|
330
|
+
|
|
331
|
+
return activeState === 'active';
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
_proto.isServer = function isServer() {
|
|
335
|
+
return this._isServer;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
_proto._execute = function _execute(actorEnvironment, _ref4) {
|
|
339
|
+
var _this4 = this;
|
|
340
|
+
|
|
341
|
+
var createSource = _ref4.createSource,
|
|
342
|
+
isClientPayload = _ref4.isClientPayload,
|
|
343
|
+
operation = _ref4.operation,
|
|
344
|
+
optimisticConfig = _ref4.optimisticConfig,
|
|
345
|
+
updater = _ref4.updater;
|
|
346
|
+
return RelayObservable.create(function (sink) {
|
|
347
|
+
var executor = OperationExecutor.execute({
|
|
348
|
+
actorIdentifier: actorEnvironment.actorIdentifier,
|
|
349
|
+
getDataID: _this4._getDataID,
|
|
350
|
+
isClientPayload: isClientPayload,
|
|
351
|
+
operation: operation,
|
|
352
|
+
operationExecutions: _this4._operationExecutions,
|
|
353
|
+
operationLoader: _this4._operationLoader,
|
|
354
|
+
operationTracker: actorEnvironment.getOperationTracker(),
|
|
355
|
+
optimisticConfig: optimisticConfig,
|
|
356
|
+
getPublishQueue: function getPublishQueue(actorIdentifier) {
|
|
357
|
+
return _this4.forActor(actorIdentifier).getPublishQueue();
|
|
358
|
+
},
|
|
359
|
+
reactFlightPayloadDeserializer: _this4._reactFlightPayloadDeserializer,
|
|
360
|
+
reactFlightServerErrorHandler: _this4._reactFlightServerErrorHandler,
|
|
361
|
+
scheduler: _this4._scheduler,
|
|
362
|
+
shouldProcessClientComponents: _this4._shouldProcessClientComponents,
|
|
363
|
+
sink: sink,
|
|
364
|
+
// NOTE: Some product tests expect `Network.execute` to be called only
|
|
365
|
+
// when the Observable is executed.
|
|
366
|
+
source: createSource(),
|
|
367
|
+
getStore: function getStore(actorIdentifier) {
|
|
368
|
+
return _this4.forActor(actorIdentifier).getStore();
|
|
369
|
+
},
|
|
370
|
+
treatMissingFieldsAsNull: _this4._treatMissingFieldsAsNull,
|
|
371
|
+
updater: updater,
|
|
372
|
+
log: _this4._logFn
|
|
373
|
+
});
|
|
374
|
+
return function () {
|
|
375
|
+
return executor.cancel();
|
|
376
|
+
};
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
_proto._scheduleUpdates = function _scheduleUpdates(task) {
|
|
381
|
+
var scheduler = this._scheduler;
|
|
382
|
+
|
|
383
|
+
if (scheduler != null) {
|
|
384
|
+
scheduler.schedule(task);
|
|
385
|
+
} else {
|
|
386
|
+
task();
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
_proto.commitMultiActorUpdate = function commitMultiActorUpdate(updater) {
|
|
391
|
+
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(this._actorEnvironments),
|
|
392
|
+
_step2;
|
|
393
|
+
|
|
394
|
+
try {
|
|
395
|
+
var _loop2 = function _loop2() {
|
|
396
|
+
var _step2$value = _step2.value,
|
|
397
|
+
actorIdentifier = _step2$value[0],
|
|
398
|
+
environment = _step2$value[1];
|
|
399
|
+
environment.commitUpdate(function (storeProxy) {
|
|
400
|
+
updater(actorIdentifier, environment, storeProxy);
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
405
|
+
_loop2();
|
|
406
|
+
}
|
|
407
|
+
} catch (err) {
|
|
408
|
+
_iterator2.e(err);
|
|
409
|
+
} finally {
|
|
410
|
+
_iterator2.f();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
return MultiActorEnvironment;
|
|
415
|
+
}();
|
|
416
|
+
|
|
417
|
+
function emptyFunction() {}
|
|
418
|
+
|
|
419
|
+
module.exports = MultiActorEnvironment;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var _require = require('./ActorIdentifier'),
|
|
14
|
+
getActorIdentifier = _require.getActorIdentifier;
|
|
15
|
+
|
|
16
|
+
var MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
MultiActorEnvironment: MultiActorEnvironment,
|
|
20
|
+
getActorIdentifier: getActorIdentifier
|
|
21
|
+
};
|
|
@@ -201,7 +201,10 @@ function rangeDelete(config, request) {
|
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
var deleteIDs = [];
|
|
204
|
+
var deleteIDs = []; // the type of data should come from a type parameter associated with ConcreteRequest,
|
|
205
|
+
// but ConcreteRequest does not contain a type parameter. Hence, we use a FlowFixMe.
|
|
206
|
+
// $FlowFixMe[incompatible-use] see above
|
|
207
|
+
|
|
205
208
|
var deletedIDField = data[rootField];
|
|
206
209
|
|
|
207
210
|
if (deletedIDField && Array.isArray(deletedIDFieldName)) {
|