relay-runtime 8.0.0 → 10.0.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 +41 -0
- package/handlers/connection/ConnectionHandler.js.flow +549 -0
- package/handlers/connection/ConnectionInterface.js.flow +92 -0
- package/handlers/connection/MutationHandlers.js.flow +88 -0
- package/index.js +1 -1
- package/index.js.flow +320 -0
- package/lib/handlers/RelayDefaultHandlerProvider.js +13 -2
- package/lib/handlers/connection/{RelayConnectionHandler.js → ConnectionHandler.js} +33 -35
- package/lib/handlers/connection/{RelayConnectionInterface.js → ConnectionInterface.js} +2 -2
- package/lib/handlers/connection/MutationHandlers.js +86 -0
- package/lib/index.js +15 -19
- package/lib/mutations/RelayDeclarativeMutationConfig.js +29 -52
- package/lib/mutations/RelayRecordProxy.js +1 -3
- package/lib/mutations/RelayRecordSourceMutator.js +2 -9
- package/lib/mutations/RelayRecordSourceProxy.js +2 -4
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -13
- package/lib/mutations/commitMutation.js +13 -3
- package/lib/mutations/validateMutation.js +16 -9
- package/lib/network/RelayObservable.js +9 -9
- package/lib/network/RelayQueryResponseCache.js +8 -6
- package/lib/query/PreloadableQueryRegistry.js +70 -0
- package/lib/query/fetchQueryInternal.js +31 -23
- package/lib/store/DataChecker.js +122 -110
- package/lib/store/RelayConcreteVariables.js +6 -2
- package/lib/store/RelayModernEnvironment.js +121 -67
- package/lib/store/RelayModernFragmentSpecResolver.js +12 -16
- package/lib/store/RelayModernQueryExecutor.js +389 -314
- package/lib/store/RelayModernRecord.js +14 -9
- package/lib/store/RelayModernSelector.js +7 -3
- package/lib/store/RelayModernStore.js +289 -484
- package/lib/store/RelayOperationTracker.js +35 -78
- package/lib/store/RelayOptimisticRecordSource.js +7 -5
- package/lib/store/RelayPublishQueue.js +6 -33
- package/lib/store/RelayReader.js +113 -45
- package/lib/store/RelayRecordSource.js +2 -9
- package/lib/store/RelayRecordSourceMapImpl.js +13 -18
- package/lib/store/RelayReferenceMarker.js +40 -60
- package/lib/store/RelayResponseNormalizer.js +158 -193
- package/lib/store/RelayStoreUtils.js +1 -0
- package/lib/store/StoreInspector.js +8 -8
- package/lib/store/TypeID.js +28 -0
- package/lib/store/cloneRelayScalarHandleSourceField.js +44 -0
- package/lib/store/normalizeRelayPayload.js +6 -2
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +5 -3
- package/lib/util/RelayConcreteNode.js +9 -6
- package/lib/util/RelayError.js +39 -9
- package/lib/util/RelayFeatureFlags.js +2 -5
- package/lib/util/RelayReplaySubject.js +3 -3
- package/lib/util/createPayloadFor3DField.js +7 -2
- package/lib/util/getRequestIdentifier.js +2 -2
- package/lib/util/recycleNodesInto.js +2 -6
- package/mutations/RelayDeclarativeMutationConfig.js.flow +380 -0
- package/mutations/RelayRecordProxy.js.flow +165 -0
- package/mutations/RelayRecordSourceMutator.js.flow +238 -0
- package/mutations/RelayRecordSourceProxy.js.flow +164 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +119 -0
- package/mutations/applyOptimisticMutation.js.flow +76 -0
- package/mutations/commitLocalUpdate.js.flow +24 -0
- package/mutations/commitMutation.js.flow +182 -0
- package/mutations/validateMutation.js.flow +213 -0
- package/network/ConvertToExecuteFunction.js.flow +49 -0
- package/network/RelayNetwork.js.flow +84 -0
- package/network/RelayNetworkTypes.js.flow +123 -0
- package/network/RelayObservable.js.flow +634 -0
- package/network/RelayQueryResponseCache.js.flow +111 -0
- package/package.json +1 -1
- package/query/GraphQLTag.js.flow +166 -0
- package/query/PreloadableQueryRegistry.js.flow +65 -0
- package/query/fetchQuery.js.flow +47 -0
- package/query/fetchQueryInternal.js.flow +348 -0
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +43 -0
- package/store/DataChecker.js.flow +502 -0
- package/store/RelayConcreteVariables.js.flow +96 -0
- package/store/RelayModernEnvironment.js.flow +551 -0
- package/store/RelayModernFragmentSpecResolver.js.flow +426 -0
- package/store/RelayModernOperationDescriptor.js.flow +88 -0
- package/store/RelayModernQueryExecutor.js.flow +1321 -0
- package/store/RelayModernRecord.js.flow +403 -0
- package/store/RelayModernSelector.js.flow +455 -0
- package/store/RelayModernStore.js.flow +842 -0
- package/store/RelayOperationTracker.js.flow +164 -0
- package/store/RelayOptimisticRecordSource.js.flow +119 -0
- package/store/RelayPublishQueue.js.flow +401 -0
- package/store/RelayReader.js.flow +473 -0
- package/store/RelayRecordSource.js.flow +29 -0
- package/store/RelayRecordSourceMapImpl.js.flow +87 -0
- package/store/RelayRecordState.js.flow +37 -0
- package/store/RelayReferenceMarker.js.flow +257 -0
- package/store/RelayResponseNormalizer.js.flow +680 -0
- package/store/RelayStoreTypes.js.flow +899 -0
- package/store/RelayStoreUtils.js.flow +219 -0
- package/store/StoreInspector.js.flow +171 -0
- package/store/TypeID.js.flow +28 -0
- package/store/ViewerPattern.js.flow +26 -0
- package/store/cloneRelayHandleSourceField.js.flow +66 -0
- package/store/cloneRelayScalarHandleSourceField.js.flow +62 -0
- package/store/createFragmentSpecResolver.js.flow +55 -0
- package/store/createRelayContext.js.flow +44 -0
- package/store/defaultGetDataID.js.flow +27 -0
- package/store/hasOverlappingIDs.js.flow +34 -0
- package/store/isRelayModernEnvironment.js.flow +27 -0
- package/store/normalizeRelayPayload.js.flow +51 -0
- package/store/readInlineData.js.flow +75 -0
- package/subscription/requestSubscription.js.flow +100 -0
- package/util/JSResourceTypes.flow.js.flow +20 -0
- package/util/NormalizationNode.js.flow +198 -0
- package/util/ReaderNode.js.flow +208 -0
- package/util/RelayConcreteNode.js.flow +93 -0
- package/util/RelayDefaultHandleKey.js.flow +17 -0
- package/util/RelayError.js.flow +62 -0
- package/util/RelayFeatureFlags.js.flow +30 -0
- package/util/RelayProfiler.js.flow +284 -0
- package/util/RelayReplaySubject.js.flow +135 -0
- package/util/RelayRuntimeTypes.js.flow +72 -0
- package/util/createPayloadFor3DField.js.flow +43 -0
- package/util/deepFreeze.js.flow +36 -0
- package/util/generateID.js.flow +21 -0
- package/util/getFragmentIdentifier.js.flow +52 -0
- package/util/getRelayHandleKey.js.flow +41 -0
- package/util/getRequestIdentifier.js.flow +42 -0
- package/util/isPromise.js.flow +21 -0
- package/util/isScalarAndEqual.js.flow +26 -0
- package/util/recycleNodesInto.js.flow +76 -0
- package/util/resolveImmediate.js.flow +30 -0
- package/util/stableCopy.js.flow +35 -0
- package/lib/handlers/RelayDefaultMissingFieldHandlers.js +0 -26
- package/lib/handlers/getRelayDefaultMissingFieldHandlers.js +0 -36
- package/lib/query/RelayModernGraphQLTag.js +0 -104
- package/lib/store/RelayConnection.js +0 -37
- package/lib/store/RelayConnectionResolver.js +0 -178
- package/lib/store/RelayRecordSourceObjectImpl.js +0 -79
- package/lib/util/getFragmentSpecIdentifier.js +0 -27
|
@@ -10,11 +10,15 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
14
|
+
|
|
15
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
+
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
+
|
|
13
19
|
var invariant = require("fbjs/lib/invariant");
|
|
14
20
|
|
|
15
|
-
var RelayOperationTracker =
|
|
16
|
-
/*#__PURE__*/
|
|
17
|
-
function () {
|
|
21
|
+
var RelayOperationTracker = /*#__PURE__*/function () {
|
|
18
22
|
function RelayOperationTracker() {
|
|
19
23
|
this._ownersToPendingOperations = new Map();
|
|
20
24
|
this._pendingOperationsToOwners = new Map();
|
|
@@ -34,12 +38,12 @@ function () {
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
var newlyAffectedOwners = new Set();
|
|
37
|
-
|
|
38
|
-
var
|
|
39
|
-
|
|
41
|
+
|
|
42
|
+
var _iterator = _createForOfIteratorHelper(affectedOwners),
|
|
43
|
+
_step;
|
|
40
44
|
|
|
41
45
|
try {
|
|
42
|
-
for (
|
|
46
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
43
47
|
var owner = _step.value;
|
|
44
48
|
|
|
45
49
|
var pendingOperationsAffectingOwner = this._ownersToPendingOperations.get(owner);
|
|
@@ -61,18 +65,9 @@ function () {
|
|
|
61
65
|
} // No new owners were affected by this operation, we may stop here
|
|
62
66
|
|
|
63
67
|
} catch (err) {
|
|
64
|
-
|
|
65
|
-
_iteratorError = err;
|
|
68
|
+
_iterator.e(err);
|
|
66
69
|
} finally {
|
|
67
|
-
|
|
68
|
-
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
|
69
|
-
_iterator["return"]();
|
|
70
|
-
}
|
|
71
|
-
} finally {
|
|
72
|
-
if (_didIteratorError) {
|
|
73
|
-
throw _iteratorError;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
70
|
+
_iterator.f();
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
if (newlyAffectedOwners.size === 0) {
|
|
@@ -82,12 +77,12 @@ function () {
|
|
|
82
77
|
|
|
83
78
|
|
|
84
79
|
var ownersAffectedByOperation = this._pendingOperationsToOwners.get(pendingOperation) || new Set();
|
|
85
|
-
|
|
86
|
-
var
|
|
87
|
-
|
|
80
|
+
|
|
81
|
+
var _iterator2 = _createForOfIteratorHelper(newlyAffectedOwners),
|
|
82
|
+
_step2;
|
|
88
83
|
|
|
89
84
|
try {
|
|
90
|
-
for (
|
|
85
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
91
86
|
var _owner = _step2.value;
|
|
92
87
|
|
|
93
88
|
this._resolveOwnerResolvers(_owner);
|
|
@@ -95,18 +90,9 @@ function () {
|
|
|
95
90
|
ownersAffectedByOperation.add(_owner);
|
|
96
91
|
}
|
|
97
92
|
} catch (err) {
|
|
98
|
-
|
|
99
|
-
_iteratorError2 = err;
|
|
93
|
+
_iterator2.e(err);
|
|
100
94
|
} finally {
|
|
101
|
-
|
|
102
|
-
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
|
103
|
-
_iterator2["return"]();
|
|
104
|
-
}
|
|
105
|
-
} finally {
|
|
106
|
-
if (_didIteratorError2) {
|
|
107
|
-
throw _iteratorError2;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
95
|
+
_iterator2.f();
|
|
110
96
|
}
|
|
111
97
|
|
|
112
98
|
this._pendingOperationsToOwners.set(pendingOperation, ownersAffectedByOperation);
|
|
@@ -129,12 +115,12 @@ function () {
|
|
|
129
115
|
// and some other operations
|
|
130
116
|
|
|
131
117
|
var updatedOwners = new Set();
|
|
132
|
-
|
|
133
|
-
var
|
|
134
|
-
|
|
118
|
+
|
|
119
|
+
var _iterator3 = _createForOfIteratorHelper(affectedOwners),
|
|
120
|
+
_step3;
|
|
135
121
|
|
|
136
122
|
try {
|
|
137
|
-
for (
|
|
123
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
138
124
|
var owner = _step3.value;
|
|
139
125
|
|
|
140
126
|
var pendingOperationsAffectingOwner = this._ownersToPendingOperations.get(owner);
|
|
@@ -153,26 +139,16 @@ function () {
|
|
|
153
139
|
} // Complete subscriptions for all owners, affected by `pendingOperation`
|
|
154
140
|
|
|
155
141
|
} catch (err) {
|
|
156
|
-
|
|
157
|
-
_iteratorError3 = err;
|
|
142
|
+
_iterator3.e(err);
|
|
158
143
|
} finally {
|
|
159
|
-
|
|
160
|
-
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
|
161
|
-
_iterator3["return"]();
|
|
162
|
-
}
|
|
163
|
-
} finally {
|
|
164
|
-
if (_didIteratorError3) {
|
|
165
|
-
throw _iteratorError3;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
144
|
+
_iterator3.f();
|
|
168
145
|
}
|
|
169
146
|
|
|
170
|
-
var
|
|
171
|
-
|
|
172
|
-
var _iteratorError4 = undefined;
|
|
147
|
+
var _iterator4 = _createForOfIteratorHelper(completedOwners),
|
|
148
|
+
_step4;
|
|
173
149
|
|
|
174
150
|
try {
|
|
175
|
-
for (
|
|
151
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
176
152
|
var _owner2 = _step4.value;
|
|
177
153
|
|
|
178
154
|
this._resolveOwnerResolvers(_owner2);
|
|
@@ -182,44 +158,25 @@ function () {
|
|
|
182
158
|
// are affected by other operations
|
|
183
159
|
|
|
184
160
|
} catch (err) {
|
|
185
|
-
|
|
186
|
-
_iteratorError4 = err;
|
|
161
|
+
_iterator4.e(err);
|
|
187
162
|
} finally {
|
|
188
|
-
|
|
189
|
-
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
|
|
190
|
-
_iterator4["return"]();
|
|
191
|
-
}
|
|
192
|
-
} finally {
|
|
193
|
-
if (_didIteratorError4) {
|
|
194
|
-
throw _iteratorError4;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
163
|
+
_iterator4.f();
|
|
197
164
|
}
|
|
198
165
|
|
|
199
|
-
var
|
|
200
|
-
|
|
201
|
-
var _iteratorError5 = undefined;
|
|
166
|
+
var _iterator5 = _createForOfIteratorHelper(updatedOwners),
|
|
167
|
+
_step5;
|
|
202
168
|
|
|
203
169
|
try {
|
|
204
|
-
for (
|
|
170
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
205
171
|
var _owner3 = _step5.value;
|
|
206
172
|
|
|
207
173
|
this._resolveOwnerResolvers(_owner3);
|
|
208
174
|
} // Finally, remove pending operation
|
|
209
175
|
|
|
210
176
|
} catch (err) {
|
|
211
|
-
|
|
212
|
-
_iteratorError5 = err;
|
|
177
|
+
_iterator5.e(err);
|
|
213
178
|
} finally {
|
|
214
|
-
|
|
215
|
-
if (!_iteratorNormalCompletion5 && _iterator5["return"] != null) {
|
|
216
|
-
_iterator5["return"]();
|
|
217
|
-
}
|
|
218
|
-
} finally {
|
|
219
|
-
if (_didIteratorError5) {
|
|
220
|
-
throw _iteratorError5;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
179
|
+
_iterator5.f();
|
|
223
180
|
}
|
|
224
181
|
|
|
225
182
|
this._pendingOperationsToOwners["delete"](pendingOperation);
|
|
@@ -12,7 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
|
|
17
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
18
|
+
|
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
16
20
|
|
|
17
21
|
var RelayRecordSource = require('./RelayRecordSource');
|
|
18
22
|
|
|
@@ -25,9 +29,7 @@ var UNPUBLISH_RECORD_SENTINEL = Object.freeze({
|
|
|
25
29
|
* shadow the base version of the record rather than updating/replacing them.
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
|
-
var RelayOptimisticRecordSource =
|
|
29
|
-
/*#__PURE__*/
|
|
30
|
-
function () {
|
|
32
|
+
var RelayOptimisticRecordSource = /*#__PURE__*/function () {
|
|
31
33
|
function RelayOptimisticRecordSource(base) {
|
|
32
34
|
this._base = base;
|
|
33
35
|
this._sink = RelayRecordSource.create();
|
|
@@ -100,7 +102,7 @@ function () {
|
|
|
100
102
|
_proto.toJSON = function toJSON() {
|
|
101
103
|
var _this = this;
|
|
102
104
|
|
|
103
|
-
var merged = (
|
|
105
|
+
var merged = _objectSpread({}, this._base.toJSON());
|
|
104
106
|
|
|
105
107
|
this._sink.getRecordIDs().forEach(function (dataID) {
|
|
106
108
|
var record = _this.get(dataID);
|
|
@@ -10,10 +10,6 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
|
-
|
|
15
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
16
|
-
|
|
17
13
|
var ErrorUtils = require("fbjs/lib/ErrorUtils");
|
|
18
14
|
|
|
19
15
|
var RelayReader = require('./RelayReader');
|
|
@@ -41,9 +37,7 @@ var warning = require("fbjs/lib/warning");
|
|
|
41
37
|
* - Executes handlers for "handle" fields.
|
|
42
38
|
* - Reverts and reapplies pending optimistic updates.
|
|
43
39
|
*/
|
|
44
|
-
var RelayPublishQueue =
|
|
45
|
-
/*#__PURE__*/
|
|
46
|
-
function () {
|
|
40
|
+
var RelayPublishQueue = /*#__PURE__*/function () {
|
|
47
41
|
// True if the next `run()` should apply the backup and rerun all optimistic
|
|
48
42
|
// updates performing a rebase.
|
|
49
43
|
// Payloads to apply or Sources to publish to the store with the next `run()`.
|
|
@@ -208,11 +202,9 @@ function () {
|
|
|
208
202
|
var payload = pendingPayload.payload,
|
|
209
203
|
operation = pendingPayload.operation,
|
|
210
204
|
updater = pendingPayload.updater;
|
|
211
|
-
var
|
|
212
|
-
source = payload.source,
|
|
205
|
+
var source = payload.source,
|
|
213
206
|
fieldPayloads = payload.fieldPayloads;
|
|
214
|
-
var
|
|
215
|
-
var mutator = new RelayRecordSourceMutator(this._store.getSource(), source, combinedConnectionEvents);
|
|
207
|
+
var mutator = new RelayRecordSourceMutator(this._store.getSource(), source);
|
|
216
208
|
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID);
|
|
217
209
|
|
|
218
210
|
if (fieldPayloads && fieldPayloads.length) {
|
|
@@ -236,10 +228,6 @@ function () {
|
|
|
236
228
|
|
|
237
229
|
this._store.publish(source, idsMarkedForInvalidation);
|
|
238
230
|
|
|
239
|
-
if (combinedConnectionEvents.length !== 0) {
|
|
240
|
-
this._store.publishConnectionEvents_UNSTABLE(combinedConnectionEvents, true);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
231
|
return recordSourceProxy.isStoreMarkedForInvalidation();
|
|
244
232
|
}
|
|
245
233
|
/**
|
|
@@ -269,18 +257,13 @@ function () {
|
|
|
269
257
|
} else {
|
|
270
258
|
var updater = data.updater;
|
|
271
259
|
var sink = RelayRecordSource.create();
|
|
272
|
-
var
|
|
273
|
-
var mutator = new RelayRecordSourceMutator(_this2._store.getSource(), sink, connectionEvents);
|
|
260
|
+
var mutator = new RelayRecordSourceMutator(_this2._store.getSource(), sink);
|
|
274
261
|
var recordSourceProxy = new RelayRecordSourceProxy(mutator, _this2._getDataID);
|
|
275
262
|
ErrorUtils.applyWithGuard(updater, null, [recordSourceProxy], null, 'RelayPublishQueue:commitData');
|
|
276
263
|
invalidatedStore = invalidatedStore || recordSourceProxy.isStoreMarkedForInvalidation();
|
|
277
264
|
var idsMarkedForInvalidation = recordSourceProxy.getIDsMarkedForInvalidation();
|
|
278
265
|
|
|
279
266
|
_this2._store.publish(sink, idsMarkedForInvalidation);
|
|
280
|
-
|
|
281
|
-
if (connectionEvents.length !== 0) {
|
|
282
|
-
_this2._store.publishConnectionEvents_UNSTABLE(connectionEvents, true);
|
|
283
|
-
}
|
|
284
267
|
}
|
|
285
268
|
});
|
|
286
269
|
|
|
@@ -299,8 +282,7 @@ function () {
|
|
|
299
282
|
var _this3 = this;
|
|
300
283
|
|
|
301
284
|
var sink = RelayRecordSource.create();
|
|
302
|
-
var
|
|
303
|
-
var mutator = new RelayRecordSourceMutator(this._store.getSource(), sink, combinedConnectionEvents);
|
|
285
|
+
var mutator = new RelayRecordSourceMutator(this._store.getSource(), sink);
|
|
304
286
|
var recordSourceProxy = new RelayRecordSourceProxy(mutator, this._getDataID, this._handlerProvider);
|
|
305
287
|
|
|
306
288
|
var processUpdate = function processUpdate(optimisticUpdate) {
|
|
@@ -311,8 +293,7 @@ function () {
|
|
|
311
293
|
var operation = optimisticUpdate.operation,
|
|
312
294
|
payload = optimisticUpdate.payload,
|
|
313
295
|
updater = optimisticUpdate.updater;
|
|
314
|
-
var
|
|
315
|
-
source = payload.source,
|
|
296
|
+
var source = payload.source,
|
|
316
297
|
fieldPayloads = payload.fieldPayloads;
|
|
317
298
|
var recordSourceSelectorProxy = new RelayRecordSourceSelectorProxy(mutator, recordSourceProxy, operation.fragment);
|
|
318
299
|
var selectorData;
|
|
@@ -322,10 +303,6 @@ function () {
|
|
|
322
303
|
selectorData = lookupSelector(source, operation.fragment);
|
|
323
304
|
}
|
|
324
305
|
|
|
325
|
-
if (connectionEvents) {
|
|
326
|
-
combinedConnectionEvents.push.apply(combinedConnectionEvents, (0, _toConsumableArray2["default"])(connectionEvents));
|
|
327
|
-
}
|
|
328
|
-
|
|
329
306
|
if (updater) {
|
|
330
307
|
ErrorUtils.applyWithGuard(updater, null, [recordSourceSelectorProxy, selectorData], null, 'RelayPublishQueue:applyUpdates');
|
|
331
308
|
}
|
|
@@ -349,10 +326,6 @@ function () {
|
|
|
349
326
|
}
|
|
350
327
|
|
|
351
328
|
this._store.publish(sink);
|
|
352
|
-
|
|
353
|
-
if (combinedConnectionEvents.length !== 0) {
|
|
354
|
-
this._store.publishConnectionEvents_UNSTABLE(combinedConnectionEvents, false);
|
|
355
|
-
}
|
|
356
329
|
};
|
|
357
330
|
|
|
358
331
|
return RelayPublishQueue;
|
package/lib/store/RelayReader.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
14
14
|
|
|
15
15
|
var RelayModernRecord = require('./RelayModernRecord');
|
|
16
16
|
|
|
@@ -18,7 +18,6 @@ var invariant = require("fbjs/lib/invariant");
|
|
|
18
18
|
|
|
19
19
|
var _require = require('../util/RelayConcreteNode'),
|
|
20
20
|
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
21
|
-
CONNECTION = _require.CONNECTION,
|
|
22
21
|
CONDITION = _require.CONDITION,
|
|
23
22
|
DEFER = _require.DEFER,
|
|
24
23
|
FRAGMENT_SPREAD = _require.FRAGMENT_SPREAD,
|
|
@@ -34,11 +33,16 @@ var _require2 = require('./RelayStoreUtils'),
|
|
|
34
33
|
FRAGMENT_OWNER_KEY = _require2.FRAGMENT_OWNER_KEY,
|
|
35
34
|
FRAGMENT_PROP_NAME_KEY = _require2.FRAGMENT_PROP_NAME_KEY,
|
|
36
35
|
ID_KEY = _require2.ID_KEY,
|
|
36
|
+
IS_WITHIN_UNMATCHED_TYPE_REFINEMENT = _require2.IS_WITHIN_UNMATCHED_TYPE_REFINEMENT,
|
|
37
37
|
MODULE_COMPONENT_KEY = _require2.MODULE_COMPONENT_KEY,
|
|
38
|
+
ROOT_ID = _require2.ROOT_ID,
|
|
38
39
|
getArgumentValues = _require2.getArgumentValues,
|
|
39
40
|
getStorageKey = _require2.getStorageKey,
|
|
40
41
|
getModuleComponentKey = _require2.getModuleComponentKey;
|
|
41
42
|
|
|
43
|
+
var _require3 = require('./TypeID'),
|
|
44
|
+
generateTypeID = _require3.generateTypeID;
|
|
45
|
+
|
|
42
46
|
function read(recordSource, selector) {
|
|
43
47
|
var reader = new RelayReader(recordSource, selector);
|
|
44
48
|
return reader.read();
|
|
@@ -48,11 +52,10 @@ function read(recordSource, selector) {
|
|
|
48
52
|
*/
|
|
49
53
|
|
|
50
54
|
|
|
51
|
-
var RelayReader =
|
|
52
|
-
/*#__PURE__*/
|
|
53
|
-
function () {
|
|
55
|
+
var RelayReader = /*#__PURE__*/function () {
|
|
54
56
|
function RelayReader(recordSource, selector) {
|
|
55
57
|
this._isMissingData = false;
|
|
58
|
+
this._isWithinUnmatchedTypeRefinement = false;
|
|
56
59
|
this._owner = selector.owner;
|
|
57
60
|
this._recordSource = recordSource;
|
|
58
61
|
this._seenRecords = {};
|
|
@@ -65,13 +68,61 @@ function () {
|
|
|
65
68
|
_proto.read = function read() {
|
|
66
69
|
var _this$_selector = this._selector,
|
|
67
70
|
node = _this$_selector.node,
|
|
68
|
-
dataID = _this$_selector.dataID
|
|
71
|
+
dataID = _this$_selector.dataID,
|
|
72
|
+
isWithinUnmatchedTypeRefinement = _this$_selector.isWithinUnmatchedTypeRefinement;
|
|
73
|
+
var abstractKey = node.abstractKey;
|
|
74
|
+
|
|
75
|
+
var record = this._recordSource.get(dataID); // Relay historically allowed child fragments to be read even if the root object
|
|
76
|
+
// did not match the type of the fragment: either the root object has a different
|
|
77
|
+
// concrete type than the fragment (for concrete fragments) or the root object does
|
|
78
|
+
// not conform to the interface/union for abstract fragments.
|
|
79
|
+
// For suspense purposes, however, we want to accurately compute whether any data
|
|
80
|
+
// is missing: but if the fragment type doesn't match (or a parent type didn't
|
|
81
|
+
// match), then no data is expected to be present.
|
|
82
|
+
// By default data is expected to be present unless this selector was read out
|
|
83
|
+
// from within a non-matching type refinement in a parent fragment:
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
var isDataExpectedToBePresent = !isWithinUnmatchedTypeRefinement; // If this is a concrete fragment and the concrete type of the record does not
|
|
87
|
+
// match, then no data is expected to be present.
|
|
88
|
+
|
|
89
|
+
if (isDataExpectedToBePresent && abstractKey == null && record != null) {
|
|
90
|
+
var recordType = RelayModernRecord.getType(record);
|
|
91
|
+
|
|
92
|
+
if (recordType !== node.type && dataID !== ROOT_ID) {
|
|
93
|
+
isDataExpectedToBePresent = false;
|
|
94
|
+
}
|
|
95
|
+
} // If this is an abstract fragment (and the precise refinement GK is enabled)
|
|
96
|
+
// then data is only expected to be present if the record type is known to
|
|
97
|
+
// implement the interface. If we aren't sure whether the record implements
|
|
98
|
+
// the interface, that itself constitutes "expected" data being missing.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if (isDataExpectedToBePresent && abstractKey != null && record != null && RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
|
|
102
|
+
var _recordType = RelayModernRecord.getType(record);
|
|
103
|
+
|
|
104
|
+
var typeID = generateTypeID(_recordType);
|
|
105
|
+
|
|
106
|
+
var typeRecord = this._recordSource.get(typeID);
|
|
107
|
+
|
|
108
|
+
var implementsInterface = typeRecord != null ? RelayModernRecord.getValue(typeRecord, abstractKey) : null;
|
|
109
|
+
|
|
110
|
+
if (implementsInterface === false) {
|
|
111
|
+
// Type known to not implement the interface
|
|
112
|
+
isDataExpectedToBePresent = false;
|
|
113
|
+
} else if (implementsInterface == null) {
|
|
114
|
+
// Don't know if the type implements the interface or not
|
|
115
|
+
this._isMissingData = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this._isWithinUnmatchedTypeRefinement = !isDataExpectedToBePresent;
|
|
69
120
|
|
|
70
121
|
var data = this._traverse(node, dataID, null);
|
|
71
122
|
|
|
72
123
|
return {
|
|
73
124
|
data: data,
|
|
74
|
-
isMissingData: this._isMissingData,
|
|
125
|
+
isMissingData: this._isMissingData && isDataExpectedToBePresent,
|
|
75
126
|
seenRecords: this._seenRecords,
|
|
76
127
|
selector: this._selector
|
|
77
128
|
};
|
|
@@ -131,14 +182,53 @@ function () {
|
|
|
131
182
|
break;
|
|
132
183
|
|
|
133
184
|
case INLINE_FRAGMENT:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
185
|
+
{
|
|
186
|
+
var abstractKey = selection.abstractKey;
|
|
187
|
+
|
|
188
|
+
if (abstractKey == null) {
|
|
189
|
+
// concrete type refinement: only read data if the type exactly matches
|
|
190
|
+
var typeName = RelayModernRecord.getType(record);
|
|
191
|
+
|
|
192
|
+
if (typeName != null && typeName === selection.type) {
|
|
193
|
+
this._traverseSelections(selection.selections, record, data);
|
|
194
|
+
}
|
|
195
|
+
} else if (RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
|
|
196
|
+
// Similar to the logic in read(): data is only expected to be present
|
|
197
|
+
// if the record is known to conform to the interface. If we don't know
|
|
198
|
+
// whether the type conforms or not, that constitutes missing data.
|
|
199
|
+
// store flags to reset after reading
|
|
200
|
+
var parentIsMissingData = this._isMissingData;
|
|
201
|
+
var parentIsWithinUnmatchedTypeRefinement = this._isWithinUnmatchedTypeRefinement;
|
|
202
|
+
|
|
203
|
+
var _typeName = RelayModernRecord.getType(record);
|
|
204
|
+
|
|
205
|
+
var typeID = generateTypeID(_typeName);
|
|
206
|
+
|
|
207
|
+
var typeRecord = this._recordSource.get(typeID);
|
|
208
|
+
|
|
209
|
+
var implementsInterface = typeRecord != null ? RelayModernRecord.getValue(typeRecord, abstractKey) : null;
|
|
210
|
+
this._isWithinUnmatchedTypeRefinement = parentIsWithinUnmatchedTypeRefinement || implementsInterface === false;
|
|
211
|
+
|
|
212
|
+
this._traverseSelections(selection.selections, record, data);
|
|
213
|
+
|
|
214
|
+
this._isWithinUnmatchedTypeRefinement = parentIsWithinUnmatchedTypeRefinement;
|
|
215
|
+
|
|
216
|
+
if (implementsInterface === false) {
|
|
217
|
+
// Type known to not implement the interface, no data expected
|
|
218
|
+
this._isMissingData = parentIsMissingData;
|
|
219
|
+
} else if (implementsInterface == null) {
|
|
220
|
+
// Don't know if the type implements the interface or not
|
|
221
|
+
this._isMissingData = true;
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
// legacy behavior for abstract refinements: always read even
|
|
225
|
+
// if the type doesn't conform and don't reset isMissingData
|
|
226
|
+
this._traverseSelections(selection.selections, record, data);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
break;
|
|
138
230
|
}
|
|
139
231
|
|
|
140
|
-
break;
|
|
141
|
-
|
|
142
232
|
case FRAGMENT_SPREAD:
|
|
143
233
|
this._createFragmentPointer(selection, record, data);
|
|
144
234
|
|
|
@@ -163,11 +253,6 @@ function () {
|
|
|
163
253
|
this._isMissingData = isMissingData;
|
|
164
254
|
break;
|
|
165
255
|
|
|
166
|
-
case CONNECTION:
|
|
167
|
-
this._readConnection(selection, record, data);
|
|
168
|
-
|
|
169
|
-
break;
|
|
170
|
-
|
|
171
256
|
case STREAM:
|
|
172
257
|
this._traverseSelections(selection.selections, record, data);
|
|
173
258
|
|
|
@@ -180,19 +265,6 @@ function () {
|
|
|
180
265
|
}
|
|
181
266
|
};
|
|
182
267
|
|
|
183
|
-
_proto._readConnection = function _readConnection(field, record, data) {
|
|
184
|
-
var parentID = RelayModernRecord.getDataID(record);
|
|
185
|
-
var connectionID = RelayConnection.createConnectionID(parentID, field.label);
|
|
186
|
-
var edgesField = field.edges;
|
|
187
|
-
var reference = {
|
|
188
|
-
variables: this._variables,
|
|
189
|
-
edgesField: edgesField,
|
|
190
|
-
id: connectionID,
|
|
191
|
-
label: field.label
|
|
192
|
-
};
|
|
193
|
-
data[RelayConnection.CONNECTION_KEY] = reference;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
268
|
_proto._readScalar = function _readScalar(field, record, data) {
|
|
197
269
|
var _field$alias;
|
|
198
270
|
|
|
@@ -225,10 +297,7 @@ function () {
|
|
|
225
297
|
}
|
|
226
298
|
|
|
227
299
|
var prevData = data[applicationName];
|
|
228
|
-
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0;
|
|
229
|
-
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
230
|
-
* suppresses an error found when Flow v0.98 was deployed. To see the error
|
|
231
|
-
* delete this comment and run Flow. */
|
|
300
|
+
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0; // $FlowFixMe[incompatible-variance]
|
|
232
301
|
|
|
233
302
|
data[applicationName] = this._traverse(field, linkedID, prevData);
|
|
234
303
|
};
|
|
@@ -259,10 +328,7 @@ function () {
|
|
|
259
328
|
if (linkedID == null) {
|
|
260
329
|
if (linkedID === undefined) {
|
|
261
330
|
_this._isMissingData = true;
|
|
262
|
-
}
|
|
263
|
-
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
264
|
-
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
265
|
-
* error delete this comment and run Flow. */
|
|
331
|
+
} // $FlowFixMe[cannot-write]
|
|
266
332
|
|
|
267
333
|
|
|
268
334
|
linkedArray[nextIndex] = linkedID;
|
|
@@ -270,10 +336,8 @@ function () {
|
|
|
270
336
|
}
|
|
271
337
|
|
|
272
338
|
var prevItem = linkedArray[nextIndex];
|
|
273
|
-
!(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevItem) : invariant(false) : void 0;
|
|
274
|
-
|
|
275
|
-
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
276
|
-
* error delete this comment and run Flow. */
|
|
339
|
+
!(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevItem) : invariant(false) : void 0; // $FlowFixMe[cannot-write]
|
|
340
|
+
// $FlowFixMe[incompatible-variance]
|
|
277
341
|
|
|
278
342
|
linkedArray[nextIndex] = _this._traverse(field, linkedID, prevItem);
|
|
279
343
|
});
|
|
@@ -325,11 +389,15 @@ function () {
|
|
|
325
389
|
|
|
326
390
|
if (data[ID_KEY] == null) {
|
|
327
391
|
data[ID_KEY] = RelayModernRecord.getDataID(record);
|
|
328
|
-
} // $FlowFixMe - writing into read-only field
|
|
392
|
+
} // $FlowFixMe[cannot-write] - writing into read-only field
|
|
329
393
|
|
|
330
394
|
|
|
331
395
|
fragmentPointers[fragmentSpread.name] = fragmentSpread.args ? getArgumentValues(fragmentSpread.args, this._variables) : {};
|
|
332
396
|
data[FRAGMENT_OWNER_KEY] = this._owner;
|
|
397
|
+
|
|
398
|
+
if (RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
|
|
399
|
+
data[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] = this._isWithinUnmatchedTypeRefinement;
|
|
400
|
+
}
|
|
333
401
|
};
|
|
334
402
|
|
|
335
403
|
_proto._createInlineDataFragmentPointer = function _createInlineDataFragmentPointer(inlineDataFragmentSpread, record, data) {
|
|
@@ -347,7 +415,7 @@ function () {
|
|
|
347
415
|
|
|
348
416
|
var inlineData = {};
|
|
349
417
|
|
|
350
|
-
this._traverseSelections(inlineDataFragmentSpread.selections, record, inlineData); // $FlowFixMe - writing into read-only field
|
|
418
|
+
this._traverseSelections(inlineDataFragmentSpread.selections, record, inlineData); // $FlowFixMe[cannot-write] - writing into read-only field
|
|
351
419
|
|
|
352
420
|
|
|
353
421
|
fragmentPointers[inlineDataFragmentSpread.name] = inlineData;
|
|
@@ -10,22 +10,15 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
14
|
-
|
|
15
13
|
var RelayRecordSourceMapImpl = require('./RelayRecordSourceMapImpl');
|
|
16
14
|
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
var RelayRecordSource =
|
|
20
|
-
/*#__PURE__*/
|
|
21
|
-
function () {
|
|
15
|
+
var RelayRecordSource = /*#__PURE__*/function () {
|
|
22
16
|
function RelayRecordSource(records) {
|
|
23
17
|
return RelayRecordSource.create(records);
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
RelayRecordSource.create = function create(records) {
|
|
27
|
-
|
|
28
|
-
return new RecordSourceImpl(records);
|
|
21
|
+
return new RelayRecordSourceMapImpl(records);
|
|
29
22
|
};
|
|
30
23
|
|
|
31
24
|
return RelayRecordSource;
|