relay-runtime 18.2.0 → 20.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/experimental.js +1 -1
- package/experimental.js.flow +8 -6
- package/index.js +1 -1
- package/index.js.flow +3 -0
- package/lib/experimental.js +5 -2
- package/lib/index.js +3 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +2 -1
- package/lib/mutations/createUpdatableProxy.js +1 -1
- package/lib/mutations/validateMutation.js +2 -2
- package/lib/network/RelayObservable.js +1 -3
- package/lib/network/wrapNetworkWithLogObserver.js +2 -2
- package/lib/query/fetchQuery.js +1 -1
- package/lib/store/DataChecker.js +12 -8
- package/lib/store/OperationExecutor.js +93 -43
- package/lib/store/RelayModernEnvironment.js +13 -4
- package/lib/store/RelayModernFragmentSpecResolver.js +4 -4
- package/lib/store/RelayModernStore.js +49 -24
- package/lib/store/RelayPublishQueue.js +11 -15
- package/lib/store/RelayReader.js +134 -151
- package/lib/store/RelayReferenceMarker.js +14 -7
- package/lib/store/RelayResponseNormalizer.js +57 -31
- package/lib/store/RelayStoreSubscriptions.js +2 -2
- package/lib/store/RelayStoreUtils.js +8 -0
- package/lib/store/ResolverFragments.js +2 -2
- package/lib/store/createRelayLoggingContext.js +17 -0
- package/lib/store/generateTypenamePrefixedDataID.js +9 -0
- package/lib/store/live-resolvers/LiveResolverCache.js +4 -2
- package/lib/store/live-resolvers/resolverDataInjector.js +4 -4
- package/lib/store/normalizeResponse.js +2 -2
- package/lib/store/observeFragmentExperimental.js +60 -13
- package/lib/store/observeQueryExperimental.js +21 -0
- package/lib/util/RelayFeatureFlags.js +7 -1
- package/lib/util/handlePotentialSnapshotErrors.js +11 -8
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +1 -0
- package/mutations/RelayRecordSourceProxy.js.flow +4 -0
- package/mutations/createUpdatableProxy.js.flow +1 -1
- package/mutations/validateMutation.js.flow +3 -3
- package/network/RelayNetworkTypes.js.flow +3 -0
- package/network/RelayObservable.js.flow +1 -5
- package/network/wrapNetworkWithLogObserver.js.flow +19 -1
- package/package.json +1 -1
- package/query/fetchQuery.js.flow +1 -1
- package/store/DataChecker.js.flow +16 -4
- package/store/OperationExecutor.js.flow +101 -15
- package/store/RelayExperimentalGraphResponseTransform.js.flow +4 -4
- package/store/RelayModernEnvironment.js.flow +22 -6
- package/store/RelayModernFragmentSpecResolver.js.flow +6 -6
- package/store/RelayModernSelector.js.flow +2 -0
- package/store/RelayModernStore.js.flow +86 -27
- package/store/RelayPublishQueue.js.flow +32 -21
- package/store/RelayReader.js.flow +168 -97
- package/store/RelayReferenceMarker.js.flow +15 -5
- package/store/RelayResponseNormalizer.js.flow +104 -69
- package/store/RelayStoreSubscriptions.js.flow +2 -2
- package/store/RelayStoreTypes.js.flow +34 -4
- package/store/RelayStoreUtils.js.flow +29 -0
- package/store/ResolverCache.js.flow +2 -2
- package/store/ResolverFragments.js.flow +5 -3
- package/store/StoreInspector.js.flow +5 -0
- package/store/createRelayContext.js.flow +3 -2
- package/store/createRelayLoggingContext.js.flow +46 -0
- package/store/generateTypenamePrefixedDataID.js.flow +25 -0
- package/store/live-resolvers/LiveResolverCache.js.flow +7 -2
- package/store/live-resolvers/resolverDataInjector.js.flow +10 -6
- package/store/normalizeResponse.js.flow +2 -0
- package/store/observeFragmentExperimental.js.flow +82 -28
- package/store/observeQueryExperimental.js.flow +61 -0
- package/store/waitForFragmentExperimental.js.flow +4 -3
- package/util/NormalizationNode.js.flow +2 -1
- package/util/RelayConcreteNode.js.flow +2 -0
- package/util/RelayError.js.flow +1 -0
- package/util/RelayFeatureFlags.js.flow +28 -0
- package/util/RelayRuntimeTypes.js.flow +6 -3
- package/util/getPaginationVariables.js.flow +2 -0
- package/util/handlePotentialSnapshotErrors.js.flow +23 -11
- package/util/registerEnvironmentWithDevTools.js.flow +4 -2
- package/util/withProvidedVariables.js.flow +1 -0
- package/util/withStartAndDuration.js.flow +3 -0
- package/relay-runtime-experimental.js +0 -4
- package/relay-runtime-experimental.min.js +0 -9
- package/relay-runtime.js +0 -4
- package/relay-runtime.min.js +0 -9
package/lib/store/RelayReader.js
CHANGED
|
@@ -4,9 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
5
5
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
6
6
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
7
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
8
7
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
8
|
var _excluded = ["message"];
|
|
9
|
+
var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
10
10
|
var _require = require('./live-resolvers/LiveResolverSuspenseSentinel'),
|
|
11
11
|
isSuspenseSentinel = _require.isSuspenseSentinel;
|
|
12
12
|
var RelayConcreteVariables = require('./RelayConcreteVariables');
|
|
@@ -36,15 +36,15 @@ function read(recordSource, selector, resolverCache, resolverContext) {
|
|
|
36
36
|
}
|
|
37
37
|
var RelayReader = /*#__PURE__*/function () {
|
|
38
38
|
function RelayReader(recordSource, selector, resolverCache, resolverContext) {
|
|
39
|
-
var _selector$clientEdgeT, _this$_owner$node$ope;
|
|
39
|
+
var _selector$clientEdgeT, _ref, _this$_owner$node$ope, _this$_owner$node$ope2;
|
|
40
40
|
this._clientEdgeTraversalPath = (_selector$clientEdgeT = selector.clientEdgeTraversalPath) !== null && _selector$clientEdgeT !== void 0 && _selector$clientEdgeT.length ? (0, _toConsumableArray2["default"])(selector.clientEdgeTraversalPath) : [];
|
|
41
41
|
this._missingClientEdges = [];
|
|
42
42
|
this._missingLiveResolverFields = [];
|
|
43
43
|
this._isMissingData = false;
|
|
44
44
|
this._isWithinUnmatchedTypeRefinement = false;
|
|
45
|
-
this.
|
|
45
|
+
this._fieldErrors = null;
|
|
46
46
|
this._owner = selector.owner;
|
|
47
|
-
this._useExecTimeResolvers = (_this$_owner$node$ope = this._owner.node.operation.use_exec_time_resolvers) !== null && _this$_owner$node$ope !== void 0 ? _this$_owner$node$ope : false;
|
|
47
|
+
this._useExecTimeResolvers = (_ref = (_this$_owner$node$ope = this._owner.node.operation.use_exec_time_resolvers) !== null && _this$_owner$node$ope !== void 0 ? _this$_owner$node$ope : ((_this$_owner$node$ope2 = this._owner.node.operation.exec_time_resolvers_enabled_provider) === null || _this$_owner$node$ope2 === void 0 ? void 0 : _this$_owner$node$ope2.get()) === true) !== null && _ref !== void 0 ? _ref : false;
|
|
48
48
|
this._recordSource = recordSource;
|
|
49
49
|
this._seenRecords = new Set();
|
|
50
50
|
this._selector = selector;
|
|
@@ -92,37 +92,30 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
92
92
|
missingLiveResolverFields: this._missingLiveResolverFields,
|
|
93
93
|
seenRecords: this._seenRecords,
|
|
94
94
|
selector: this._selector,
|
|
95
|
-
|
|
95
|
+
fieldErrors: this._fieldErrors
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
|
-
_proto.
|
|
98
|
+
_proto._maybeAddFieldErrors = function _maybeAddFieldErrors(record, storageKey) {
|
|
99
99
|
var errors = RelayModernRecord.getErrors(record, storageKey);
|
|
100
100
|
if (errors == null) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
var owner = this._fragmentName;
|
|
104
|
-
if (this.
|
|
105
|
-
this.
|
|
106
|
-
}
|
|
107
|
-
var
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
handled: false
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
} catch (err) {
|
|
123
|
-
_iterator.e(err);
|
|
124
|
-
} finally {
|
|
125
|
-
_iterator.f();
|
|
104
|
+
if (this._fieldErrors == null) {
|
|
105
|
+
this._fieldErrors = [];
|
|
106
|
+
}
|
|
107
|
+
for (var i = 0; i < errors.length; i++) {
|
|
108
|
+
var _error$path, _this$_selector$node$2, _this$_selector$node$3;
|
|
109
|
+
var error = errors[i];
|
|
110
|
+
this._fieldErrors.push({
|
|
111
|
+
kind: 'relay_field_payload.error',
|
|
112
|
+
owner: owner,
|
|
113
|
+
fieldPath: ((_error$path = error.path) !== null && _error$path !== void 0 ? _error$path : []).join('.'),
|
|
114
|
+
error: error,
|
|
115
|
+
shouldThrow: (_this$_selector$node$2 = (_this$_selector$node$3 = this._selector.node.metadata) === null || _this$_selector$node$3 === void 0 ? void 0 : _this$_selector$node$3.throwOnFieldError) !== null && _this$_selector$node$2 !== void 0 ? _this$_selector$node$2 : false,
|
|
116
|
+
handled: false,
|
|
117
|
+
uiContext: undefined
|
|
118
|
+
});
|
|
126
119
|
}
|
|
127
120
|
};
|
|
128
121
|
_proto._markDataAsMissing = function _markDataAsMissing(fieldName) {
|
|
@@ -130,19 +123,21 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
130
123
|
if (this._isWithinUnmatchedTypeRefinement) {
|
|
131
124
|
return;
|
|
132
125
|
}
|
|
133
|
-
if (this.
|
|
134
|
-
this.
|
|
126
|
+
if (this._fieldErrors == null) {
|
|
127
|
+
this._fieldErrors = [];
|
|
135
128
|
}
|
|
136
129
|
var owner = this._fragmentName;
|
|
137
|
-
this.
|
|
130
|
+
this._fieldErrors.push(((_this$_selector$node$4 = (_this$_selector$node$5 = this._selector.node.metadata) === null || _this$_selector$node$5 === void 0 ? void 0 : _this$_selector$node$5.throwOnFieldError) !== null && _this$_selector$node$4 !== void 0 ? _this$_selector$node$4 : false) ? {
|
|
138
131
|
kind: 'missing_expected_data.throw',
|
|
139
132
|
owner: owner,
|
|
140
133
|
fieldPath: fieldName,
|
|
141
|
-
handled: false
|
|
134
|
+
handled: false,
|
|
135
|
+
uiContext: undefined
|
|
142
136
|
} : {
|
|
143
137
|
kind: 'missing_expected_data.log',
|
|
144
138
|
owner: owner,
|
|
145
|
-
fieldPath: fieldName
|
|
139
|
+
fieldPath: fieldName,
|
|
140
|
+
uiContext: undefined
|
|
146
141
|
});
|
|
147
142
|
this._isMissingData = true;
|
|
148
143
|
if (this._clientEdgeTraversalPath.length) {
|
|
@@ -177,8 +172,8 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
177
172
|
return;
|
|
178
173
|
}
|
|
179
174
|
var owner = this._fragmentName;
|
|
180
|
-
if (this.
|
|
181
|
-
this.
|
|
175
|
+
if (this._fieldErrors == null) {
|
|
176
|
+
this._fieldErrors = [];
|
|
182
177
|
}
|
|
183
178
|
var fieldName;
|
|
184
179
|
if (selection.field.linkedField != null) {
|
|
@@ -190,18 +185,20 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
190
185
|
}
|
|
191
186
|
switch (selection.action) {
|
|
192
187
|
case 'THROW':
|
|
193
|
-
this.
|
|
188
|
+
this._fieldErrors.push({
|
|
194
189
|
kind: 'missing_required_field.throw',
|
|
195
190
|
fieldPath: fieldName,
|
|
196
191
|
owner: owner,
|
|
197
|
-
handled: false
|
|
192
|
+
handled: false,
|
|
193
|
+
uiContext: undefined
|
|
198
194
|
});
|
|
199
195
|
return;
|
|
200
196
|
case 'LOG':
|
|
201
|
-
this.
|
|
197
|
+
this._fieldErrors.push({
|
|
202
198
|
kind: 'missing_required_field.log',
|
|
203
199
|
fieldPath: fieldName,
|
|
204
|
-
owner: owner
|
|
200
|
+
owner: owner,
|
|
201
|
+
uiContext: undefined
|
|
205
202
|
});
|
|
206
203
|
return;
|
|
207
204
|
default:
|
|
@@ -222,33 +219,33 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
222
219
|
value = this._asResult(_value);
|
|
223
220
|
break;
|
|
224
221
|
case 'NULL':
|
|
225
|
-
if (this.
|
|
222
|
+
if (this._fieldErrors != null && this._fieldErrors.length > 0) {
|
|
226
223
|
value = null;
|
|
227
224
|
}
|
|
228
225
|
break;
|
|
229
226
|
default:
|
|
230
227
|
to;
|
|
231
228
|
}
|
|
232
|
-
var
|
|
233
|
-
this.
|
|
234
|
-
if (
|
|
235
|
-
if (this.
|
|
236
|
-
this.
|
|
229
|
+
var childrenFieldErrors = this._fieldErrors;
|
|
230
|
+
this._fieldErrors = previousResponseFields;
|
|
231
|
+
if (childrenFieldErrors != null) {
|
|
232
|
+
if (this._fieldErrors == null) {
|
|
233
|
+
this._fieldErrors = [];
|
|
237
234
|
}
|
|
238
|
-
for (var i = 0; i <
|
|
239
|
-
this.
|
|
235
|
+
for (var i = 0; i < childrenFieldErrors.length; i++) {
|
|
236
|
+
this._fieldErrors.push(markFieldErrorHasHandled(childrenFieldErrors[i]));
|
|
240
237
|
}
|
|
241
238
|
}
|
|
242
239
|
return value;
|
|
243
240
|
};
|
|
244
241
|
_proto._asResult = function _asResult(value) {
|
|
245
|
-
if (this.
|
|
242
|
+
if (this._fieldErrors == null || this._fieldErrors.length === 0) {
|
|
246
243
|
return {
|
|
247
244
|
ok: true,
|
|
248
245
|
value: value
|
|
249
246
|
};
|
|
250
247
|
}
|
|
251
|
-
var errors = this.
|
|
248
|
+
var errors = this._fieldErrors.map(function (error) {
|
|
252
249
|
switch (error.kind) {
|
|
253
250
|
case 'relay_field_payload.error':
|
|
254
251
|
var _error$error = error.error,
|
|
@@ -272,7 +269,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
272
269
|
return null;
|
|
273
270
|
default:
|
|
274
271
|
error.kind;
|
|
275
|
-
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Unexpected error
|
|
272
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Unexpected error fieldError kind: %s', error.kind) : invariant(false) : void 0;
|
|
276
273
|
}
|
|
277
274
|
}).filter(Boolean);
|
|
278
275
|
return {
|
|
@@ -293,8 +290,8 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
293
290
|
case 'CatchField':
|
|
294
291
|
{
|
|
295
292
|
var _selection$field$back, _selection$field, _field$alias;
|
|
296
|
-
var previousResponseFields = this.
|
|
297
|
-
this.
|
|
293
|
+
var previousResponseFields = this._fieldErrors;
|
|
294
|
+
this._fieldErrors = null;
|
|
298
295
|
var catchFieldValue = this._readClientSideDirectiveField(selection, record, data);
|
|
299
296
|
var field = (_selection$field$back = (_selection$field = selection.field) === null || _selection$field === void 0 ? void 0 : _selection$field.backingField) !== null && _selection$field$back !== void 0 ? _selection$field$back : selection.field;
|
|
300
297
|
var fieldName = (_field$alias = field === null || field === void 0 ? void 0 : field.alias) !== null && _field$alias !== void 0 ? _field$alias : field === null || field === void 0 ? void 0 : field.name;
|
|
@@ -409,12 +406,26 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
409
406
|
return this._readLink(selection.field, record, data);
|
|
410
407
|
}
|
|
411
408
|
case 'RelayResolver':
|
|
412
|
-
return this._readResolverField(selection.field, record, data);
|
|
413
409
|
case 'RelayLiveResolver':
|
|
414
|
-
|
|
410
|
+
{
|
|
411
|
+
if (this._useExecTimeResolvers) {
|
|
412
|
+
return this._readScalar(selection.field, record, data);
|
|
413
|
+
} else {
|
|
414
|
+
return this._readResolverField(selection.field, record, data);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
415
417
|
case 'ClientEdgeToClientObject':
|
|
416
418
|
case 'ClientEdgeToServerObject':
|
|
417
|
-
|
|
419
|
+
if (this._useExecTimeResolvers && (selection.field.backingField.kind === 'RelayResolver' || selection.field.backingField.kind === 'RelayLiveResolver')) {
|
|
420
|
+
var field = selection.field;
|
|
421
|
+
if (field.linkedField.plural) {
|
|
422
|
+
return this._readPluralLink(field.linkedField, record, data);
|
|
423
|
+
} else {
|
|
424
|
+
return this._readLink(field.linkedField, record, data);
|
|
425
|
+
}
|
|
426
|
+
} else {
|
|
427
|
+
return this._readClientEdge(selection.field, record, data);
|
|
428
|
+
}
|
|
418
429
|
case 'AliasedInlineFragmentSpread':
|
|
419
430
|
return this._readAliasedInlineFragment(selection.field, record, data);
|
|
420
431
|
default:
|
|
@@ -425,8 +436,8 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
425
436
|
_proto._readResolverField = function _readResolverField(field, record, data) {
|
|
426
437
|
var _field$alias2;
|
|
427
438
|
var parentRecordID = RelayModernRecord.getDataID(record);
|
|
428
|
-
var prevErrors = this.
|
|
429
|
-
this.
|
|
439
|
+
var prevErrors = this._fieldErrors;
|
|
440
|
+
this._fieldErrors = null;
|
|
430
441
|
var result = this._readResolverFieldImpl(field, parentRecordID);
|
|
431
442
|
var fieldName = (_field$alias2 = field.alias) !== null && _field$alias2 !== void 0 ? _field$alias2 : field.name;
|
|
432
443
|
this._prependPreviousErrors(prevErrors, fieldName);
|
|
@@ -442,14 +453,14 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
442
453
|
return {
|
|
443
454
|
data: snapshot.data,
|
|
444
455
|
isMissingData: snapshot.isMissingData,
|
|
445
|
-
|
|
456
|
+
fieldErrors: snapshot.fieldErrors
|
|
446
457
|
};
|
|
447
458
|
}
|
|
448
459
|
snapshot = read(_this._recordSource, singularReaderSelector, _this._resolverCache);
|
|
449
460
|
return {
|
|
450
461
|
data: snapshot.data,
|
|
451
462
|
isMissingData: snapshot.isMissingData,
|
|
452
|
-
|
|
463
|
+
fieldErrors: snapshot.fieldErrors
|
|
453
464
|
};
|
|
454
465
|
};
|
|
455
466
|
var evaluate = function evaluate() {
|
|
@@ -459,6 +470,9 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
459
470
|
__fragmentOwner: _this._owner,
|
|
460
471
|
__fragments: (0, _defineProperty2["default"])({}, fragment.name, fragment.args ? getArgumentValues(fragment.args, _this._variables) : {})
|
|
461
472
|
};
|
|
473
|
+
if (_this._clientEdgeTraversalPath.length > 0 && _this._clientEdgeTraversalPath[_this._clientEdgeTraversalPath.length - 1] !== null) {
|
|
474
|
+
key[CLIENT_EDGE_TRAVERSAL_PATH] = (0, _toConsumableArray2["default"])(_this._clientEdgeTraversalPath);
|
|
475
|
+
}
|
|
462
476
|
var resolverContext = {
|
|
463
477
|
getDataForResolverFragment: getDataForResolverFragment
|
|
464
478
|
};
|
|
@@ -494,56 +508,33 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
494
508
|
return result;
|
|
495
509
|
};
|
|
496
510
|
_proto._propagateResolverMetadata = function _propagateResolverMetadata(fieldPath, cachedSnapshot, resolverError, seenRecord, suspenseID, updatedDataIDs) {
|
|
511
|
+
var _this2 = this;
|
|
497
512
|
if (cachedSnapshot != null) {
|
|
498
513
|
if (cachedSnapshot.missingClientEdges != null) {
|
|
499
|
-
var
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
503
|
-
var missing = _step2.value;
|
|
504
|
-
this._missingClientEdges.push(missing);
|
|
505
|
-
}
|
|
506
|
-
} catch (err) {
|
|
507
|
-
_iterator2.e(err);
|
|
508
|
-
} finally {
|
|
509
|
-
_iterator2.f();
|
|
514
|
+
for (var i = 0; i < cachedSnapshot.missingClientEdges.length; i++) {
|
|
515
|
+
var missing = cachedSnapshot.missingClientEdges[i];
|
|
516
|
+
this._missingClientEdges.push(missing);
|
|
510
517
|
}
|
|
511
518
|
}
|
|
512
519
|
if (cachedSnapshot.missingLiveResolverFields != null) {
|
|
513
520
|
this._isMissingData = this._isMissingData || cachedSnapshot.missingLiveResolverFields.length > 0;
|
|
514
|
-
var
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
518
|
-
var missingResolverField = _step3.value;
|
|
519
|
-
this._missingLiveResolverFields.push(missingResolverField);
|
|
520
|
-
}
|
|
521
|
-
} catch (err) {
|
|
522
|
-
_iterator3.e(err);
|
|
523
|
-
} finally {
|
|
524
|
-
_iterator3.f();
|
|
521
|
+
for (var _i = 0; _i < cachedSnapshot.missingLiveResolverFields.length; _i++) {
|
|
522
|
+
var missingResolverField = cachedSnapshot.missingLiveResolverFields[_i];
|
|
523
|
+
this._missingLiveResolverFields.push(missingResolverField);
|
|
525
524
|
}
|
|
526
525
|
}
|
|
527
|
-
if (cachedSnapshot.
|
|
528
|
-
if (this.
|
|
529
|
-
this.
|
|
526
|
+
if (cachedSnapshot.fieldErrors != null) {
|
|
527
|
+
if (this._fieldErrors == null) {
|
|
528
|
+
this._fieldErrors = [];
|
|
530
529
|
}
|
|
531
|
-
var
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
this._errorResponseFields.push(error);
|
|
539
|
-
} else {
|
|
540
|
-
this._errorResponseFields.push(markFieldErrorHasHandled(error));
|
|
541
|
-
}
|
|
530
|
+
for (var _i2 = 0; _i2 < cachedSnapshot.fieldErrors.length; _i2++) {
|
|
531
|
+
var _this$_selector$node$6;
|
|
532
|
+
var error = cachedSnapshot.fieldErrors[_i2];
|
|
533
|
+
if (((_this$_selector$node$6 = this._selector.node.metadata) === null || _this$_selector$node$6 === void 0 ? void 0 : _this$_selector$node$6.throwOnFieldError) === true) {
|
|
534
|
+
this._fieldErrors.push(error);
|
|
535
|
+
} else {
|
|
536
|
+
this._fieldErrors.push(markFieldErrorHasHandled(error));
|
|
542
537
|
}
|
|
543
|
-
} catch (err) {
|
|
544
|
-
_iterator4.e(err);
|
|
545
|
-
} finally {
|
|
546
|
-
_iterator4.f();
|
|
547
538
|
}
|
|
548
539
|
}
|
|
549
540
|
this._isMissingData = this._isMissingData || cachedSnapshot.isMissingData;
|
|
@@ -556,12 +547,13 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
556
547
|
owner: this._fragmentName,
|
|
557
548
|
error: resolverError,
|
|
558
549
|
shouldThrow: (_this$_selector$node$7 = (_this$_selector$node$8 = this._selector.node.metadata) === null || _this$_selector$node$8 === void 0 ? void 0 : _this$_selector$node$8.throwOnFieldError) !== null && _this$_selector$node$7 !== void 0 ? _this$_selector$node$7 : false,
|
|
559
|
-
handled: false
|
|
550
|
+
handled: false,
|
|
551
|
+
uiContext: undefined
|
|
560
552
|
};
|
|
561
|
-
if (this.
|
|
562
|
-
this.
|
|
553
|
+
if (this._fieldErrors == null) {
|
|
554
|
+
this._fieldErrors = [errorEvent];
|
|
563
555
|
} else {
|
|
564
|
-
this.
|
|
556
|
+
this._fieldErrors.push(errorEvent);
|
|
565
557
|
}
|
|
566
558
|
}
|
|
567
559
|
if (seenRecord != null) {
|
|
@@ -572,22 +564,13 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
572
564
|
this._missingLiveResolverFields.push(suspenseID);
|
|
573
565
|
}
|
|
574
566
|
if (updatedDataIDs != null) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
579
|
-
var recordID = _step5.value;
|
|
580
|
-
this._updatedDataIDs.add(recordID);
|
|
581
|
-
}
|
|
582
|
-
} catch (err) {
|
|
583
|
-
_iterator5.e(err);
|
|
584
|
-
} finally {
|
|
585
|
-
_iterator5.f();
|
|
586
|
-
}
|
|
567
|
+
updatedDataIDs.forEach(function (recordID) {
|
|
568
|
+
_this2._updatedDataIDs.add(recordID);
|
|
569
|
+
});
|
|
587
570
|
}
|
|
588
571
|
};
|
|
589
572
|
_proto._readClientEdge = function _readClientEdge(field, record, data) {
|
|
590
|
-
var
|
|
573
|
+
var _this3 = this;
|
|
591
574
|
var _backingField$alias;
|
|
592
575
|
var backingField = field.backingField;
|
|
593
576
|
!(backingField.kind !== 'ClientExtension') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Client extension client edges are not yet implemented.') : invariant(false) : void 0;
|
|
@@ -607,21 +590,21 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
607
590
|
storeIDs = clientEdgeResolverResponse.map(function (itemResponse) {
|
|
608
591
|
var _field$concreteType;
|
|
609
592
|
var concreteType = (_field$concreteType = field.concreteType) !== null && _field$concreteType !== void 0 ? _field$concreteType : itemResponse.__typename;
|
|
610
|
-
!(typeof concreteType === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected resolver for field at `%s` in `%s` modeling an edge to an abstract type to return an object with a `__typename` property.', backingField.path,
|
|
611
|
-
var localId = extractIdFromResponse(itemResponse, backingField.path,
|
|
612
|
-
var id =
|
|
593
|
+
!(typeof concreteType === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected resolver for field at `%s` in `%s` modeling an edge to an abstract type to return an object with a `__typename` property.', backingField.path, _this3._owner.identifier) : invariant(false) : void 0;
|
|
594
|
+
var localId = extractIdFromResponse(itemResponse, backingField.path, _this3._owner.identifier);
|
|
595
|
+
var id = _this3._resolverCache.ensureClientRecord(localId, concreteType);
|
|
613
596
|
var modelResolvers = field.modelResolvers;
|
|
614
597
|
if (modelResolvers != null) {
|
|
615
598
|
var modelResolver = modelResolvers[concreteType];
|
|
616
|
-
!(modelResolver !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Invalid `__typename` returned by resolver at `%s` in `%s`. Expected one of %s but got `%s`.', backingField.path,
|
|
617
|
-
var model =
|
|
599
|
+
!(modelResolver !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Invalid `__typename` returned by resolver at `%s` in `%s`. Expected one of %s but got `%s`.', backingField.path, _this3._owner.identifier, Object.keys(modelResolvers).join(', '), concreteType) : invariant(false) : void 0;
|
|
600
|
+
var model = _this3._readResolverFieldImpl(modelResolver, id);
|
|
618
601
|
return model != null ? id : null;
|
|
619
602
|
}
|
|
620
603
|
return id;
|
|
621
604
|
});
|
|
622
605
|
} else {
|
|
623
606
|
storeIDs = clientEdgeResolverResponse.map(function (obj) {
|
|
624
|
-
return extractIdFromResponse(obj, backingField.path,
|
|
607
|
+
return extractIdFromResponse(obj, backingField.path, _this3._owner.identifier);
|
|
625
608
|
});
|
|
626
609
|
}
|
|
627
610
|
this._clientEdgeTraversalPath.push(null);
|
|
@@ -665,8 +648,8 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
665
648
|
this._clientEdgeTraversalPath.push(traversalPathSegment);
|
|
666
649
|
var prevData = data[fieldName];
|
|
667
650
|
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field at `%s` in `%s` on record `%s` ' + 'to be an object, got `%s`.', backingField.path, this._owner.identifier, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0;
|
|
668
|
-
var prevErrors = this.
|
|
669
|
-
this.
|
|
651
|
+
var prevErrors = this._fieldErrors;
|
|
652
|
+
this._fieldErrors = null;
|
|
670
653
|
var edgeValue = this._traverse(field.linkedField, storeID, prevData);
|
|
671
654
|
this._prependPreviousErrors(prevErrors, fieldName);
|
|
672
655
|
this._clientEdgeTraversalPath.pop();
|
|
@@ -679,8 +662,8 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
679
662
|
var fieldName = (_field$alias3 = field.alias) !== null && _field$alias3 !== void 0 ? _field$alias3 : field.name;
|
|
680
663
|
var storageKey = getStorageKey(field, this._variables);
|
|
681
664
|
var value = RelayModernRecord.getValue(record, storageKey);
|
|
682
|
-
if (value === null) {
|
|
683
|
-
this.
|
|
665
|
+
if (value === null || RelayFeatureFlags.ENABLE_NONCOMPLIANT_ERROR_HANDLING_ON_LISTS && Array.isArray(value) && value.length === 0) {
|
|
666
|
+
this._maybeAddFieldErrors(record, storageKey);
|
|
684
667
|
} else if (value === undefined) {
|
|
685
668
|
this._markDataAsMissing(fieldName);
|
|
686
669
|
}
|
|
@@ -695,7 +678,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
695
678
|
if (linkedID == null) {
|
|
696
679
|
data[fieldName] = linkedID;
|
|
697
680
|
if (linkedID === null) {
|
|
698
|
-
this.
|
|
681
|
+
this._maybeAddFieldErrors(record, storageKey);
|
|
699
682
|
} else if (linkedID === undefined) {
|
|
700
683
|
this._markDataAsMissing(fieldName);
|
|
701
684
|
}
|
|
@@ -703,29 +686,29 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
703
686
|
}
|
|
704
687
|
var prevData = data[fieldName];
|
|
705
688
|
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` at `%s` on record `%s` ' + 'to be an object, got `%s`.', fieldName, this._owner.identifier, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0;
|
|
706
|
-
var prevErrors = this.
|
|
707
|
-
this.
|
|
689
|
+
var prevErrors = this._fieldErrors;
|
|
690
|
+
this._fieldErrors = null;
|
|
708
691
|
var value = this._traverse(field, linkedID, prevData);
|
|
709
692
|
this._prependPreviousErrors(prevErrors, fieldName);
|
|
710
693
|
data[fieldName] = value;
|
|
711
694
|
return value;
|
|
712
695
|
};
|
|
713
696
|
_proto._prependPreviousErrors = function _prependPreviousErrors(prevErrors, fieldNameOrIndex) {
|
|
714
|
-
if (this.
|
|
715
|
-
for (var i = 0; i < this.
|
|
716
|
-
var event = this.
|
|
697
|
+
if (this._fieldErrors != null) {
|
|
698
|
+
for (var i = 0; i < this._fieldErrors.length; i++) {
|
|
699
|
+
var event = this._fieldErrors[i];
|
|
717
700
|
if (event.owner === this._fragmentName && (event.kind === 'missing_expected_data.throw' || event.kind === 'missing_expected_data.log' || event.kind === 'missing_required_field.throw' || event.kind === 'missing_required_field.log')) {
|
|
718
701
|
event.fieldPath = "".concat(fieldNameOrIndex, ".").concat(event.fieldPath);
|
|
719
702
|
}
|
|
720
703
|
}
|
|
721
704
|
if (prevErrors != null) {
|
|
722
|
-
for (var
|
|
723
|
-
prevErrors.push(this.
|
|
705
|
+
for (var _i3 = this._fieldErrors.length - 1; _i3 >= 0; _i3--) {
|
|
706
|
+
prevErrors.push(this._fieldErrors[_i3]);
|
|
724
707
|
}
|
|
725
|
-
this.
|
|
708
|
+
this._fieldErrors = prevErrors;
|
|
726
709
|
}
|
|
727
710
|
} else {
|
|
728
|
-
this.
|
|
711
|
+
this._fieldErrors = prevErrors;
|
|
729
712
|
}
|
|
730
713
|
};
|
|
731
714
|
_proto._readActorChange = function _readActorChange(field, record, data) {
|
|
@@ -738,7 +721,7 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
738
721
|
if (externalRef === undefined) {
|
|
739
722
|
this._markDataAsMissing(fieldName);
|
|
740
723
|
} else if (externalRef === null) {
|
|
741
|
-
this.
|
|
724
|
+
this._maybeAddFieldErrors(record, storageKey);
|
|
742
725
|
}
|
|
743
726
|
return data[fieldName];
|
|
744
727
|
}
|
|
@@ -757,13 +740,13 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
757
740
|
_proto._readPluralLink = function _readPluralLink(field, record, data) {
|
|
758
741
|
var storageKey = getStorageKey(field, this._variables);
|
|
759
742
|
var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
|
|
760
|
-
if (linkedIDs === null) {
|
|
761
|
-
this.
|
|
743
|
+
if (linkedIDs === null || RelayFeatureFlags.ENABLE_NONCOMPLIANT_ERROR_HANDLING_ON_LISTS && Array.isArray(linkedIDs) && linkedIDs.length === 0) {
|
|
744
|
+
this._maybeAddFieldErrors(record, storageKey);
|
|
762
745
|
}
|
|
763
746
|
return this._readLinkedIds(field, linkedIDs, record, data);
|
|
764
747
|
};
|
|
765
748
|
_proto._readLinkedIds = function _readLinkedIds(field, linkedIDs, record, data) {
|
|
766
|
-
var
|
|
749
|
+
var _this4 = this;
|
|
767
750
|
var _field$alias6;
|
|
768
751
|
var fieldName = (_field$alias6 = field.alias) !== null && _field$alias6 !== void 0 ? _field$alias6 : field.name;
|
|
769
752
|
if (linkedIDs == null) {
|
|
@@ -775,32 +758,32 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
775
758
|
}
|
|
776
759
|
var prevData = data[fieldName];
|
|
777
760
|
!(prevData == null || Array.isArray(prevData)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an array, got `%s`.', fieldName, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0;
|
|
778
|
-
var prevErrors = this.
|
|
779
|
-
this.
|
|
761
|
+
var prevErrors = this._fieldErrors;
|
|
762
|
+
this._fieldErrors = null;
|
|
780
763
|
var linkedArray = prevData || [];
|
|
781
764
|
linkedIDs.forEach(function (linkedID, nextIndex) {
|
|
782
765
|
if (linkedID == null) {
|
|
783
766
|
if (linkedID === undefined) {
|
|
784
|
-
|
|
767
|
+
_this4._markDataAsMissing(String(nextIndex));
|
|
785
768
|
}
|
|
786
769
|
linkedArray[nextIndex] = linkedID;
|
|
787
770
|
return;
|
|
788
771
|
}
|
|
789
772
|
var prevItem = linkedArray[nextIndex];
|
|
790
773
|
!(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`.', fieldName, RelayModernRecord.getDataID(record), prevItem) : invariant(false) : void 0;
|
|
791
|
-
var prevErrors =
|
|
792
|
-
|
|
793
|
-
linkedArray[nextIndex] =
|
|
794
|
-
|
|
774
|
+
var prevErrors = _this4._fieldErrors;
|
|
775
|
+
_this4._fieldErrors = null;
|
|
776
|
+
linkedArray[nextIndex] = _this4._traverse(field, linkedID, prevItem);
|
|
777
|
+
_this4._prependPreviousErrors(prevErrors, nextIndex);
|
|
795
778
|
});
|
|
796
779
|
this._prependPreviousErrors(prevErrors, fieldName);
|
|
797
780
|
data[fieldName] = linkedArray;
|
|
798
781
|
return linkedArray;
|
|
799
782
|
};
|
|
800
783
|
_proto._readModuleImport = function _readModuleImport(moduleImport, record, data) {
|
|
801
|
-
var _moduleImport$compone;
|
|
802
784
|
var componentKey = getModuleComponentKey(moduleImport.documentName);
|
|
803
|
-
var
|
|
785
|
+
var relayStoreComponent = RelayModernRecord.getValue(record, componentKey);
|
|
786
|
+
var component = relayStoreComponent !== undefined ? relayStoreComponent : moduleImport.componentModuleProvider;
|
|
804
787
|
if (component == null) {
|
|
805
788
|
if (component === undefined) {
|
|
806
789
|
this._markDataAsMissing('<module-import>');
|
|
@@ -816,8 +799,8 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
816
799
|
data[MODULE_COMPONENT_KEY] = component;
|
|
817
800
|
};
|
|
818
801
|
_proto._readAliasedInlineFragment = function _readAliasedInlineFragment(aliasedInlineFragment, record, data) {
|
|
819
|
-
var prevErrors = this.
|
|
820
|
-
this.
|
|
802
|
+
var prevErrors = this._fieldErrors;
|
|
803
|
+
this._fieldErrors = null;
|
|
821
804
|
var fieldValue = this._readInlineFragment(aliasedInlineFragment.fragment, record, {}, true);
|
|
822
805
|
this._prependPreviousErrors(prevErrors, aliasedInlineFragment.name);
|
|
823
806
|
if (fieldValue === false) {
|
|
@@ -12,19 +12,21 @@ var RelayStoreUtils = require('./RelayStoreUtils');
|
|
|
12
12
|
var _require2 = require('./TypeID'),
|
|
13
13
|
generateTypeID = _require2.generateTypeID;
|
|
14
14
|
var invariant = require('invariant');
|
|
15
|
-
var
|
|
15
|
+
var getReadTimeResolverStorageKey = RelayStoreUtils.getReadTimeResolverStorageKey,
|
|
16
|
+
getStorageKey = RelayStoreUtils.getStorageKey,
|
|
16
17
|
getModuleOperationKey = RelayStoreUtils.getModuleOperationKey;
|
|
17
|
-
function mark(recordSource, selector, references, operationLoader, shouldProcessClientComponents) {
|
|
18
|
+
function mark(recordSource, selector, references, operationLoader, shouldProcessClientComponents, useExecTimeResolvers) {
|
|
18
19
|
var dataID = selector.dataID,
|
|
19
20
|
node = selector.node,
|
|
20
21
|
variables = selector.variables;
|
|
21
|
-
var marker = new RelayReferenceMarker(recordSource, variables, references, operationLoader, shouldProcessClientComponents);
|
|
22
|
+
var marker = new RelayReferenceMarker(recordSource, variables, references, operationLoader, shouldProcessClientComponents, useExecTimeResolvers);
|
|
22
23
|
marker.mark(node, dataID);
|
|
23
24
|
}
|
|
24
25
|
var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
25
|
-
function RelayReferenceMarker(recordSource, variables, references, operationLoader, shouldProcessClientComponents) {
|
|
26
|
+
function RelayReferenceMarker(recordSource, variables, references, operationLoader, shouldProcessClientComponents, useExecTimeResolvers) {
|
|
26
27
|
this._operationLoader = operationLoader !== null && operationLoader !== void 0 ? operationLoader : null;
|
|
27
28
|
this._operationName = null;
|
|
29
|
+
this._useExecTimeResolvers = useExecTimeResolvers !== null && useExecTimeResolvers !== void 0 ? useExecTimeResolvers : false;
|
|
28
30
|
this._recordSource = recordSource;
|
|
29
31
|
this._references = references;
|
|
30
32
|
this._variables = variables;
|
|
@@ -123,8 +125,6 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
123
125
|
_this._traverseSelections(selection.fragment.selections, record);
|
|
124
126
|
break;
|
|
125
127
|
case 'RelayResolver':
|
|
126
|
-
_this._traverseResolverField(selection, record);
|
|
127
|
-
break;
|
|
128
128
|
case 'RelayLiveResolver':
|
|
129
129
|
_this._traverseResolverField(selection, record);
|
|
130
130
|
break;
|
|
@@ -138,6 +138,10 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
140
|
_proto._traverseClientEdgeToClientObject = function _traverseClientEdgeToClientObject(field, record) {
|
|
141
|
+
if (this._useExecTimeResolvers) {
|
|
142
|
+
this._traverseLink(field.linkedField, record);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
141
145
|
var dataID = this._traverseResolverField(field.backingField, record);
|
|
142
146
|
if (dataID == null) {
|
|
143
147
|
return;
|
|
@@ -195,7 +199,10 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
195
199
|
}
|
|
196
200
|
};
|
|
197
201
|
_proto._traverseResolverField = function _traverseResolverField(field, record) {
|
|
198
|
-
|
|
202
|
+
if (this._useExecTimeResolvers) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
var storageKey = getReadTimeResolverStorageKey(field, this._variables);
|
|
199
206
|
var dataID = RelayModernRecord.getLinkedRecordID(record, storageKey);
|
|
200
207
|
if (dataID != null) {
|
|
201
208
|
this._references.add(dataID);
|