relay-runtime 2.0.0-rc.2 → 5.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/index.js +1 -1
- package/lib/{generateRelayClientID.js → ClientID.js} +10 -3
- package/lib/ConvertToExecuteFunction.js +6 -4
- package/lib/DataChecker.js +88 -69
- package/lib/NormalizationNode.js +1 -1
- package/lib/ReaderNode.js +1 -1
- package/lib/RelayCombinedEnvironmentTypes.js +1 -1
- package/lib/RelayConcreteNode.js +5 -2
- package/lib/RelayConcreteVariables.js +15 -9
- package/lib/RelayConnectionHandler.js +27 -20
- package/lib/RelayConnectionInterface.js +4 -2
- package/lib/RelayCore.js +48 -15
- package/lib/RelayDeclarativeMutationConfig.js +16 -15
- package/lib/RelayDefaultHandleKey.js +1 -1
- package/lib/RelayDefaultHandlerProvider.js +7 -6
- package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
- package/lib/RelayError.js +7 -2
- package/lib/RelayFeatureFlags.js +16 -0
- package/lib/RelayInMemoryRecordSource.js +8 -2
- package/lib/RelayModernEnvironment.js +159 -237
- package/lib/RelayModernFragmentOwner.js +72 -0
- package/lib/RelayModernFragmentSpecResolver.js +66 -15
- package/lib/RelayModernGraphQLTag.js +9 -5
- package/lib/RelayModernOperationDescriptor.js +9 -6
- package/lib/RelayModernQueryExecutor.js +791 -0
- package/lib/RelayModernRecord.js +44 -24
- package/lib/RelayModernSelector.js +208 -82
- package/lib/RelayModernStore.js +66 -34
- package/lib/RelayNetwork.js +14 -7
- package/lib/RelayNetworkLogger.js +6 -2
- package/lib/RelayNetworkLoggerTransaction.js +8 -4
- package/lib/RelayNetworkTypes.js +1 -1
- package/lib/RelayObservable.js +72 -41
- package/lib/RelayOperationTracker.js +265 -0
- package/lib/RelayProfiler.js +10 -6
- package/lib/RelayPublishQueue.js +66 -47
- package/lib/RelayQueryResponseCache.js +11 -5
- package/lib/RelayReader.js +135 -126
- package/lib/RelayRecordProxy.js +24 -20
- package/lib/RelayRecordSourceMutator.js +88 -25
- package/lib/RelayRecordSourceProxy.js +38 -19
- package/lib/RelayRecordSourceSelectorProxy.js +10 -7
- package/lib/RelayRecordState.js +1 -1
- package/lib/RelayReferenceMarker.js +66 -55
- package/lib/RelayReplaySubject.js +134 -0
- package/lib/RelayResponseNormalizer.js +245 -134
- package/lib/RelayRuntimeTypes.js +1 -1
- package/lib/RelayStoreUtils.js +55 -16
- package/lib/RelayViewerHandler.js +8 -50
- package/lib/StoreInspector.js +171 -0
- package/lib/applyRelayModernOptimisticMutation.js +8 -2
- package/lib/cloneRelayHandleSourceField.js +17 -7
- package/lib/commitLocalUpdate.js +1 -1
- package/lib/commitRelayModernMutation.js +33 -13
- package/lib/createRelayContext.js +27 -0
- package/lib/createRelayNetworkLogger.js +8 -2
- package/lib/deepFreeze.js +1 -1
- package/lib/defaultGetDataID.js +24 -0
- package/lib/fetchQueryInternal.js +232 -0
- package/lib/fetchRelayModernQuery.js +5 -3
- package/lib/getFragmentIdentifier.js +52 -0
- package/lib/getFragmentSpecIdentifier.js +26 -0
- package/lib/getRelayHandleKey.js +8 -2
- package/lib/getRequestParametersIdentifier.js +26 -0
- package/lib/hasOverlappingIDs.js +1 -1
- package/lib/index.js +155 -53
- package/lib/isPromise.js +1 -1
- package/lib/isScalarAndEqual.js +1 -1
- package/lib/normalizeRelayPayload.js +19 -10
- package/lib/recycleNodesInto.js +23 -5
- package/lib/requestRelaySubscription.js +9 -3
- package/lib/validateMutation.js +13 -6
- package/package.json +2 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/lib/normalizePayload.js +0 -37
- package/lib/simpleClone.js +0 -27
|
@@ -0,0 +1,265 @@
|
|
|
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
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var invariant = require("fbjs/lib/invariant");
|
|
13
|
+
|
|
14
|
+
var RelayOperationTracker =
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
function () {
|
|
17
|
+
function RelayOperationTracker() {
|
|
18
|
+
this._ownersToPendingOperations = new Map();
|
|
19
|
+
this._pendingOperationsToOwners = new Map();
|
|
20
|
+
this._ownersToPromise = new Map();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Update the map of current processing operations with the set of
|
|
24
|
+
* affected owners and notify subscribers
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var _proto = RelayOperationTracker.prototype;
|
|
29
|
+
|
|
30
|
+
_proto.update = function update(pendingOperation, affectedOwners) {
|
|
31
|
+
if (affectedOwners.size === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var newlyAffectedOwners = new Set();
|
|
36
|
+
var _iteratorNormalCompletion = true;
|
|
37
|
+
var _didIteratorError = false;
|
|
38
|
+
var _iteratorError = undefined;
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
for (var _iterator = affectedOwners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
42
|
+
var owner = _step.value;
|
|
43
|
+
|
|
44
|
+
var pendingOperationsAffectingOwner = this._ownersToPendingOperations.get(owner);
|
|
45
|
+
|
|
46
|
+
if (pendingOperationsAffectingOwner != null) {
|
|
47
|
+
// In this case the `owner` already affected by some operations
|
|
48
|
+
// We just need to detect, is it the same operation that we already
|
|
49
|
+
// have in the list, or it's a new operation
|
|
50
|
+
if (!pendingOperationsAffectingOwner.has(pendingOperation)) {
|
|
51
|
+
pendingOperationsAffectingOwner.add(pendingOperation);
|
|
52
|
+
newlyAffectedOwners.add(owner);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
// This is a new `owner` that is affected by the operation
|
|
56
|
+
this._ownersToPendingOperations.set(owner, new Set([pendingOperation]));
|
|
57
|
+
|
|
58
|
+
newlyAffectedOwners.add(owner);
|
|
59
|
+
}
|
|
60
|
+
} // No new owners were affected by this operation, we may stop here
|
|
61
|
+
|
|
62
|
+
} catch (err) {
|
|
63
|
+
_didIteratorError = true;
|
|
64
|
+
_iteratorError = err;
|
|
65
|
+
} finally {
|
|
66
|
+
try {
|
|
67
|
+
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
|
68
|
+
_iterator["return"]();
|
|
69
|
+
}
|
|
70
|
+
} finally {
|
|
71
|
+
if (_didIteratorError) {
|
|
72
|
+
throw _iteratorError;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (newlyAffectedOwners.size === 0) {
|
|
78
|
+
return;
|
|
79
|
+
} // But, if some owners were affected we need to add them to
|
|
80
|
+
// the `_pendingOperationsToOwners` set
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
var ownersAffectedByOperation = this._pendingOperationsToOwners.get(pendingOperation) || new Set();
|
|
84
|
+
var _iteratorNormalCompletion2 = true;
|
|
85
|
+
var _didIteratorError2 = false;
|
|
86
|
+
var _iteratorError2 = undefined;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
for (var _iterator2 = newlyAffectedOwners[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
90
|
+
var _owner = _step2.value;
|
|
91
|
+
|
|
92
|
+
this._resolveOwnerResolvers(_owner);
|
|
93
|
+
|
|
94
|
+
ownersAffectedByOperation.add(_owner);
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
_didIteratorError2 = true;
|
|
98
|
+
_iteratorError2 = err;
|
|
99
|
+
} finally {
|
|
100
|
+
try {
|
|
101
|
+
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
|
102
|
+
_iterator2["return"]();
|
|
103
|
+
}
|
|
104
|
+
} finally {
|
|
105
|
+
if (_didIteratorError2) {
|
|
106
|
+
throw _iteratorError2;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this._pendingOperationsToOwners.set(pendingOperation, ownersAffectedByOperation);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Once pending operation is completed we need to remove it
|
|
115
|
+
* from all tracking maps
|
|
116
|
+
*/
|
|
117
|
+
;
|
|
118
|
+
|
|
119
|
+
_proto.complete = function complete(pendingOperation) {
|
|
120
|
+
var affectedOwners = this._pendingOperationsToOwners.get(pendingOperation);
|
|
121
|
+
|
|
122
|
+
if (affectedOwners == null) {
|
|
123
|
+
return;
|
|
124
|
+
} // These were the owners affected only by `pendingOperation`
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
var completedOwners = new Set(); // These were the owners affected by `pendingOperation`
|
|
128
|
+
// and some other operations
|
|
129
|
+
|
|
130
|
+
var updatedOwners = new Set();
|
|
131
|
+
var _iteratorNormalCompletion3 = true;
|
|
132
|
+
var _didIteratorError3 = false;
|
|
133
|
+
var _iteratorError3 = undefined;
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
for (var _iterator3 = affectedOwners[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
137
|
+
var owner = _step3.value;
|
|
138
|
+
|
|
139
|
+
var pendingOperationsAffectingOwner = this._ownersToPendingOperations.get(owner);
|
|
140
|
+
|
|
141
|
+
if (!pendingOperationsAffectingOwner) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pendingOperationsAffectingOwner["delete"](pendingOperation);
|
|
146
|
+
|
|
147
|
+
if (pendingOperationsAffectingOwner.size > 0) {
|
|
148
|
+
updatedOwners.add(owner);
|
|
149
|
+
} else {
|
|
150
|
+
completedOwners.add(owner);
|
|
151
|
+
}
|
|
152
|
+
} // Complete subscriptions for all owners, affected by `pendingOperation`
|
|
153
|
+
|
|
154
|
+
} catch (err) {
|
|
155
|
+
_didIteratorError3 = true;
|
|
156
|
+
_iteratorError3 = err;
|
|
157
|
+
} finally {
|
|
158
|
+
try {
|
|
159
|
+
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
|
160
|
+
_iterator3["return"]();
|
|
161
|
+
}
|
|
162
|
+
} finally {
|
|
163
|
+
if (_didIteratorError3) {
|
|
164
|
+
throw _iteratorError3;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var _iteratorNormalCompletion4 = true;
|
|
170
|
+
var _didIteratorError4 = false;
|
|
171
|
+
var _iteratorError4 = undefined;
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
for (var _iterator4 = completedOwners[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
175
|
+
var _owner2 = _step4.value;
|
|
176
|
+
|
|
177
|
+
this._resolveOwnerResolvers(_owner2);
|
|
178
|
+
|
|
179
|
+
this._ownersToPendingOperations["delete"](_owner2);
|
|
180
|
+
} // Update all owner that were updated by `pendingOperation` but still
|
|
181
|
+
// are affected by other operations
|
|
182
|
+
|
|
183
|
+
} catch (err) {
|
|
184
|
+
_didIteratorError4 = true;
|
|
185
|
+
_iteratorError4 = err;
|
|
186
|
+
} finally {
|
|
187
|
+
try {
|
|
188
|
+
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
|
|
189
|
+
_iterator4["return"]();
|
|
190
|
+
}
|
|
191
|
+
} finally {
|
|
192
|
+
if (_didIteratorError4) {
|
|
193
|
+
throw _iteratorError4;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
var _iteratorNormalCompletion5 = true;
|
|
199
|
+
var _didIteratorError5 = false;
|
|
200
|
+
var _iteratorError5 = undefined;
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
for (var _iterator5 = updatedOwners[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
204
|
+
var _owner3 = _step5.value;
|
|
205
|
+
|
|
206
|
+
this._resolveOwnerResolvers(_owner3);
|
|
207
|
+
} // Finally, remove pending operation
|
|
208
|
+
|
|
209
|
+
} catch (err) {
|
|
210
|
+
_didIteratorError5 = true;
|
|
211
|
+
_iteratorError5 = err;
|
|
212
|
+
} finally {
|
|
213
|
+
try {
|
|
214
|
+
if (!_iteratorNormalCompletion5 && _iterator5["return"] != null) {
|
|
215
|
+
_iterator5["return"]();
|
|
216
|
+
}
|
|
217
|
+
} finally {
|
|
218
|
+
if (_didIteratorError5) {
|
|
219
|
+
throw _iteratorError5;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
this._pendingOperationsToOwners["delete"](pendingOperation);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
_proto._resolveOwnerResolvers = function _resolveOwnerResolvers(owner) {
|
|
228
|
+
var promiseEntry = this._ownersToPromise.get(owner);
|
|
229
|
+
|
|
230
|
+
if (promiseEntry != null) {
|
|
231
|
+
promiseEntry.resolve();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this._ownersToPromise["delete"](owner);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
_proto.getPromiseForPendingOperationsAffectingOwner = function getPromiseForPendingOperationsAffectingOwner(owner) {
|
|
238
|
+
if (!this._ownersToPendingOperations.has(owner)) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
var cachedPromiseEntry = this._ownersToPromise.get(owner);
|
|
243
|
+
|
|
244
|
+
if (cachedPromiseEntry != null) {
|
|
245
|
+
return cachedPromiseEntry.promise;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
var resolve;
|
|
249
|
+
var promise = new Promise(function (r) {
|
|
250
|
+
resolve = r;
|
|
251
|
+
});
|
|
252
|
+
!(resolve != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayOperationTracker: Expected resolver to be defined. If you' + 'are seeing this, it is likely a bug in Relay.') : invariant(false) : void 0;
|
|
253
|
+
|
|
254
|
+
this._ownersToPromise.set(owner, {
|
|
255
|
+
promise: promise,
|
|
256
|
+
resolve: resolve
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
return promise;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
return RelayOperationTracker;
|
|
263
|
+
}();
|
|
264
|
+
|
|
265
|
+
module.exports = RelayOperationTracker;
|
package/lib/RelayProfiler.js
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
+
var emptyFunction = require("fbjs/lib/emptyFunction");
|
|
13
|
+
|
|
14
|
+
var removeFromArray = require("fbjs/lib/removeFromArray");
|
|
15
|
+
|
|
12
16
|
var aggregateHandlersByName = {
|
|
13
17
|
'*': []
|
|
14
18
|
};
|
|
@@ -17,7 +21,7 @@ var profileHandlersByName = {
|
|
|
17
21
|
};
|
|
18
22
|
var NOT_INVOKED = {};
|
|
19
23
|
var defaultProfiler = {
|
|
20
|
-
stop:
|
|
24
|
+
stop: emptyFunction
|
|
21
25
|
};
|
|
22
26
|
|
|
23
27
|
var shouldInstrument = function shouldInstrument(name) {
|
|
@@ -101,8 +105,8 @@ var RelayProfiler = {
|
|
|
101
105
|
*/
|
|
102
106
|
instrument: function instrument(name, originalFunction) {
|
|
103
107
|
if (!shouldInstrument(name)) {
|
|
104
|
-
originalFunction.attachHandler =
|
|
105
|
-
originalFunction.detachHandler =
|
|
108
|
+
originalFunction.attachHandler = emptyFunction;
|
|
109
|
+
originalFunction.detachHandler = emptyFunction;
|
|
106
110
|
return originalFunction;
|
|
107
111
|
}
|
|
108
112
|
|
|
@@ -156,7 +160,7 @@ var RelayProfiler = {
|
|
|
156
160
|
};
|
|
157
161
|
|
|
158
162
|
instrumentedCallback.detachHandler = function (handler) {
|
|
159
|
-
|
|
163
|
+
removeFromArray(handlers, handler);
|
|
160
164
|
};
|
|
161
165
|
|
|
162
166
|
instrumentedCallback.displayName = '(instrumented ' + name + ')';
|
|
@@ -195,7 +199,7 @@ var RelayProfiler = {
|
|
|
195
199
|
detachAggregateHandler: function detachAggregateHandler(name, handler) {
|
|
196
200
|
if (shouldInstrument(name)) {
|
|
197
201
|
if (aggregateHandlersByName.hasOwnProperty(name)) {
|
|
198
|
-
|
|
202
|
+
removeFromArray(aggregateHandlersByName[name], handler);
|
|
199
203
|
}
|
|
200
204
|
}
|
|
201
205
|
},
|
|
@@ -262,7 +266,7 @@ var RelayProfiler = {
|
|
|
262
266
|
detachProfileHandler: function detachProfileHandler(name, handler) {
|
|
263
267
|
if (shouldInstrument(name)) {
|
|
264
268
|
if (profileHandlersByName.hasOwnProperty(name)) {
|
|
265
|
-
|
|
269
|
+
removeFromArray(profileHandlersByName[name], handler);
|
|
266
270
|
}
|
|
267
271
|
}
|
|
268
272
|
}
|
package/lib/RelayPublishQueue.js
CHANGED
|
@@ -4,11 +4,27 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
+
var ErrorUtils = require("fbjs/lib/ErrorUtils");
|
|
13
|
+
|
|
14
|
+
var RelayInMemoryRecordSource = require("./RelayInMemoryRecordSource");
|
|
15
|
+
|
|
16
|
+
var RelayReader = require("./RelayReader");
|
|
17
|
+
|
|
18
|
+
var RelayRecordSourceMutator = require("./RelayRecordSourceMutator");
|
|
19
|
+
|
|
20
|
+
var RelayRecordSourceProxy = require("./RelayRecordSourceProxy");
|
|
21
|
+
|
|
22
|
+
var RelayRecordSourceSelectorProxy = require("./RelayRecordSourceSelectorProxy");
|
|
23
|
+
|
|
24
|
+
var invariant = require("fbjs/lib/invariant");
|
|
25
|
+
|
|
26
|
+
var normalizeRelayPayload = require("./normalizeRelayPayload");
|
|
27
|
+
|
|
12
28
|
/**
|
|
13
29
|
* Coordinates the concurrent modification of a `Store` due to optimistic and
|
|
14
30
|
* non-revertable client updates and server payloads:
|
|
@@ -34,8 +50,8 @@ function () {
|
|
|
34
50
|
// Optimistic updaters that are already added and might be rerun in order to
|
|
35
51
|
// rebase them.
|
|
36
52
|
// Garbage collection hold, should rerun gc on dispose
|
|
37
|
-
function RelayPublishQueue(store, handlerProvider) {
|
|
38
|
-
this._backup = new
|
|
53
|
+
function RelayPublishQueue(store, handlerProvider, getDataID) {
|
|
54
|
+
this._backup = new RelayInMemoryRecordSource();
|
|
39
55
|
this._handlerProvider = handlerProvider || null;
|
|
40
56
|
this._pendingBackupRebase = false;
|
|
41
57
|
this._pendingUpdaters = new Set();
|
|
@@ -44,6 +60,7 @@ function () {
|
|
|
44
60
|
this._store = store;
|
|
45
61
|
this._appliedOptimisticUpdates = new Set();
|
|
46
62
|
this._gcHold = null;
|
|
63
|
+
this._getDataID = getDataID;
|
|
47
64
|
}
|
|
48
65
|
/**
|
|
49
66
|
* Schedule applying an optimistic updates on the next `run()`.
|
|
@@ -53,14 +70,14 @@ function () {
|
|
|
53
70
|
var _proto = RelayPublishQueue.prototype;
|
|
54
71
|
|
|
55
72
|
_proto.applyUpdate = function applyUpdate(updater) {
|
|
56
|
-
!(!this._appliedOptimisticUpdates.has(updater) && !this._pendingOptimisticUpdates.has(updater)) ? process.env.NODE_ENV !== "production" ?
|
|
73
|
+
!(!this._appliedOptimisticUpdates.has(updater) && !this._pendingOptimisticUpdates.has(updater)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayPublishQueue: Cannot apply the same update function more than ' + 'once concurrently.') : invariant(false) : void 0;
|
|
57
74
|
|
|
58
75
|
this._pendingOptimisticUpdates.add(updater);
|
|
59
|
-
}
|
|
76
|
+
}
|
|
60
77
|
/**
|
|
61
78
|
* Schedule reverting an optimistic updates on the next `run()`.
|
|
62
79
|
*/
|
|
63
|
-
|
|
80
|
+
;
|
|
64
81
|
|
|
65
82
|
_proto.revertUpdate = function revertUpdate(updater) {
|
|
66
83
|
if (this._pendingOptimisticUpdates.has(updater)) {
|
|
@@ -71,11 +88,11 @@ function () {
|
|
|
71
88
|
|
|
72
89
|
this._appliedOptimisticUpdates["delete"](updater);
|
|
73
90
|
}
|
|
74
|
-
}
|
|
91
|
+
}
|
|
75
92
|
/**
|
|
76
93
|
* Schedule a revert of all optimistic updates on the next `run()`.
|
|
77
94
|
*/
|
|
78
|
-
|
|
95
|
+
;
|
|
79
96
|
|
|
80
97
|
_proto.revertAll = function revertAll() {
|
|
81
98
|
this._pendingBackupRebase = true;
|
|
@@ -83,11 +100,11 @@ function () {
|
|
|
83
100
|
this._pendingOptimisticUpdates.clear();
|
|
84
101
|
|
|
85
102
|
this._appliedOptimisticUpdates.clear();
|
|
86
|
-
}
|
|
103
|
+
}
|
|
87
104
|
/**
|
|
88
105
|
* Schedule applying a payload to the store on the next `run()`.
|
|
89
106
|
*/
|
|
90
|
-
|
|
107
|
+
;
|
|
91
108
|
|
|
92
109
|
_proto.commitPayload = function commitPayload(operation, _ref, updater) {
|
|
93
110
|
var fieldPayloads = _ref.fieldPayloads,
|
|
@@ -98,7 +115,7 @@ function () {
|
|
|
98
115
|
kind: 'payload',
|
|
99
116
|
payload: {
|
|
100
117
|
fieldPayloads: fieldPayloads,
|
|
101
|
-
|
|
118
|
+
operation: operation,
|
|
102
119
|
source: source,
|
|
103
120
|
updater: updater
|
|
104
121
|
}
|
|
@@ -114,29 +131,29 @@ function () {
|
|
|
114
131
|
kind: 'payload',
|
|
115
132
|
payload: {
|
|
116
133
|
fieldPayloads: fieldPayloads,
|
|
117
|
-
|
|
134
|
+
operation: null,
|
|
118
135
|
source: source,
|
|
119
136
|
updater: null
|
|
120
137
|
}
|
|
121
138
|
});
|
|
122
|
-
}
|
|
139
|
+
}
|
|
123
140
|
/**
|
|
124
141
|
* Schedule an updater to mutate the store on the next `run()` typically to
|
|
125
142
|
* update client schema fields.
|
|
126
143
|
*/
|
|
127
|
-
|
|
144
|
+
;
|
|
128
145
|
|
|
129
146
|
_proto.commitUpdate = function commitUpdate(updater) {
|
|
130
147
|
this._pendingBackupRebase = true;
|
|
131
148
|
|
|
132
149
|
this._pendingUpdaters.add(updater);
|
|
133
|
-
}
|
|
150
|
+
}
|
|
134
151
|
/**
|
|
135
152
|
* Schedule a publish to the store from the provided source on the next
|
|
136
153
|
* `run()`. As an example, to update the store with substituted fields that
|
|
137
154
|
* are missing in the store.
|
|
138
155
|
*/
|
|
139
|
-
|
|
156
|
+
;
|
|
140
157
|
|
|
141
158
|
_proto.commitSource = function commitSource(source) {
|
|
142
159
|
this._pendingBackupRebase = true;
|
|
@@ -145,17 +162,17 @@ function () {
|
|
|
145
162
|
kind: 'source',
|
|
146
163
|
source: source
|
|
147
164
|
});
|
|
148
|
-
}
|
|
165
|
+
}
|
|
149
166
|
/**
|
|
150
167
|
* Execute all queued up operations from the other public methods.
|
|
151
168
|
*/
|
|
152
|
-
|
|
169
|
+
;
|
|
153
170
|
|
|
154
171
|
_proto.run = function run() {
|
|
155
172
|
if (this._pendingBackupRebase && this._backup.size()) {
|
|
156
173
|
this._store.publish(this._backup);
|
|
157
174
|
|
|
158
|
-
this._backup = new
|
|
175
|
+
this._backup = new RelayInMemoryRecordSource();
|
|
159
176
|
}
|
|
160
177
|
|
|
161
178
|
this._commitData();
|
|
@@ -178,32 +195,33 @@ function () {
|
|
|
178
195
|
}
|
|
179
196
|
}
|
|
180
197
|
|
|
181
|
-
this._store.notify();
|
|
198
|
+
return this._store.notify();
|
|
182
199
|
};
|
|
183
200
|
|
|
184
201
|
_proto._getSourceFromPayload = function _getSourceFromPayload(payload) {
|
|
185
202
|
var _this = this;
|
|
186
203
|
|
|
187
204
|
var fieldPayloads = payload.fieldPayloads,
|
|
188
|
-
|
|
205
|
+
operation = payload.operation,
|
|
189
206
|
source = payload.source,
|
|
190
207
|
updater = payload.updater;
|
|
191
|
-
var mutator = new
|
|
192
|
-
var store = new
|
|
208
|
+
var mutator = new RelayRecordSourceMutator(this._store.getSource(), source);
|
|
209
|
+
var store = new RelayRecordSourceProxy(mutator, this._getDataID);
|
|
193
210
|
|
|
194
211
|
if (fieldPayloads && fieldPayloads.length) {
|
|
195
212
|
fieldPayloads.forEach(function (fieldPayload) {
|
|
196
213
|
var handler = _this._handlerProvider && _this._handlerProvider(fieldPayload.handle);
|
|
197
214
|
|
|
198
|
-
!handler ? process.env.NODE_ENV !== "production" ?
|
|
215
|
+
!handler ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected a handler to be provided for ' + 'handle `%s`.', fieldPayload.handle) : invariant(false) : void 0;
|
|
199
216
|
handler.update(store, fieldPayload);
|
|
200
217
|
});
|
|
201
218
|
}
|
|
202
219
|
|
|
203
220
|
if (updater) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
var
|
|
221
|
+
var selector = operation === null || operation === void 0 ? void 0 : operation.fragment;
|
|
222
|
+
!(selector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected a selector to be provided with updater function.') : invariant(false) : void 0;
|
|
223
|
+
var selectorStore = new RelayRecordSourceSelectorProxy(store, selector);
|
|
224
|
+
var selectorData = lookupSelector(source, selector, operation);
|
|
207
225
|
updater(selectorStore, selectorData);
|
|
208
226
|
}
|
|
209
227
|
|
|
@@ -239,13 +257,12 @@ function () {
|
|
|
239
257
|
return;
|
|
240
258
|
}
|
|
241
259
|
|
|
242
|
-
var sink = new
|
|
260
|
+
var sink = new RelayInMemoryRecordSource();
|
|
243
261
|
|
|
244
262
|
this._pendingUpdaters.forEach(function (updater) {
|
|
245
|
-
var mutator = new
|
|
246
|
-
var store = new
|
|
247
|
-
|
|
248
|
-
require("fbjs/lib/ErrorUtils").applyWithGuard(updater, null, [store], null, 'RelayPublishQueue:commitUpdaters');
|
|
263
|
+
var mutator = new RelayRecordSourceMutator(_this3._store.getSource(), sink);
|
|
264
|
+
var store = new RelayRecordSourceProxy(mutator, _this3._getDataID);
|
|
265
|
+
ErrorUtils.applyWithGuard(updater, null, [store], null, 'RelayPublishQueue:commitUpdaters');
|
|
249
266
|
});
|
|
250
267
|
|
|
251
268
|
this._store.publish(sink);
|
|
@@ -257,9 +274,9 @@ function () {
|
|
|
257
274
|
var _this4 = this;
|
|
258
275
|
|
|
259
276
|
if (this._pendingOptimisticUpdates.size || this._pendingBackupRebase && this._appliedOptimisticUpdates.size) {
|
|
260
|
-
var sink = new
|
|
261
|
-
var mutator = new
|
|
262
|
-
var store = new
|
|
277
|
+
var sink = new RelayInMemoryRecordSource();
|
|
278
|
+
var mutator = new RelayRecordSourceMutator(this._store.getSource(), sink, this._backup);
|
|
279
|
+
var store = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider); // rerun all updaters in case we are running a rebase
|
|
263
280
|
|
|
264
281
|
if (this._pendingBackupRebase && this._appliedOptimisticUpdates.size) {
|
|
265
282
|
this._appliedOptimisticUpdates.forEach(function (optimisticUpdate) {
|
|
@@ -272,17 +289,18 @@ function () {
|
|
|
272
289
|
var selectorData, source;
|
|
273
290
|
|
|
274
291
|
if (response) {
|
|
275
|
-
var _normalizeRelayPayloa =
|
|
292
|
+
var _normalizeRelayPayloa = normalizeRelayPayload(operation.root, response, null, {
|
|
293
|
+
getDataID: _this4._getDataID
|
|
294
|
+
});
|
|
276
295
|
|
|
277
296
|
source = _normalizeRelayPayloa.source;
|
|
278
|
-
selectorData = lookupSelector(source, operation.fragment);
|
|
297
|
+
selectorData = lookupSelector(source, operation.fragment, operation);
|
|
279
298
|
}
|
|
280
299
|
|
|
281
|
-
selectorStoreUpdater &&
|
|
300
|
+
selectorStoreUpdater && ErrorUtils.applyWithGuard(selectorStoreUpdater, null, [selectorStore, selectorData], null, 'RelayPublishQueue:applyUpdates');
|
|
282
301
|
} else if (optimisticUpdate.storeUpdater) {
|
|
283
302
|
var storeUpdater = optimisticUpdate.storeUpdater;
|
|
284
|
-
|
|
285
|
-
require("fbjs/lib/ErrorUtils").applyWithGuard(storeUpdater, null, [store], null, 'RelayPublishQueue:applyUpdates');
|
|
303
|
+
ErrorUtils.applyWithGuard(storeUpdater, null, [store], null, 'RelayPublishQueue:applyUpdates');
|
|
286
304
|
} else {
|
|
287
305
|
var _source = optimisticUpdate.source,
|
|
288
306
|
fieldPayloads = optimisticUpdate.fieldPayloads;
|
|
@@ -303,17 +321,18 @@ function () {
|
|
|
303
321
|
var selectorData, source;
|
|
304
322
|
|
|
305
323
|
if (response) {
|
|
306
|
-
var _normalizeRelayPayloa2 =
|
|
324
|
+
var _normalizeRelayPayloa2 = normalizeRelayPayload(operation.root, response, null, {
|
|
325
|
+
getDataID: _this4._getDataID
|
|
326
|
+
});
|
|
307
327
|
|
|
308
328
|
source = _normalizeRelayPayloa2.source;
|
|
309
|
-
selectorData = lookupSelector(source, operation.fragment);
|
|
329
|
+
selectorData = lookupSelector(source, operation.fragment, operation);
|
|
310
330
|
}
|
|
311
331
|
|
|
312
|
-
selectorStoreUpdater &&
|
|
332
|
+
selectorStoreUpdater && ErrorUtils.applyWithGuard(selectorStoreUpdater, null, [selectorStore, selectorData], null, 'RelayPublishQueue:applyUpdates');
|
|
313
333
|
} else if (optimisticUpdate.storeUpdater) {
|
|
314
334
|
var storeUpdater = optimisticUpdate.storeUpdater;
|
|
315
|
-
|
|
316
|
-
require("fbjs/lib/ErrorUtils").applyWithGuard(storeUpdater, null, [store], null, 'RelayPublishQueue:applyUpdates');
|
|
335
|
+
ErrorUtils.applyWithGuard(storeUpdater, null, [store], null, 'RelayPublishQueue:applyUpdates');
|
|
317
336
|
} else {
|
|
318
337
|
var _source2 = optimisticUpdate.source,
|
|
319
338
|
fieldPayloads = optimisticUpdate.fieldPayloads;
|
|
@@ -333,8 +352,8 @@ function () {
|
|
|
333
352
|
return RelayPublishQueue;
|
|
334
353
|
}();
|
|
335
354
|
|
|
336
|
-
function lookupSelector(source, selector) {
|
|
337
|
-
var selectorData =
|
|
355
|
+
function lookupSelector(source, selector, owner) {
|
|
356
|
+
var selectorData = RelayReader.read(source, selector, owner).data;
|
|
338
357
|
|
|
339
358
|
if (process.env.NODE_ENV !== "production") {
|
|
340
359
|
var deepFreeze = require("./deepFreeze");
|
|
@@ -4,12 +4,18 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
13
|
+
|
|
14
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
|
15
|
+
|
|
16
|
+
var invariant = require("fbjs/lib/invariant");
|
|
17
|
+
|
|
18
|
+
var stableCopy = require("./stableCopy");
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
21
|
* A cache for storing query responses, featuring:
|
|
@@ -22,8 +28,8 @@ function () {
|
|
|
22
28
|
function RelayQueryResponseCache(_ref) {
|
|
23
29
|
var size = _ref.size,
|
|
24
30
|
ttl = _ref.ttl;
|
|
25
|
-
!(size > 0) ? process.env.NODE_ENV !== "production" ?
|
|
26
|
-
!(ttl > 0) ? process.env.NODE_ENV !== "production" ?
|
|
31
|
+
!(size > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayQueryResponseCache: Expected the max cache size to be > 0, got ' + '`%s`.', size) : invariant(false) : void 0;
|
|
32
|
+
!(ttl > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayQueryResponseCache: Expected the max ttl to be > 0, got `%s`.', ttl) : invariant(false) : void 0;
|
|
27
33
|
this._responses = new Map();
|
|
28
34
|
this._size = size;
|
|
29
35
|
this._ttl = ttl;
|
|
@@ -82,7 +88,7 @@ function () {
|
|
|
82
88
|
}();
|
|
83
89
|
|
|
84
90
|
function getCacheKey(queryID, variables) {
|
|
85
|
-
return JSON.stringify(
|
|
91
|
+
return JSON.stringify(stableCopy({
|
|
86
92
|
queryID: queryID,
|
|
87
93
|
variables: variables
|
|
88
94
|
}));
|