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
|
@@ -13,11 +13,19 @@
|
|
|
13
13
|
|
|
14
14
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
17
|
|
|
18
18
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
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; } } }; }
|
|
25
|
+
|
|
26
|
+
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); }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
21
29
|
|
|
22
30
|
var RelayError = require('../util/RelayError');
|
|
23
31
|
|
|
@@ -56,13 +64,12 @@ function execute(config) {
|
|
|
56
64
|
*/
|
|
57
65
|
|
|
58
66
|
|
|
59
|
-
var Executor =
|
|
60
|
-
/*#__PURE__*/
|
|
61
|
-
function () {
|
|
67
|
+
var Executor = /*#__PURE__*/function () {
|
|
62
68
|
function Executor(_ref) {
|
|
63
69
|
var _this = this;
|
|
64
70
|
|
|
65
71
|
var operation = _ref.operation,
|
|
72
|
+
operationExecutions = _ref.operationExecutions,
|
|
66
73
|
operationLoader = _ref.operationLoader,
|
|
67
74
|
optimisticConfig = _ref.optimisticConfig,
|
|
68
75
|
publishQueue = _ref.publishQueue,
|
|
@@ -72,13 +79,16 @@ function () {
|
|
|
72
79
|
store = _ref.store,
|
|
73
80
|
updater = _ref.updater,
|
|
74
81
|
operationTracker = _ref.operationTracker,
|
|
82
|
+
treatMissingFieldsAsNull = _ref.treatMissingFieldsAsNull,
|
|
75
83
|
getDataID = _ref.getDataID,
|
|
76
84
|
isClientPayload = _ref.isClientPayload;
|
|
77
85
|
this._getDataID = getDataID;
|
|
86
|
+
this._treatMissingFieldsAsNull = treatMissingFieldsAsNull;
|
|
78
87
|
this._incrementalPayloadsPending = false;
|
|
79
88
|
this._incrementalResults = new Map();
|
|
80
89
|
this._nextSubscriptionId = 0;
|
|
81
90
|
this._operation = operation;
|
|
91
|
+
this._operationExecutions = operationExecutions;
|
|
82
92
|
this._operationLoader = operationLoader;
|
|
83
93
|
this._operationTracker = operationTracker;
|
|
84
94
|
this._operationUpdateEpochs = new Map();
|
|
@@ -116,7 +126,7 @@ function () {
|
|
|
116
126
|
if (optimisticConfig != null) {
|
|
117
127
|
this._processOptimisticResponse(optimisticConfig.response != null ? {
|
|
118
128
|
data: optimisticConfig.response
|
|
119
|
-
} : null, optimisticConfig.updater);
|
|
129
|
+
} : null, optimisticConfig.updater, false);
|
|
120
130
|
}
|
|
121
131
|
} // Cancel any pending execution tasks and mark the executor as completed.
|
|
122
132
|
|
|
@@ -132,6 +142,8 @@ function () {
|
|
|
132
142
|
|
|
133
143
|
this._state = 'completed';
|
|
134
144
|
|
|
145
|
+
this._operationExecutions["delete"](this._operation.request.identifier);
|
|
146
|
+
|
|
135
147
|
if (this._subscriptions.size !== 0) {
|
|
136
148
|
this._subscriptions.forEach(function (sub) {
|
|
137
149
|
return sub.unsubscribe();
|
|
@@ -156,6 +168,42 @@ function () {
|
|
|
156
168
|
this._completeOperationTracker();
|
|
157
169
|
};
|
|
158
170
|
|
|
171
|
+
_proto._updateActiveState = function _updateActiveState() {
|
|
172
|
+
var activeState;
|
|
173
|
+
|
|
174
|
+
switch (this._state) {
|
|
175
|
+
case 'started':
|
|
176
|
+
{
|
|
177
|
+
activeState = 'active';
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
case 'loading_incremental':
|
|
182
|
+
{
|
|
183
|
+
activeState = 'active';
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
case 'completed':
|
|
188
|
+
{
|
|
189
|
+
activeState = 'inactive';
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
case 'loading_final':
|
|
194
|
+
{
|
|
195
|
+
activeState = this._pendingModulePayloadsCount > 0 ? 'active' : 'inactive';
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
default:
|
|
200
|
+
this._state;
|
|
201
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernQueryExecutor: invalid executor state.') : invariant(false) : void 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
this._operationExecutions.set(this._operation.request.identifier, activeState);
|
|
205
|
+
};
|
|
206
|
+
|
|
159
207
|
_proto._schedule = function _schedule(task) {
|
|
160
208
|
var _this3 = this;
|
|
161
209
|
|
|
@@ -210,6 +258,8 @@ function () {
|
|
|
210
258
|
|
|
211
259
|
_proto._start = function _start(id, subscription) {
|
|
212
260
|
this._subscriptions.set(id, subscription);
|
|
261
|
+
|
|
262
|
+
this._updateActiveState();
|
|
213
263
|
} // Handle a raw GraphQL response.
|
|
214
264
|
;
|
|
215
265
|
|
|
@@ -223,69 +273,158 @@ function () {
|
|
|
223
273
|
});
|
|
224
274
|
};
|
|
225
275
|
|
|
226
|
-
_proto.
|
|
227
|
-
var
|
|
276
|
+
_proto._handleErrorResponse = function _handleErrorResponse(responses) {
|
|
277
|
+
var _this5 = this;
|
|
228
278
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
279
|
+
var results = [];
|
|
280
|
+
responses.forEach(function (response) {
|
|
281
|
+
if (response.data === null && response.extensions != null && !response.hasOwnProperty('errors')) {
|
|
282
|
+
// Skip extensions-only payloads
|
|
283
|
+
return;
|
|
284
|
+
} else if (response.data == null) {
|
|
285
|
+
// Error if any other payload in the batch is missing data, regardless of whether
|
|
286
|
+
// it had `errors` or not.
|
|
287
|
+
var errors = response.hasOwnProperty('errors') && response.errors != null ? response.errors : null;
|
|
288
|
+
var messages = errors ? errors.map(function (_ref2) {
|
|
289
|
+
var message = _ref2.message;
|
|
290
|
+
return message;
|
|
291
|
+
}).join('\n') : '(No errors)';
|
|
292
|
+
var error = RelayError.create('RelayNetwork', 'No data returned for operation `' + _this5._operation.request.node.params.name + '`, got error(s):\n' + messages + '\n\nSee the error `source` property for more information.');
|
|
293
|
+
error.source = {
|
|
294
|
+
errors: errors,
|
|
295
|
+
operation: _this5._operation.request.node,
|
|
296
|
+
variables: _this5._operation.request.variables
|
|
297
|
+
}; // In V8, Error objects keep the closure scope chain alive until the
|
|
298
|
+
// err.stack property is accessed.
|
|
299
|
+
|
|
300
|
+
error.stack;
|
|
301
|
+
throw error;
|
|
302
|
+
} else {
|
|
303
|
+
var responseWithData = response;
|
|
304
|
+
results.push(responseWithData);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
return results;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* This method return boolean to indicate if the optimistic
|
|
311
|
+
* response has been handled
|
|
312
|
+
*/
|
|
313
|
+
;
|
|
232
314
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var messages = errors ? errors.map(function (_ref2) {
|
|
236
|
-
var message = _ref2.message;
|
|
237
|
-
return message;
|
|
238
|
-
}).join('\n') : '(No errors)';
|
|
239
|
-
var error = RelayError.create('RelayNetwork', 'No data returned for operation `' + this._operation.request.node.params.name + '`, got error(s):\n' + messages + '\n\nSee the error `source` property for more information.');
|
|
240
|
-
error.source = {
|
|
241
|
-
errors: errors,
|
|
242
|
-
operation: this._operation.request.node,
|
|
243
|
-
variables: this._operation.request.variables
|
|
244
|
-
};
|
|
245
|
-
throw error;
|
|
246
|
-
} // Above check ensures that response.data != null
|
|
315
|
+
_proto._handleOptimisticResponses = function _handleOptimisticResponses(responses) {
|
|
316
|
+
var _response$extensions;
|
|
247
317
|
|
|
318
|
+
if (responses.length > 1) {
|
|
319
|
+
if (responses.some(function (responsePart) {
|
|
320
|
+
var _responsePart$extensi;
|
|
248
321
|
|
|
249
|
-
|
|
322
|
+
return ((_responsePart$extensi = responsePart.extensions) === null || _responsePart$extensi === void 0 ? void 0 : _responsePart$extensi.isOptimistic) === true;
|
|
323
|
+
})) {
|
|
324
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Optimistic responses cannot be batched.') : invariant(false) : void 0;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
var response = responses[0];
|
|
250
331
|
var isOptimistic = ((_response$extensions = response.extensions) === null || _response$extensions === void 0 ? void 0 : _response$extensions.isOptimistic) === true;
|
|
251
332
|
|
|
252
333
|
if (isOptimistic && this._state !== 'started') {
|
|
253
334
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernQueryExecutor: optimistic payload received after server payload.') : invariant(false) : void 0;
|
|
254
335
|
}
|
|
255
336
|
|
|
256
|
-
|
|
257
|
-
|
|
337
|
+
if (isOptimistic) {
|
|
338
|
+
this._processOptimisticResponse(response, null, this._treatMissingFieldsAsNull);
|
|
339
|
+
|
|
340
|
+
this._sink.next(response);
|
|
341
|
+
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return false;
|
|
346
|
+
};
|
|
258
347
|
|
|
259
|
-
|
|
260
|
-
|
|
348
|
+
_proto._handleNext = function _handleNext(response) {
|
|
349
|
+
if (this._state === 'completed') {
|
|
350
|
+
return;
|
|
261
351
|
}
|
|
262
352
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
353
|
+
var responses = Array.isArray(response) ? response : [response];
|
|
354
|
+
|
|
355
|
+
var responsesWithData = this._handleErrorResponse(responses);
|
|
356
|
+
|
|
357
|
+
if (responsesWithData.length === 0) {
|
|
358
|
+
// no results with data, nothing to process
|
|
359
|
+
// this can occur with extensions-only payloads
|
|
360
|
+
var isFinal = responses.some(function (x) {
|
|
361
|
+
var _x$extensions;
|
|
362
|
+
|
|
363
|
+
return ((_x$extensions = x.extensions) === null || _x$extensions === void 0 ? void 0 : _x$extensions.is_final) === true;
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
if (isFinal) {
|
|
367
|
+
this._state = 'loading_final';
|
|
368
|
+
|
|
369
|
+
this._updateActiveState();
|
|
370
|
+
|
|
371
|
+
this._incrementalPayloadsPending = false;
|
|
281
372
|
}
|
|
373
|
+
|
|
374
|
+
this._sink.next(response);
|
|
375
|
+
|
|
376
|
+
return;
|
|
377
|
+
} // Next, handle optimistic responses
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
var isOptimistic = this._handleOptimisticResponses(responsesWithData);
|
|
381
|
+
|
|
382
|
+
if (isOptimistic) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
var _partitionGraphQLResp = partitionGraphQLResponses(responsesWithData),
|
|
387
|
+
nonIncrementalResponses = _partitionGraphQLResp[0],
|
|
388
|
+
incrementalResponses = _partitionGraphQLResp[1]; // In theory this doesn't preserve the ordering of the batch.
|
|
389
|
+
// The idea is that a batch is always:
|
|
390
|
+
// * at-most one non-incremental payload
|
|
391
|
+
// * followed zero or more incremental payloads
|
|
392
|
+
// The non-incremental payload can appear if the server sends a batch
|
|
393
|
+
// w the initial payload followed by some early-to-resolve incremental
|
|
394
|
+
// payloads (although, can that even happen?)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
if (nonIncrementalResponses.length > 0) {
|
|
398
|
+
var payloadFollowups = this._processResponses(nonIncrementalResponses); // Please note, that we're passing `this._operation` to the publish
|
|
399
|
+
// queue here, which will later passed to the store (via notify)
|
|
400
|
+
// to indicate that this is an operation that cause the store to update
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
var updatedOwners = this._publishQueue.run(this._operation);
|
|
404
|
+
|
|
405
|
+
this._updateOperationTracker(updatedOwners);
|
|
406
|
+
|
|
407
|
+
this._processPayloadFollowups(payloadFollowups);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (incrementalResponses.length > 0) {
|
|
411
|
+
var _payloadFollowups = this._processIncrementalResponses(incrementalResponses); // For the incremental case, we're only handling follow-up responses
|
|
412
|
+
// for already initiated operation (and we're not passing it to
|
|
413
|
+
// the run(...) call)
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
var _updatedOwners = this._publishQueue.run();
|
|
417
|
+
|
|
418
|
+
this._updateOperationTracker(_updatedOwners);
|
|
419
|
+
|
|
420
|
+
this._processPayloadFollowups(_payloadFollowups);
|
|
282
421
|
}
|
|
283
422
|
|
|
284
423
|
this._sink.next(response);
|
|
285
424
|
};
|
|
286
425
|
|
|
287
|
-
_proto._processOptimisticResponse = function _processOptimisticResponse(response, updater) {
|
|
288
|
-
var
|
|
426
|
+
_proto._processOptimisticResponse = function _processOptimisticResponse(response, updater, treatMissingFieldsAsNull) {
|
|
427
|
+
var _this6 = this;
|
|
289
428
|
|
|
290
429
|
!(this._optimisticUpdates === null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'environment.execute: only support one optimistic response per ' + 'execute.') : invariant(false) : void 0;
|
|
291
430
|
|
|
@@ -299,7 +438,7 @@ function () {
|
|
|
299
438
|
var payload = normalizeResponse(response, this._operation.root, ROOT_TYPE, {
|
|
300
439
|
getDataID: this._getDataID,
|
|
301
440
|
path: [],
|
|
302
|
-
|
|
441
|
+
treatMissingFieldsAsNull: treatMissingFieldsAsNull
|
|
303
442
|
});
|
|
304
443
|
validateOptimisticResponsePayload(payload);
|
|
305
444
|
optimisticUpdates.push({
|
|
@@ -313,12 +452,12 @@ function () {
|
|
|
313
452
|
optimisticUpdates.push({
|
|
314
453
|
operation: this._operation,
|
|
315
454
|
payload: {
|
|
316
|
-
connectionEvents: null,
|
|
317
455
|
errors: null,
|
|
318
456
|
fieldPayloads: null,
|
|
319
457
|
incrementalPlaceholders: null,
|
|
320
458
|
moduleImportPayloads: null,
|
|
321
|
-
source: RelayRecordSource.create()
|
|
459
|
+
source: RelayRecordSource.create(),
|
|
460
|
+
isFinal: false
|
|
322
461
|
},
|
|
323
462
|
updater: updater
|
|
324
463
|
});
|
|
@@ -326,7 +465,7 @@ function () {
|
|
|
326
465
|
|
|
327
466
|
this._optimisticUpdates = optimisticUpdates;
|
|
328
467
|
optimisticUpdates.forEach(function (update) {
|
|
329
|
-
return
|
|
468
|
+
return _this6._publishQueue.applyUpdate(update);
|
|
330
469
|
});
|
|
331
470
|
|
|
332
471
|
this._publishQueue.run();
|
|
@@ -337,12 +476,12 @@ function () {
|
|
|
337
476
|
var moduleImportPayloads = payload.moduleImportPayloads;
|
|
338
477
|
var operationLoader = this._operationLoader;
|
|
339
478
|
!operationLoader ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected an operationLoader to be ' + 'configured when using `@match`.') : invariant(false) : void 0;
|
|
340
|
-
|
|
341
|
-
var
|
|
342
|
-
|
|
479
|
+
|
|
480
|
+
var _iterator = _createForOfIteratorHelper(moduleImportPayloads),
|
|
481
|
+
_step;
|
|
343
482
|
|
|
344
483
|
try {
|
|
345
|
-
for (
|
|
484
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
346
485
|
var moduleImportPayload = _step.value;
|
|
347
486
|
var operation = operationLoader.get(moduleImportPayload.operationReference);
|
|
348
487
|
|
|
@@ -355,18 +494,9 @@ function () {
|
|
|
355
494
|
}
|
|
356
495
|
}
|
|
357
496
|
} catch (err) {
|
|
358
|
-
|
|
359
|
-
_iteratorError = err;
|
|
497
|
+
_iterator.e(err);
|
|
360
498
|
} finally {
|
|
361
|
-
|
|
362
|
-
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
|
363
|
-
_iterator["return"]();
|
|
364
|
-
}
|
|
365
|
-
} finally {
|
|
366
|
-
if (_didIteratorError) {
|
|
367
|
-
throw _iteratorError;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
499
|
+
_iterator.f();
|
|
370
500
|
}
|
|
371
501
|
}
|
|
372
502
|
};
|
|
@@ -378,7 +508,7 @@ function () {
|
|
|
378
508
|
}, selector, moduleImportPayload.typeName, {
|
|
379
509
|
getDataID: this._getDataID,
|
|
380
510
|
path: moduleImportPayload.path,
|
|
381
|
-
|
|
511
|
+
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull
|
|
382
512
|
});
|
|
383
513
|
};
|
|
384
514
|
|
|
@@ -400,60 +530,59 @@ function () {
|
|
|
400
530
|
};
|
|
401
531
|
|
|
402
532
|
_proto._processAsyncOptimisticModuleImport = function _processAsyncOptimisticModuleImport(operationLoader, moduleImportPayload) {
|
|
403
|
-
var
|
|
533
|
+
var _this7 = this;
|
|
404
534
|
|
|
405
535
|
operationLoader.load(moduleImportPayload.operationReference).then(function (operation) {
|
|
406
|
-
if (operation == null ||
|
|
536
|
+
if (operation == null || _this7._state !== 'started') {
|
|
407
537
|
return;
|
|
408
538
|
}
|
|
409
539
|
|
|
410
|
-
var moduleImportOptimisitcUpdates =
|
|
540
|
+
var moduleImportOptimisitcUpdates = _this7._processOptimisticModuleImport(operation, moduleImportPayload);
|
|
411
541
|
|
|
412
542
|
moduleImportOptimisitcUpdates.forEach(function (update) {
|
|
413
|
-
return
|
|
543
|
+
return _this7._publishQueue.applyUpdate(update);
|
|
414
544
|
});
|
|
415
545
|
|
|
416
|
-
if (
|
|
417
|
-
process.env.NODE_ENV !== "production" ? warning(false, 'RelayModernQueryExecutor: Unexpected ModuleImport optimisitc ' + 'update in operation %s.' +
|
|
546
|
+
if (_this7._optimisticUpdates == null) {
|
|
547
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'RelayModernQueryExecutor: Unexpected ModuleImport optimisitc ' + 'update in operation %s.' + _this7._operation.request.node.params.name) : void 0;
|
|
418
548
|
} else {
|
|
419
549
|
var _this$_optimisticUpda;
|
|
420
550
|
|
|
421
|
-
(_this$_optimisticUpda =
|
|
551
|
+
(_this$_optimisticUpda = _this7._optimisticUpdates).push.apply(_this$_optimisticUpda, (0, _toConsumableArray2["default"])(moduleImportOptimisitcUpdates));
|
|
422
552
|
|
|
423
|
-
|
|
553
|
+
_this7._publishQueue.run();
|
|
424
554
|
}
|
|
425
555
|
});
|
|
426
556
|
};
|
|
427
557
|
|
|
428
|
-
_proto.
|
|
429
|
-
var
|
|
558
|
+
_proto._processResponses = function _processResponses(responses) {
|
|
559
|
+
var _this8 = this;
|
|
430
560
|
|
|
431
561
|
if (this._optimisticUpdates !== null) {
|
|
432
562
|
this._optimisticUpdates.forEach(function (update) {
|
|
433
|
-
return
|
|
563
|
+
return _this8._publishQueue.revertUpdate(update);
|
|
434
564
|
});
|
|
435
565
|
|
|
436
566
|
this._optimisticUpdates = null;
|
|
437
567
|
}
|
|
438
568
|
|
|
439
|
-
var payload = normalizeResponse(response, this._operation.root, ROOT_TYPE, {
|
|
440
|
-
getDataID: this._getDataID,
|
|
441
|
-
path: [],
|
|
442
|
-
request: this._operation.request
|
|
443
|
-
});
|
|
444
569
|
this._incrementalPayloadsPending = false;
|
|
445
570
|
|
|
446
571
|
this._incrementalResults.clear();
|
|
447
572
|
|
|
448
573
|
this._source.clear();
|
|
449
574
|
|
|
450
|
-
|
|
575
|
+
return responses.map(function (payloadPart) {
|
|
576
|
+
var relayPayload = normalizeResponse(payloadPart, _this8._operation.root, ROOT_TYPE, {
|
|
577
|
+
getDataID: _this8._getDataID,
|
|
578
|
+
treatMissingFieldsAsNull: _this8._treatMissingFieldsAsNull,
|
|
579
|
+
path: []
|
|
580
|
+
});
|
|
451
581
|
|
|
452
|
-
|
|
582
|
+
_this8._publishQueue.commitPayload(_this8._operation, relayPayload, _this8._updater);
|
|
453
583
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
this._processPayloadFollowups(payload);
|
|
584
|
+
return relayPayload;
|
|
585
|
+
});
|
|
457
586
|
}
|
|
458
587
|
/**
|
|
459
588
|
* Handles any follow-up actions for a Relay payload for @match, @defer,
|
|
@@ -461,47 +590,67 @@ function () {
|
|
|
461
590
|
*/
|
|
462
591
|
;
|
|
463
592
|
|
|
464
|
-
_proto._processPayloadFollowups = function _processPayloadFollowups(
|
|
465
|
-
var
|
|
593
|
+
_proto._processPayloadFollowups = function _processPayloadFollowups(payloads) {
|
|
594
|
+
var _this9 = this;
|
|
466
595
|
|
|
467
596
|
if (this._state === 'completed') {
|
|
468
597
|
return;
|
|
469
598
|
}
|
|
470
599
|
|
|
471
|
-
|
|
472
|
-
|
|
600
|
+
payloads.forEach(function (payload) {
|
|
601
|
+
var incrementalPlaceholders = payload.incrementalPlaceholders,
|
|
602
|
+
moduleImportPayloads = payload.moduleImportPayloads,
|
|
603
|
+
isFinal = payload.isFinal;
|
|
604
|
+
_this9._state = isFinal ? 'loading_final' : 'loading_incremental';
|
|
473
605
|
|
|
474
|
-
|
|
475
|
-
var operationLoader = this._operationLoader;
|
|
476
|
-
!operationLoader ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected an operationLoader to be ' + 'configured when using `@match`.') : invariant(false) : void 0;
|
|
477
|
-
moduleImportPayloads.forEach(function (moduleImportPayload) {
|
|
478
|
-
_this8._processModuleImportPayload(moduleImportPayload, operationLoader);
|
|
479
|
-
});
|
|
480
|
-
}
|
|
606
|
+
_this9._updateActiveState();
|
|
481
607
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
_this8._processIncrementalPlaceholder(payload, incrementalPlaceholder);
|
|
486
|
-
});
|
|
608
|
+
if (isFinal) {
|
|
609
|
+
_this9._incrementalPayloadsPending = false;
|
|
610
|
+
}
|
|
487
611
|
|
|
488
|
-
if (
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
// with incremental delivery disabled.
|
|
494
|
-
process.env.NODE_ENV !== "production" ? warning(this._isClientPayload, 'RelayModernEnvironment: Operation `%s` contains @defer/@stream ' + 'directives but was executed in non-streaming mode. See ' + 'https://fburl.com/relay-incremental-delivery-non-streaming-warning.', this._operation.request.node.params.name) : void 0; // But eagerly process any deferred payloads
|
|
495
|
-
|
|
496
|
-
incrementalPlaceholders.forEach(function (placeholder) {
|
|
497
|
-
if (placeholder.kind === 'defer') {
|
|
498
|
-
_this8._processDeferResponse(placeholder.label, placeholder.path, placeholder, {
|
|
499
|
-
data: placeholder.data
|
|
500
|
-
});
|
|
501
|
-
}
|
|
612
|
+
if (moduleImportPayloads && moduleImportPayloads.length !== 0) {
|
|
613
|
+
var operationLoader = _this9._operationLoader;
|
|
614
|
+
!operationLoader ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected an operationLoader to be ' + 'configured when using `@match`.') : invariant(false) : void 0;
|
|
615
|
+
moduleImportPayloads.forEach(function (moduleImportPayload) {
|
|
616
|
+
_this9._processModuleImportPayload(moduleImportPayload, operationLoader);
|
|
502
617
|
});
|
|
503
618
|
}
|
|
504
|
-
|
|
619
|
+
|
|
620
|
+
if (incrementalPlaceholders && incrementalPlaceholders.length !== 0) {
|
|
621
|
+
_this9._incrementalPayloadsPending = _this9._state !== 'loading_final';
|
|
622
|
+
incrementalPlaceholders.forEach(function (incrementalPlaceholder) {
|
|
623
|
+
_this9._processIncrementalPlaceholder(payload, incrementalPlaceholder);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
if (_this9._isClientPayload || _this9._state === 'loading_final') {
|
|
627
|
+
// The query has defer/stream selections that are enabled, but either
|
|
628
|
+
// the server indicated that this is a "final" payload: no incremental
|
|
629
|
+
// payloads will be delivered, then warn that the query was (likely)
|
|
630
|
+
// executed on the server in non-streaming mode, with incremental
|
|
631
|
+
// delivery disabled; or this is a client payload, and there will be
|
|
632
|
+
// no incremental payload.
|
|
633
|
+
process.env.NODE_ENV !== "production" ? warning(_this9._isClientPayload, 'RelayModernEnvironment: Operation `%s` contains @defer/@stream ' + 'directives but was executed in non-streaming mode. See ' + 'https://fburl.com/relay-incremental-delivery-non-streaming-warning.', _this9._operation.request.node.params.name) : void 0; // But eagerly process any deferred payloads
|
|
634
|
+
|
|
635
|
+
var relayPayloads = [];
|
|
636
|
+
incrementalPlaceholders.forEach(function (placeholder) {
|
|
637
|
+
if (placeholder.kind === 'defer') {
|
|
638
|
+
relayPayloads.push(_this9._processDeferResponse(placeholder.label, placeholder.path, placeholder, {
|
|
639
|
+
data: placeholder.data
|
|
640
|
+
}));
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
if (relayPayloads.length > 0) {
|
|
645
|
+
var updatedOwners = _this9._publishQueue.run();
|
|
646
|
+
|
|
647
|
+
_this9._updateOperationTracker(updatedOwners);
|
|
648
|
+
|
|
649
|
+
_this9._processPayloadFollowups(relayPayloads);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
});
|
|
505
654
|
};
|
|
506
655
|
|
|
507
656
|
_proto._maybeCompleteSubscriptionOperationTracking = function _maybeCompleteSubscriptionOperationTracking() {
|
|
@@ -525,18 +674,16 @@ function () {
|
|
|
525
674
|
;
|
|
526
675
|
|
|
527
676
|
_proto._processModuleImportPayload = function _processModuleImportPayload(moduleImportPayload, operationLoader) {
|
|
528
|
-
var
|
|
677
|
+
var _this10 = this;
|
|
529
678
|
|
|
530
679
|
var syncOperation = operationLoader.get(moduleImportPayload.operationReference);
|
|
531
680
|
|
|
532
681
|
if (syncOperation != null) {
|
|
533
682
|
// If the operation module is available synchronously, normalize the
|
|
534
683
|
// data synchronously.
|
|
535
|
-
this.
|
|
536
|
-
_this9._handleModuleImportPayload(moduleImportPayload, syncOperation);
|
|
684
|
+
this._handleModuleImportPayload(moduleImportPayload, syncOperation);
|
|
537
685
|
|
|
538
|
-
|
|
539
|
-
});
|
|
686
|
+
this._maybeCompleteSubscriptionOperationTracking();
|
|
540
687
|
} else {
|
|
541
688
|
// Otherwise load the operation module and schedule a task to normalize
|
|
542
689
|
// the data when the module is available.
|
|
@@ -545,9 +692,9 @@ function () {
|
|
|
545
692
|
this._pendingModulePayloadsCount++;
|
|
546
693
|
|
|
547
694
|
var decrementPendingCount = function decrementPendingCount() {
|
|
548
|
-
|
|
695
|
+
_this10._pendingModulePayloadsCount--;
|
|
549
696
|
|
|
550
|
-
|
|
697
|
+
_this10._maybeCompleteSubscriptionOperationTracking();
|
|
551
698
|
}; // Observable.from(operationLoader.load()) wouldn't catch synchronous
|
|
552
699
|
// errors thrown by the load function, which is user-defined. Guard
|
|
553
700
|
// against that with Observable.from(new Promise(<work>)).
|
|
@@ -557,23 +704,23 @@ function () {
|
|
|
557
704
|
operationLoader.load(moduleImportPayload.operationReference).then(resolve, reject);
|
|
558
705
|
})).map(function (operation) {
|
|
559
706
|
if (operation != null) {
|
|
560
|
-
|
|
561
|
-
|
|
707
|
+
_this10._schedule(function () {
|
|
708
|
+
_this10._handleModuleImportPayload(moduleImportPayload, operation);
|
|
562
709
|
});
|
|
563
710
|
}
|
|
564
711
|
}).subscribe({
|
|
565
712
|
complete: function complete() {
|
|
566
|
-
|
|
713
|
+
_this10._complete(_id3);
|
|
567
714
|
|
|
568
715
|
decrementPendingCount();
|
|
569
716
|
},
|
|
570
717
|
error: function error(_error4) {
|
|
571
|
-
|
|
718
|
+
_this10._error(_error4);
|
|
572
719
|
|
|
573
720
|
decrementPendingCount();
|
|
574
721
|
},
|
|
575
722
|
start: function start(subscription) {
|
|
576
|
-
return
|
|
723
|
+
return _this10._start(_id3, subscription);
|
|
577
724
|
}
|
|
578
725
|
});
|
|
579
726
|
}
|
|
@@ -588,7 +735,7 @@ function () {
|
|
|
588
735
|
|
|
589
736
|
this._updateOperationTracker(updatedOwners);
|
|
590
737
|
|
|
591
|
-
this._processPayloadFollowups(relayPayload);
|
|
738
|
+
this._processPayloadFollowups([relayPayload]);
|
|
592
739
|
}
|
|
593
740
|
/**
|
|
594
741
|
* The executor now knows that GraphQL responses are expected for a given
|
|
@@ -604,8 +751,6 @@ function () {
|
|
|
604
751
|
;
|
|
605
752
|
|
|
606
753
|
_proto._processIncrementalPlaceholder = function _processIncrementalPlaceholder(relayPayload, placeholder) {
|
|
607
|
-
var _this10 = this;
|
|
608
|
-
|
|
609
754
|
var _relayPayload$fieldPa;
|
|
610
755
|
|
|
611
756
|
// Update the label => path => placeholder map
|
|
@@ -632,9 +777,9 @@ function () {
|
|
|
632
777
|
|
|
633
778
|
var parentID;
|
|
634
779
|
|
|
635
|
-
if (placeholder.kind === 'stream'
|
|
780
|
+
if (placeholder.kind === 'stream') {
|
|
636
781
|
parentID = placeholder.parentID;
|
|
637
|
-
} else if (placeholder.kind === 'defer'
|
|
782
|
+
} else if (placeholder.kind === 'defer') {
|
|
638
783
|
parentID = placeholder.selector.dataID;
|
|
639
784
|
} else {
|
|
640
785
|
placeholder;
|
|
@@ -685,11 +830,13 @@ function () {
|
|
|
685
830
|
|
|
686
831
|
|
|
687
832
|
if (pendingResponses != null) {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
833
|
+
var payloadFollowups = this._processIncrementalResponses(pendingResponses);
|
|
834
|
+
|
|
835
|
+
var updatedOwners = this._publishQueue.run();
|
|
836
|
+
|
|
837
|
+
this._updateOperationTracker(updatedOwners);
|
|
838
|
+
|
|
839
|
+
this._processPayloadFollowups(payloadFollowups);
|
|
693
840
|
}
|
|
694
841
|
}
|
|
695
842
|
/**
|
|
@@ -699,131 +846,70 @@ function () {
|
|
|
699
846
|
*/
|
|
700
847
|
;
|
|
701
848
|
|
|
702
|
-
_proto.
|
|
703
|
-
var
|
|
704
|
-
path = incrementalResponse.path,
|
|
705
|
-
response = incrementalResponse.response;
|
|
706
|
-
|
|
707
|
-
var resultForLabel = this._incrementalResults.get(label);
|
|
849
|
+
_proto._processIncrementalResponses = function _processIncrementalResponses(incrementalResponses) {
|
|
850
|
+
var _this11 = this;
|
|
708
851
|
|
|
709
|
-
|
|
710
|
-
|
|
852
|
+
var relayPayloads = [];
|
|
853
|
+
incrementalResponses.forEach(function (incrementalResponse) {
|
|
854
|
+
var label = incrementalResponse.label,
|
|
855
|
+
path = incrementalResponse.path,
|
|
856
|
+
response = incrementalResponse.response;
|
|
711
857
|
|
|
712
|
-
|
|
713
|
-
}
|
|
858
|
+
var resultForLabel = _this11._incrementalResults.get(label);
|
|
714
859
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
var resultForPath = resultForLabel.get(pathKey);
|
|
860
|
+
if (resultForLabel == null) {
|
|
861
|
+
resultForLabel = new Map();
|
|
718
862
|
|
|
719
|
-
|
|
720
|
-
resultForPath = {
|
|
721
|
-
kind: 'response',
|
|
722
|
-
responses: [incrementalResponse]
|
|
723
|
-
};
|
|
724
|
-
resultForLabel.set(pathKey, resultForPath);
|
|
725
|
-
return;
|
|
726
|
-
} else if (resultForPath.kind === 'response') {
|
|
727
|
-
resultForPath.responses.push(incrementalResponse);
|
|
728
|
-
return;
|
|
863
|
+
_this11._incrementalResults.set(label, resultForLabel);
|
|
729
864
|
}
|
|
730
865
|
|
|
731
|
-
|
|
866
|
+
if (label.indexOf('$defer$') !== -1) {
|
|
867
|
+
var pathKey = path.map(String).join('.');
|
|
868
|
+
var resultForPath = resultForLabel.get(pathKey);
|
|
869
|
+
|
|
870
|
+
if (resultForPath == null) {
|
|
871
|
+
resultForPath = {
|
|
872
|
+
kind: 'response',
|
|
873
|
+
responses: [incrementalResponse]
|
|
874
|
+
};
|
|
875
|
+
resultForLabel.set(pathKey, resultForPath);
|
|
876
|
+
return;
|
|
877
|
+
} else if (resultForPath.kind === 'response') {
|
|
878
|
+
resultForPath.responses.push(incrementalResponse);
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
732
881
|
|
|
733
|
-
|
|
734
|
-
this._processConnectionPageInfoResponse(label, path, placeholder, response);
|
|
735
|
-
} else {
|
|
882
|
+
var placeholder = resultForPath.placeholder;
|
|
736
883
|
!(placeholder.kind === 'defer') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected data for path `%s` for label `%s` ' + 'to be data for @defer, was `@%s`.', pathKey, label, placeholder.kind) : invariant(false) : void 0;
|
|
737
|
-
|
|
738
|
-
this._processDeferResponse(label, path, placeholder, response);
|
|
739
|
-
}
|
|
740
|
-
} else {
|
|
741
|
-
// @stream payload path values end in the field name and item index,
|
|
742
|
-
// but Relay records paths relative to the parent of the stream node:
|
|
743
|
-
// therefore we strip the last two elements just to lookup the path
|
|
744
|
-
// (the item index is used later to insert the element in the list)
|
|
745
|
-
var _pathKey = path.slice(0, -2).map(String).join('.');
|
|
746
|
-
|
|
747
|
-
var _resultForPath = resultForLabel.get(_pathKey);
|
|
748
|
-
|
|
749
|
-
if (_resultForPath == null) {
|
|
750
|
-
_resultForPath = {
|
|
751
|
-
kind: 'response',
|
|
752
|
-
responses: [incrementalResponse]
|
|
753
|
-
};
|
|
754
|
-
resultForLabel.set(_pathKey, _resultForPath);
|
|
755
|
-
return;
|
|
756
|
-
} else if (_resultForPath.kind === 'response') {
|
|
757
|
-
_resultForPath.responses.push(incrementalResponse);
|
|
758
|
-
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
var _placeholder = _resultForPath.placeholder;
|
|
763
|
-
|
|
764
|
-
if (_placeholder.kind === 'connection_edge') {
|
|
765
|
-
this._processConnectionEdgeResponse(label, path, _placeholder, response);
|
|
884
|
+
relayPayloads.push(_this11._processDeferResponse(label, path, placeholder, response));
|
|
766
885
|
} else {
|
|
767
|
-
|
|
886
|
+
// @stream payload path values end in the field name and item index,
|
|
887
|
+
// but Relay records paths relative to the parent of the stream node:
|
|
888
|
+
// therefore we strip the last two elements just to lookup the path
|
|
889
|
+
// (the item index is used later to insert the element in the list)
|
|
890
|
+
var _pathKey = path.slice(0, -2).map(String).join('.');
|
|
891
|
+
|
|
892
|
+
var _resultForPath = resultForLabel.get(_pathKey);
|
|
893
|
+
|
|
894
|
+
if (_resultForPath == null) {
|
|
895
|
+
_resultForPath = {
|
|
896
|
+
kind: 'response',
|
|
897
|
+
responses: [incrementalResponse]
|
|
898
|
+
};
|
|
899
|
+
resultForLabel.set(_pathKey, _resultForPath);
|
|
900
|
+
return;
|
|
901
|
+
} else if (_resultForPath.kind === 'response') {
|
|
902
|
+
_resultForPath.responses.push(incrementalResponse);
|
|
903
|
+
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
768
906
|
|
|
769
|
-
|
|
907
|
+
var _placeholder = _resultForPath.placeholder;
|
|
908
|
+
!(_placeholder.kind === 'stream') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected data for path `%s` for label `%s` ' + 'to be data for @stream, was `@%s`.', _pathKey, label, _placeholder.kind) : invariant(false) : void 0;
|
|
909
|
+
relayPayloads.push(_this11._processStreamResponse(label, path, _placeholder, response));
|
|
770
910
|
}
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
|
|
774
|
-
_proto._processConnectionPageInfoResponse = function _processConnectionPageInfoResponse(label, path, placeholder, response) {
|
|
775
|
-
var _relayPayload$connect;
|
|
776
|
-
|
|
777
|
-
var relayPayload = normalizeResponse(response, placeholder.selector, placeholder.typeName, {
|
|
778
|
-
getDataID: this._getDataID,
|
|
779
|
-
path: placeholder.path,
|
|
780
|
-
request: this._operation.request
|
|
781
911
|
});
|
|
782
|
-
|
|
783
|
-
var _RelayConnectionInter = RelayConnectionInterface.get(),
|
|
784
|
-
END_CURSOR = _RelayConnectionInter.END_CURSOR,
|
|
785
|
-
HAS_NEXT_PAGE = _RelayConnectionInter.HAS_NEXT_PAGE,
|
|
786
|
-
HAS_PREV_PAGE = _RelayConnectionInter.HAS_PREV_PAGE,
|
|
787
|
-
PAGE_INFO = _RelayConnectionInter.PAGE_INFO,
|
|
788
|
-
START_CURSOR = _RelayConnectionInter.START_CURSOR;
|
|
789
|
-
|
|
790
|
-
var pageRecord = relayPayload.source.get(placeholder.selector.dataID);
|
|
791
|
-
var pageInfoID = pageRecord != null ? RelayModernRecord.getLinkedRecordID(pageRecord, PAGE_INFO) : null;
|
|
792
|
-
var pageInfoRecord = pageInfoID != null ? relayPayload.source.get(pageInfoID) : null;
|
|
793
|
-
var endCursor;
|
|
794
|
-
var hasNextPage;
|
|
795
|
-
var hasPrevPage;
|
|
796
|
-
var startCursor;
|
|
797
|
-
|
|
798
|
-
if (pageInfoRecord != null) {
|
|
799
|
-
endCursor = RelayModernRecord.getValue(pageInfoRecord, END_CURSOR);
|
|
800
|
-
hasNextPage = RelayModernRecord.getValue(pageInfoRecord, HAS_NEXT_PAGE);
|
|
801
|
-
hasPrevPage = RelayModernRecord.getValue(pageInfoRecord, HAS_PREV_PAGE);
|
|
802
|
-
startCursor = RelayModernRecord.getValue(pageInfoRecord, START_CURSOR);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
relayPayload = (0, _objectSpread2["default"])({}, relayPayload, {
|
|
806
|
-
connectionEvents: ((_relayPayload$connect = relayPayload.connectionEvents) !== null && _relayPayload$connect !== void 0 ? _relayPayload$connect : []).concat({
|
|
807
|
-
kind: 'stream.pageInfo',
|
|
808
|
-
args: placeholder.args,
|
|
809
|
-
connectionID: placeholder.connectionID,
|
|
810
|
-
pageInfo: {
|
|
811
|
-
endCursor: typeof endCursor === 'string' ? endCursor : null,
|
|
812
|
-
startCursor: typeof startCursor === 'string' ? startCursor : null,
|
|
813
|
-
hasNextPage: typeof hasNextPage === 'boolean' ? hasNextPage : null,
|
|
814
|
-
hasPrevPage: typeof hasPrevPage === 'boolean' ? hasPrevPage : null
|
|
815
|
-
},
|
|
816
|
-
request: this._operation.request
|
|
817
|
-
})
|
|
818
|
-
});
|
|
819
|
-
|
|
820
|
-
this._publishQueue.commitPayload(this._operation, relayPayload);
|
|
821
|
-
|
|
822
|
-
var updatedOwners = this._publishQueue.run();
|
|
823
|
-
|
|
824
|
-
this._updateOperationTracker(updatedOwners);
|
|
825
|
-
|
|
826
|
-
this._processPayloadFollowups(relayPayload);
|
|
912
|
+
return relayPayloads;
|
|
827
913
|
};
|
|
828
914
|
|
|
829
915
|
_proto._processDeferResponse = function _processDeferResponse(label, path, placeholder, response) {
|
|
@@ -831,7 +917,7 @@ function () {
|
|
|
831
917
|
var relayPayload = normalizeResponse(response, placeholder.selector, placeholder.typeName, {
|
|
832
918
|
getDataID: this._getDataID,
|
|
833
919
|
path: placeholder.path,
|
|
834
|
-
|
|
920
|
+
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull
|
|
835
921
|
});
|
|
836
922
|
|
|
837
923
|
this._publishQueue.commitPayload(this._operation, relayPayload); // Load the version of the parent record from which this incremental data
|
|
@@ -844,55 +930,21 @@ function () {
|
|
|
844
930
|
var fieldPayloads = parentEntry.fieldPayloads;
|
|
845
931
|
|
|
846
932
|
if (fieldPayloads.length !== 0) {
|
|
933
|
+
var _response$extensions2;
|
|
934
|
+
|
|
847
935
|
var handleFieldsRelayPayload = {
|
|
848
|
-
connectionEvents: null,
|
|
849
936
|
errors: null,
|
|
850
937
|
fieldPayloads: fieldPayloads,
|
|
851
938
|
incrementalPlaceholders: null,
|
|
852
939
|
moduleImportPayloads: null,
|
|
853
|
-
source: RelayRecordSource.create()
|
|
940
|
+
source: RelayRecordSource.create(),
|
|
941
|
+
isFinal: ((_response$extensions2 = response.extensions) === null || _response$extensions2 === void 0 ? void 0 : _response$extensions2.is_final) === true
|
|
854
942
|
};
|
|
855
943
|
|
|
856
944
|
this._publishQueue.commitPayload(this._operation, handleFieldsRelayPayload);
|
|
857
945
|
}
|
|
858
946
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
this._updateOperationTracker(updatedOwners);
|
|
862
|
-
|
|
863
|
-
this._processPayloadFollowups(relayPayload);
|
|
864
|
-
};
|
|
865
|
-
|
|
866
|
-
_proto._processConnectionEdgeResponse = function _processConnectionEdgeResponse(label, path, placeholder, response) {
|
|
867
|
-
var _relayPayload$connect2;
|
|
868
|
-
|
|
869
|
-
var parentID = placeholder.parentID,
|
|
870
|
-
node = placeholder.node,
|
|
871
|
-
variables = placeholder.variables;
|
|
872
|
-
|
|
873
|
-
var _this$_normalizeStrea = this._normalizeStreamItem(response, parentID, node, variables, path, placeholder.path),
|
|
874
|
-
relayPayload = _this$_normalizeStrea.relayPayload,
|
|
875
|
-
itemID = _this$_normalizeStrea.itemID,
|
|
876
|
-
itemIndex = _this$_normalizeStrea.itemIndex;
|
|
877
|
-
|
|
878
|
-
relayPayload = (0, _objectSpread2["default"])({}, relayPayload, {
|
|
879
|
-
connectionEvents: ((_relayPayload$connect2 = relayPayload.connectionEvents) !== null && _relayPayload$connect2 !== void 0 ? _relayPayload$connect2 : []).concat({
|
|
880
|
-
kind: 'stream.edge',
|
|
881
|
-
args: placeholder.args,
|
|
882
|
-
connectionID: placeholder.connectionID,
|
|
883
|
-
edgeID: itemID,
|
|
884
|
-
index: itemIndex,
|
|
885
|
-
request: this._operation.request
|
|
886
|
-
})
|
|
887
|
-
});
|
|
888
|
-
|
|
889
|
-
this._publishQueue.commitPayload(this._operation, relayPayload);
|
|
890
|
-
|
|
891
|
-
var updatedOwners = this._publishQueue.run();
|
|
892
|
-
|
|
893
|
-
this._updateOperationTracker(updatedOwners);
|
|
894
|
-
|
|
895
|
-
this._processPayloadFollowups(relayPayload);
|
|
947
|
+
return relayPayload;
|
|
896
948
|
}
|
|
897
949
|
/**
|
|
898
950
|
* Process the data for one item in a @stream field.
|
|
@@ -907,13 +959,13 @@ function () {
|
|
|
907
959
|
var field = node.selections[0];
|
|
908
960
|
!(field != null && field.kind === 'LinkedField' && field.plural === true) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected @stream to be used on a plural field.') : invariant(false) : void 0;
|
|
909
961
|
|
|
910
|
-
var _this$
|
|
911
|
-
fieldPayloads = _this$
|
|
912
|
-
itemID = _this$
|
|
913
|
-
itemIndex = _this$
|
|
914
|
-
prevIDs = _this$
|
|
915
|
-
relayPayload = _this$
|
|
916
|
-
storageKey = _this$
|
|
962
|
+
var _this$_normalizeStrea = this._normalizeStreamItem(response, parentID, field, variables, path, placeholder.path),
|
|
963
|
+
fieldPayloads = _this$_normalizeStrea.fieldPayloads,
|
|
964
|
+
itemID = _this$_normalizeStrea.itemID,
|
|
965
|
+
itemIndex = _this$_normalizeStrea.itemIndex,
|
|
966
|
+
prevIDs = _this$_normalizeStrea.prevIDs,
|
|
967
|
+
relayPayload = _this$_normalizeStrea.relayPayload,
|
|
968
|
+
storageKey = _this$_normalizeStrea.storageKey; // Publish the new item and update the parent record to set
|
|
917
969
|
// field[index] = item *if* the parent record hasn't been concurrently
|
|
918
970
|
// modified.
|
|
919
971
|
|
|
@@ -952,22 +1004,18 @@ function () {
|
|
|
952
1004
|
|
|
953
1005
|
if (fieldPayloads.length !== 0) {
|
|
954
1006
|
var handleFieldsRelayPayload = {
|
|
955
|
-
connectionEvents: null,
|
|
956
1007
|
errors: null,
|
|
957
1008
|
fieldPayloads: fieldPayloads,
|
|
958
1009
|
incrementalPlaceholders: null,
|
|
959
1010
|
moduleImportPayloads: null,
|
|
960
|
-
source: RelayRecordSource.create()
|
|
1011
|
+
source: RelayRecordSource.create(),
|
|
1012
|
+
isFinal: false
|
|
961
1013
|
};
|
|
962
1014
|
|
|
963
1015
|
this._publishQueue.commitPayload(this._operation, handleFieldsRelayPayload);
|
|
964
1016
|
}
|
|
965
1017
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
this._updateOperationTracker(updatedOwners);
|
|
969
|
-
|
|
970
|
-
this._processPayloadFollowups(relayPayload);
|
|
1018
|
+
return relayPayload;
|
|
971
1019
|
};
|
|
972
1020
|
|
|
973
1021
|
_proto._normalizeStreamItem = function _normalizeStreamItem(response, parentID, field, variables, path, normalizationPath) {
|
|
@@ -1020,7 +1068,7 @@ function () {
|
|
|
1020
1068
|
var relayPayload = normalizeResponse(response, selector, typeName, {
|
|
1021
1069
|
getDataID: this._getDataID,
|
|
1022
1070
|
path: [].concat((0, _toConsumableArray2["default"])(normalizationPath), [responseKey, String(itemIndex)]),
|
|
1023
|
-
|
|
1071
|
+
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull
|
|
1024
1072
|
});
|
|
1025
1073
|
return {
|
|
1026
1074
|
fieldPayloads: fieldPayloads,
|
|
@@ -1047,15 +1095,42 @@ function () {
|
|
|
1047
1095
|
return Executor;
|
|
1048
1096
|
}();
|
|
1049
1097
|
|
|
1098
|
+
function partitionGraphQLResponses(responses) {
|
|
1099
|
+
var nonIncrementalResponses = [];
|
|
1100
|
+
var incrementalResponses = [];
|
|
1101
|
+
responses.forEach(function (response) {
|
|
1102
|
+
if (response.path != null || response.label != null) {
|
|
1103
|
+
var label = response.label,
|
|
1104
|
+
path = response.path;
|
|
1105
|
+
|
|
1106
|
+
if (label == null || path == null) {
|
|
1107
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernQueryExecutor: invalid incremental payload, expected ' + '`path` and `label` to either both be null/undefined, or ' + '`path` to be an `Array<string | number>` and `label` to be a ' + '`string`.') : invariant(false) : void 0;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
incrementalResponses.push({
|
|
1111
|
+
label: label,
|
|
1112
|
+
path: path,
|
|
1113
|
+
response: response
|
|
1114
|
+
});
|
|
1115
|
+
} else {
|
|
1116
|
+
nonIncrementalResponses.push(response);
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
return [nonIncrementalResponses, incrementalResponses];
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1050
1122
|
function normalizeResponse(response, selector, typeName, options) {
|
|
1123
|
+
var _response$extensions3;
|
|
1124
|
+
|
|
1051
1125
|
var data = response.data,
|
|
1052
1126
|
errors = response.errors;
|
|
1053
1127
|
var source = RelayRecordSource.create();
|
|
1054
1128
|
var record = RelayModernRecord.create(selector.dataID, typeName);
|
|
1055
1129
|
source.set(selector.dataID, record);
|
|
1056
1130
|
var relayPayload = RelayResponseNormalizer.normalize(source, selector, data, options);
|
|
1057
|
-
return (
|
|
1058
|
-
errors: errors
|
|
1131
|
+
return _objectSpread({}, relayPayload, {
|
|
1132
|
+
errors: errors,
|
|
1133
|
+
isFinal: ((_response$extensions3 = response.extensions) === null || _response$extensions3 === void 0 ? void 0 : _response$extensions3.is_final) === true
|
|
1059
1134
|
});
|
|
1060
1135
|
}
|
|
1061
1136
|
|