relay-runtime 11.0.0-rc.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/handlers/connection/ConnectionHandler.js.flow +7 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +20 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +12 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +15 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +148 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +406 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -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 +7 -2
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +5 -2
- package/lib/mutations/validateMutation.js +39 -17
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayObservable.js +3 -1
- package/lib/network/RelayQueryResponseCache.js +20 -3
- package/lib/network/wrapNetworkWithLogObserver.js +78 -0
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +1 -1
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/store/DataChecker.js +132 -50
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +524 -187
- package/lib/store/RelayConcreteVariables.js +29 -4
- package/lib/store/RelayModernEnvironment.js +137 -220
- package/lib/store/RelayModernFragmentSpecResolver.js +49 -23
- package/lib/store/RelayModernRecord.js +36 -2
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +53 -22
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +30 -8
- package/lib/store/RelayReader.js +177 -29
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +53 -28
- package/lib/store/RelayResponseNormalizer.js +247 -108
- package/lib/store/RelayStoreReactFlightUtils.js +7 -11
- package/lib/store/RelayStoreSubscriptions.js +8 -5
- package/lib/store/RelayStoreUtils.js +10 -4
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createRelayContext.js +2 -2
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +32 -6
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayFeatureFlags.js +5 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +67 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- 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 +217 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +485 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +245 -0
- package/multi-actor-environment/index.js.flow +27 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
- package/mutations/commitMutation.js.flow +3 -1
- package/mutations/validateMutation.js.flow +42 -16
- package/network/RelayNetworkTypes.js.flow +17 -8
- package/network/RelayObservable.js.flow +2 -0
- package/network/RelayQueryResponseCache.js.flow +31 -17
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +3 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +5 -1
- package/store/DataChecker.js.flow +148 -44
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +578 -237
- package/store/RelayConcreteVariables.js.flow +31 -1
- package/store/RelayModernEnvironment.js.flow +132 -220
- package/store/RelayModernFragmentSpecResolver.js.flow +40 -14
- package/store/RelayModernOperationDescriptor.js.flow +9 -3
- package/store/RelayModernRecord.js.flow +49 -0
- package/store/RelayModernStore.js.flow +57 -17
- package/store/RelayOperationTracker.js.flow +56 -34
- package/store/RelayPublishQueue.js.flow +37 -11
- package/store/RelayReader.js.flow +186 -27
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +51 -21
- package/store/RelayResponseNormalizer.js.flow +251 -67
- package/store/RelayStoreReactFlightUtils.js.flow +6 -9
- package/store/RelayStoreSubscriptions.js.flow +10 -3
- package/store/RelayStoreTypes.js.flow +144 -21
- package/store/RelayStoreUtils.js.flow +19 -4
- package/store/ResolverCache.js.flow +247 -0
- package/store/ResolverFragments.js.flow +128 -0
- package/store/createRelayContext.js.flow +1 -1
- package/store/defaultGetDataID.js.flow +3 -1
- package/subscription/requestSubscription.js.flow +43 -8
- package/util/NormalizationNode.js.flow +16 -3
- package/util/ReaderNode.js.flow +29 -2
- package/util/RelayConcreteNode.js.flow +3 -0
- package/util/RelayFeatureFlags.js.flow +10 -6
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +7 -6
- package/util/RelayRuntimeTypes.js.flow +4 -2
- package/util/deepFreeze.js.flow +2 -1
- package/util/getPaginationMetadata.js.flow +74 -0
- package/util/getPaginationVariables.js.flow +112 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +80 -0
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -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,406 @@
|
|
|
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 ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
20
|
+
|
|
21
|
+
var OperationExecutor = require('../store/OperationExecutor');
|
|
22
|
+
|
|
23
|
+
var RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
24
|
+
|
|
25
|
+
var RelayModernStore = require('../store/RelayModernStore');
|
|
26
|
+
|
|
27
|
+
var RelayObservable = require('../network/RelayObservable');
|
|
28
|
+
|
|
29
|
+
var RelayRecordSource = require('../store/RelayRecordSource');
|
|
30
|
+
|
|
31
|
+
var defaultGetDataID = require('../store/defaultGetDataID');
|
|
32
|
+
|
|
33
|
+
var defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
|
|
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
|
+
updater = _ref.updater;
|
|
263
|
+
return this._execute(actorEnvironment, {
|
|
264
|
+
createSource: function createSource() {
|
|
265
|
+
return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
|
|
266
|
+
},
|
|
267
|
+
isClientPayload: false,
|
|
268
|
+
operation: operation,
|
|
269
|
+
optimisticConfig: null,
|
|
270
|
+
updater: updater
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
_proto.executeMutation = function executeMutation(actorEnvironment, _ref2) {
|
|
275
|
+
var operation = _ref2.operation,
|
|
276
|
+
optimisticResponse = _ref2.optimisticResponse,
|
|
277
|
+
optimisticUpdater = _ref2.optimisticUpdater,
|
|
278
|
+
updater = _ref2.updater,
|
|
279
|
+
uploadables = _ref2.uploadables;
|
|
280
|
+
var optimisticConfig;
|
|
281
|
+
|
|
282
|
+
if (optimisticResponse || optimisticUpdater) {
|
|
283
|
+
optimisticConfig = {
|
|
284
|
+
operation: operation,
|
|
285
|
+
response: optimisticResponse,
|
|
286
|
+
updater: optimisticUpdater
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return this._execute(actorEnvironment, {
|
|
291
|
+
createSource: function createSource() {
|
|
292
|
+
return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, operation.request.cacheConfig), {}, {
|
|
293
|
+
force: true
|
|
294
|
+
}), uploadables);
|
|
295
|
+
},
|
|
296
|
+
isClientPayload: false,
|
|
297
|
+
operation: operation,
|
|
298
|
+
optimisticConfig: optimisticConfig,
|
|
299
|
+
updater: updater
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
_proto.executeWithSource = function executeWithSource(actorEnvironment, config) {
|
|
304
|
+
return this._execute(actorEnvironment, {
|
|
305
|
+
createSource: function createSource() {
|
|
306
|
+
return config.source;
|
|
307
|
+
},
|
|
308
|
+
isClientPayload: false,
|
|
309
|
+
operation: config.operation,
|
|
310
|
+
optimisticConfig: null,
|
|
311
|
+
updater: null
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
_proto.isRequestActive = function isRequestActive(_actorEnvironment, requestIdentifier) {
|
|
316
|
+
var activeState = this._operationExecutions.get(requestIdentifier);
|
|
317
|
+
|
|
318
|
+
return activeState === 'active';
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
_proto.isServer = function isServer() {
|
|
322
|
+
return this._isServer;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
_proto._execute = function _execute(actorEnvironment, _ref3) {
|
|
326
|
+
var _this4 = this;
|
|
327
|
+
|
|
328
|
+
var createSource = _ref3.createSource,
|
|
329
|
+
isClientPayload = _ref3.isClientPayload,
|
|
330
|
+
operation = _ref3.operation,
|
|
331
|
+
optimisticConfig = _ref3.optimisticConfig,
|
|
332
|
+
updater = _ref3.updater;
|
|
333
|
+
return RelayObservable.create(function (sink) {
|
|
334
|
+
var executor = OperationExecutor.execute({
|
|
335
|
+
actorIdentifier: actorEnvironment.actorIdentifier,
|
|
336
|
+
getDataID: _this4._getDataID,
|
|
337
|
+
isClientPayload: isClientPayload,
|
|
338
|
+
operation: operation,
|
|
339
|
+
operationExecutions: _this4._operationExecutions,
|
|
340
|
+
operationLoader: _this4._operationLoader,
|
|
341
|
+
operationTracker: actorEnvironment.getOperationTracker(),
|
|
342
|
+
optimisticConfig: optimisticConfig,
|
|
343
|
+
getPublishQueue: function getPublishQueue(actorIdentifier) {
|
|
344
|
+
return _this4.forActor(actorIdentifier).getPublishQueue();
|
|
345
|
+
},
|
|
346
|
+
reactFlightPayloadDeserializer: _this4._reactFlightPayloadDeserializer,
|
|
347
|
+
reactFlightServerErrorHandler: _this4._reactFlightServerErrorHandler,
|
|
348
|
+
scheduler: _this4._scheduler,
|
|
349
|
+
shouldProcessClientComponents: _this4._shouldProcessClientComponents,
|
|
350
|
+
sink: sink,
|
|
351
|
+
// NOTE: Some product tests expect `Network.execute` to be called only
|
|
352
|
+
// when the Observable is executed.
|
|
353
|
+
source: createSource(),
|
|
354
|
+
getStore: function getStore(actorIdentifier) {
|
|
355
|
+
return _this4.forActor(actorIdentifier).getStore();
|
|
356
|
+
},
|
|
357
|
+
treatMissingFieldsAsNull: _this4._treatMissingFieldsAsNull,
|
|
358
|
+
updater: updater,
|
|
359
|
+
log: _this4._logFn
|
|
360
|
+
});
|
|
361
|
+
return function () {
|
|
362
|
+
return executor.cancel();
|
|
363
|
+
};
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
_proto._scheduleUpdates = function _scheduleUpdates(task) {
|
|
368
|
+
var scheduler = this._scheduler;
|
|
369
|
+
|
|
370
|
+
if (scheduler != null) {
|
|
371
|
+
scheduler.schedule(task);
|
|
372
|
+
} else {
|
|
373
|
+
task();
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
_proto.commitMultiActorUpdate = function commitMultiActorUpdate(updater) {
|
|
378
|
+
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(this._actorEnvironments),
|
|
379
|
+
_step2;
|
|
380
|
+
|
|
381
|
+
try {
|
|
382
|
+
var _loop2 = function _loop2() {
|
|
383
|
+
var _step2$value = _step2.value,
|
|
384
|
+
actorIdentifier = _step2$value[0],
|
|
385
|
+
environment = _step2$value[1];
|
|
386
|
+
environment.commitUpdate(function (storeProxy) {
|
|
387
|
+
updater(actorIdentifier, environment, storeProxy);
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
392
|
+
_loop2();
|
|
393
|
+
}
|
|
394
|
+
} catch (err) {
|
|
395
|
+
_iterator2.e(err);
|
|
396
|
+
} finally {
|
|
397
|
+
_iterator2.f();
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
return MultiActorEnvironment;
|
|
402
|
+
}();
|
|
403
|
+
|
|
404
|
+
function emptyFunction() {}
|
|
405
|
+
|
|
406
|
+
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 MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
14
|
+
|
|
15
|
+
var _require = require('./ActorIdentifier'),
|
|
16
|
+
getActorIdentifier = _require.getActorIdentifier;
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
MultiActorEnvironment: MultiActorEnvironment,
|
|
20
|
+
getActorIdentifier: getActorIdentifier
|
|
21
|
+
};
|
|
@@ -14,7 +14,7 @@ var RelayModernRecord = require('../store/RelayModernRecord');
|
|
|
14
14
|
|
|
15
15
|
var RelayRecordProxy = require('./RelayRecordProxy');
|
|
16
16
|
|
|
17
|
-
var invariant = require(
|
|
17
|
+
var invariant = require('invariant');
|
|
18
18
|
|
|
19
19
|
var _require = require('../store/RelayRecordState'),
|
|
20
20
|
EXISTENT = _require.EXISTENT,
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var invariant = require(
|
|
13
|
+
var invariant = require('invariant');
|
|
14
14
|
|
|
15
15
|
var _require = require('../store/RelayStoreUtils'),
|
|
16
16
|
getStorageKey = _require.getStorageKey,
|
|
@@ -61,8 +61,13 @@ var RelayRecordSourceSelectorProxy = /*#__PURE__*/function () {
|
|
|
61
61
|
|
|
62
62
|
_proto._getRootField = function _getRootField(selector, fieldName, plural) {
|
|
63
63
|
var field = selector.node.selections.find(function (selection) {
|
|
64
|
-
return selection.kind === 'LinkedField' && selection.name === fieldName;
|
|
64
|
+
return selection.kind === 'LinkedField' && selection.name === fieldName || selection.kind === 'RequiredField' && selection.field.name === fieldName;
|
|
65
65
|
});
|
|
66
|
+
|
|
67
|
+
if (field && field.kind === 'RequiredField') {
|
|
68
|
+
field = field.field;
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
!(field && field.kind === 'LinkedField') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceSelectorProxy#getRootField(): Cannot find root ' + 'field `%s`, no such field is defined on GraphQL document `%s`.', fieldName, selector.node.name) : invariant(false) : void 0;
|
|
67
72
|
!(field.plural === plural) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceSelectorProxy#getRootField(): Expected root field ' + '`%s` to be %s.', fieldName, plural ? 'plural' : 'singular') : invariant(false) : void 0;
|
|
68
73
|
return field;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
var RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
14
14
|
|
|
15
|
-
var invariant = require(
|
|
15
|
+
var invariant = require('invariant');
|
|
16
16
|
|
|
17
17
|
var isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
18
18
|
|
|
@@ -16,7 +16,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
16
16
|
|
|
17
17
|
var RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
18
18
|
|
|
19
|
-
var invariant = require(
|
|
19
|
+
var invariant = require('invariant');
|
|
20
20
|
|
|
21
21
|
var isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
22
22
|
|
|
@@ -58,7 +58,10 @@ function commitMutation(environment, config) {
|
|
|
58
58
|
onUnsubscribe = config.onUnsubscribe,
|
|
59
59
|
variables = config.variables,
|
|
60
60
|
uploadables = config.uploadables;
|
|
61
|
-
var operation = createOperationDescriptor(mutation,
|
|
61
|
+
var operation = createOperationDescriptor(mutation,
|
|
62
|
+
/* $FlowFixMe[class-object-subtyping] added when improving typing for this
|
|
63
|
+
* parameters */
|
|
64
|
+
variables, cacheConfig, generateUniqueClientID()); // TODO: remove this check after we fix flow.
|
|
62
65
|
|
|
63
66
|
if (typeof optimisticResponse === 'function') {
|
|
64
67
|
optimisticResponse = optimisticResponse();
|
|
@@ -14,10 +14,28 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
16
16
|
|
|
17
|
-
var warning = require("fbjs/lib/warning");
|
|
17
|
+
var warning = require("fbjs/lib/warning"); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
18
|
+
|
|
18
19
|
|
|
19
20
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
20
21
|
|
|
22
|
+
var _require = require('../util/RelayConcreteNode'),
|
|
23
|
+
ACTOR_CHANGE = _require.ACTOR_CHANGE,
|
|
24
|
+
CONDITION = _require.CONDITION,
|
|
25
|
+
CLIENT_COMPONENT = _require.CLIENT_COMPONENT,
|
|
26
|
+
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
27
|
+
DEFER = _require.DEFER,
|
|
28
|
+
FLIGHT_FIELD = _require.FLIGHT_FIELD,
|
|
29
|
+
FRAGMENT_SPREAD = _require.FRAGMENT_SPREAD,
|
|
30
|
+
INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
|
|
31
|
+
LINKED_FIELD = _require.LINKED_FIELD,
|
|
32
|
+
LINKED_HANDLE = _require.LINKED_HANDLE,
|
|
33
|
+
MODULE_IMPORT = _require.MODULE_IMPORT,
|
|
34
|
+
SCALAR_FIELD = _require.SCALAR_FIELD,
|
|
35
|
+
SCALAR_HANDLE = _require.SCALAR_HANDLE,
|
|
36
|
+
STREAM = _require.STREAM,
|
|
37
|
+
TYPE_DISCRIMINATOR = _require.TYPE_DISCRIMINATOR;
|
|
38
|
+
|
|
21
39
|
var validateMutation = function validateMutation() {};
|
|
22
40
|
|
|
23
41
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -60,20 +78,24 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
60
78
|
|
|
61
79
|
var validateSelection = function validateSelection(optimisticResponse, selection, context) {
|
|
62
80
|
switch (selection.kind) {
|
|
63
|
-
case
|
|
81
|
+
case CONDITION:
|
|
64
82
|
validateSelections(optimisticResponse, selection.selections, context);
|
|
65
83
|
return;
|
|
66
84
|
|
|
67
|
-
case
|
|
85
|
+
case CLIENT_COMPONENT:
|
|
86
|
+
case FRAGMENT_SPREAD:
|
|
68
87
|
validateSelections(optimisticResponse, selection.fragment.selections, context);
|
|
69
88
|
return;
|
|
70
89
|
|
|
71
|
-
case
|
|
72
|
-
case
|
|
73
|
-
case
|
|
90
|
+
case SCALAR_FIELD:
|
|
91
|
+
case LINKED_FIELD:
|
|
92
|
+
case FLIGHT_FIELD:
|
|
74
93
|
return validateField(optimisticResponse, selection, context);
|
|
75
94
|
|
|
76
|
-
case
|
|
95
|
+
case ACTOR_CHANGE:
|
|
96
|
+
return validateField(optimisticResponse, selection.linkedField, context);
|
|
97
|
+
|
|
98
|
+
case INLINE_FRAGMENT:
|
|
77
99
|
var type = selection.type;
|
|
78
100
|
var isConcreteType = selection.abstractKey == null;
|
|
79
101
|
selection.selections.forEach(function (subselection) {
|
|
@@ -85,20 +107,20 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
85
107
|
});
|
|
86
108
|
return;
|
|
87
109
|
|
|
88
|
-
case
|
|
110
|
+
case CLIENT_EXTENSION:
|
|
89
111
|
selection.selections.forEach(function (subselection) {
|
|
90
112
|
validateSelection(optimisticResponse, subselection, context);
|
|
91
113
|
});
|
|
92
114
|
return;
|
|
93
115
|
|
|
94
|
-
case
|
|
116
|
+
case MODULE_IMPORT:
|
|
95
117
|
return validateModuleImport(context);
|
|
96
118
|
|
|
97
|
-
case
|
|
98
|
-
case
|
|
99
|
-
case
|
|
100
|
-
case
|
|
101
|
-
case
|
|
119
|
+
case LINKED_HANDLE:
|
|
120
|
+
case SCALAR_HANDLE:
|
|
121
|
+
case DEFER:
|
|
122
|
+
case STREAM:
|
|
123
|
+
case TYPE_DISCRIMINATOR:
|
|
102
124
|
{
|
|
103
125
|
// TODO(T35864292) - Add missing validations for these types
|
|
104
126
|
return;
|
|
@@ -120,14 +142,14 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
120
142
|
context.visitedPaths.add(path);
|
|
121
143
|
|
|
122
144
|
switch (field.kind) {
|
|
123
|
-
case
|
|
145
|
+
case SCALAR_FIELD:
|
|
124
146
|
if (hasOwnProperty.call(optimisticResponse, fieldName) === false) {
|
|
125
147
|
addFieldToDiff(path, context.missingDiff, true);
|
|
126
148
|
}
|
|
127
149
|
|
|
128
150
|
return;
|
|
129
151
|
|
|
130
|
-
case
|
|
152
|
+
case LINKED_FIELD:
|
|
131
153
|
var selections = field.selections;
|
|
132
154
|
|
|
133
155
|
if (optimisticResponse[fieldName] === null || hasOwnProperty.call(optimisticResponse, fieldName) && optimisticResponse[fieldName] === undefined) {
|
|
@@ -160,7 +182,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
160
182
|
}
|
|
161
183
|
}
|
|
162
184
|
|
|
163
|
-
case
|
|
185
|
+
case FLIGHT_FIELD:
|
|
164
186
|
if (optimisticResponse[fieldName] === null || hasOwnProperty.call(optimisticResponse, fieldName) && optimisticResponse[fieldName] === undefined) {
|
|
165
187
|
return;
|
|
166
188
|
}
|