relay-runtime 10.0.1 → 10.1.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.
Files changed (70) hide show
  1. package/handlers/RelayDefaultHandlerProvider.js.flow +6 -0
  2. package/handlers/connection/MutationHandlers.js.flow +114 -3
  3. package/index.js +1 -1
  4. package/index.js.flow +16 -1
  5. package/lib/handlers/RelayDefaultHandlerProvider.js +9 -0
  6. package/lib/handlers/connection/MutationHandlers.js +138 -12
  7. package/lib/index.js +7 -0
  8. package/lib/mutations/RelayDeclarativeMutationConfig.js +2 -2
  9. package/lib/mutations/commitMutation.js +1 -4
  10. package/lib/mutations/validateMutation.js +27 -7
  11. package/lib/network/RelayQueryResponseCache.js +2 -2
  12. package/lib/query/GraphQLTag.js +2 -1
  13. package/lib/query/fetchQuery.js +2 -3
  14. package/lib/query/fetchQueryInternal.js +2 -3
  15. package/lib/store/DataChecker.js +82 -5
  16. package/lib/store/RelayModernEnvironment.js +18 -6
  17. package/lib/store/RelayModernFragmentSpecResolver.js +10 -1
  18. package/lib/store/RelayModernOperationDescriptor.js +6 -5
  19. package/lib/store/RelayModernQueryExecutor.js +44 -23
  20. package/lib/store/RelayModernStore.js +25 -14
  21. package/lib/store/RelayOperationTracker.js +2 -2
  22. package/lib/store/RelayPublishQueue.js +1 -1
  23. package/lib/store/RelayReader.js +196 -33
  24. package/lib/store/RelayRecordSourceMapImpl.js +2 -2
  25. package/lib/store/RelayReferenceMarker.js +89 -5
  26. package/lib/store/RelayResponseNormalizer.js +119 -19
  27. package/lib/store/RelayStoreReactFlightUtils.js +47 -0
  28. package/lib/store/defaultRequiredFieldLogger.js +18 -0
  29. package/lib/store/normalizeRelayPayload.js +1 -1
  30. package/lib/subscription/requestSubscription.js +2 -3
  31. package/lib/util/NormalizationNode.js +1 -5
  32. package/lib/util/RelayConcreteNode.js +2 -0
  33. package/lib/util/RelayFeatureFlags.js +5 -2
  34. package/lib/util/getFragmentIdentifier.js +12 -3
  35. package/lib/util/getOperation.js +33 -0
  36. package/lib/util/isEmptyObject.js +25 -0
  37. package/lib/util/recycleNodesInto.js +4 -1
  38. package/lib/util/reportMissingRequiredFields.js +48 -0
  39. package/mutations/commitMutation.js.flow +1 -2
  40. package/mutations/validateMutation.js.flow +34 -5
  41. package/network/RelayNetworkTypes.js.flow +22 -0
  42. package/package.json +2 -2
  43. package/query/GraphQLTag.js.flow +3 -1
  44. package/query/fetchQuery.js.flow +2 -2
  45. package/query/fetchQueryInternal.js.flow +0 -5
  46. package/relay-runtime.js +2 -2
  47. package/relay-runtime.min.js +2 -2
  48. package/store/DataChecker.js.flow +68 -2
  49. package/store/RelayModernEnvironment.js.flow +29 -9
  50. package/store/RelayModernFragmentSpecResolver.js.flow +13 -1
  51. package/store/RelayModernOperationDescriptor.js.flow +5 -1
  52. package/store/RelayModernQueryExecutor.js.flow +47 -23
  53. package/store/RelayModernStore.js.flow +31 -15
  54. package/store/RelayPublishQueue.js.flow +1 -1
  55. package/store/RelayReader.js.flow +180 -15
  56. package/store/RelayReferenceMarker.js.flow +72 -5
  57. package/store/RelayResponseNormalizer.js.flow +130 -19
  58. package/store/RelayStoreReactFlightUtils.js.flow +64 -0
  59. package/store/RelayStoreTypes.js.flow +90 -31
  60. package/store/defaultRequiredFieldLogger.js.flow +23 -0
  61. package/subscription/requestSubscription.js.flow +5 -2
  62. package/util/NormalizationNode.js.flow +17 -2
  63. package/util/ReaderNode.js.flow +20 -1
  64. package/util/RelayConcreteNode.js.flow +6 -0
  65. package/util/RelayFeatureFlags.js.flow +8 -1
  66. package/util/getFragmentIdentifier.js.flow +33 -9
  67. package/util/getOperation.js.flow +40 -0
  68. package/util/isEmptyObject.js.flow +25 -0
  69. package/util/recycleNodesInto.js.flow +11 -0
  70. package/util/reportMissingRequiredFields.js.flow +51 -0
@@ -14,9 +14,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
14
14
 
15
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
16
 
17
- 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; } } }; }
17
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; 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 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; } } }; }
18
18
 
19
- 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); }
19
+ 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(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
20
 
21
21
  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; }
22
22
 
@@ -32,6 +32,8 @@ var RelayReader = require('./RelayReader');
32
32
 
33
33
  var RelayReferenceMarker = require('./RelayReferenceMarker');
34
34
 
35
+ var RelayStoreReactFlightUtils = require('./RelayStoreReactFlightUtils');
36
+
35
37
  var RelayStoreUtils = require('./RelayStoreUtils');
36
38
 
37
39
  var deepFreeze = require('../util/deepFreeze');
@@ -42,6 +44,8 @@ var hasOverlappingIDs = require('./hasOverlappingIDs');
42
44
 
43
45
  var invariant = require("fbjs/lib/invariant");
44
46
 
47
+ var isEmptyObject = require('../util/isEmptyObject');
48
+
45
49
  var recycleNodesInto = require('../util/recycleNodesInto');
46
50
 
47
51
  var resolveImmediate = require('../util/resolveImmediate');
@@ -186,7 +190,7 @@ var RelayModernStore = /*#__PURE__*/function () {
186
190
  if (rootEntryIsStale) {
187
191
  _this2._roots["delete"](id);
188
192
 
189
- _this2._scheduleGC();
193
+ _this2.scheduleGC();
190
194
  } else {
191
195
  _this2._releaseBuffer.push(id); // If the release buffer is now over-full, remove the least-recently
192
196
  // added entry and schedule a GC. Note that all items in the release
@@ -198,7 +202,7 @@ var RelayModernStore = /*#__PURE__*/function () {
198
202
 
199
203
  _this2._roots["delete"](_id);
200
204
 
201
- _this2._scheduleGC();
205
+ _this2.scheduleGC();
202
206
  }
203
207
  }
204
208
  }
@@ -266,9 +270,10 @@ var RelayModernStore = /*#__PURE__*/function () {
266
270
 
267
271
  var source = this.getSource();
268
272
  var updatedOwners = [];
273
+ var hasUpdatedRecords = !isEmptyObject(this._updatedRecordIDs);
269
274
 
270
275
  this._subscriptions.forEach(function (subscription) {
271
- var owner = _this3._updateSubscription(source, subscription);
276
+ var owner = _this3._updateSubscription(source, subscription, hasUpdatedRecords);
272
277
 
273
278
  if (owner != null) {
274
279
  updatedOwners.push(owner);
@@ -383,7 +388,7 @@ var RelayModernStore = /*#__PURE__*/function () {
383
388
  _this5._gcHoldCounter--;
384
389
 
385
390
  if (_this5._gcHoldCounter === 0 && _this5._shouldScheduleGC) {
386
- _this5._scheduleGC();
391
+ _this5.scheduleGC();
387
392
 
388
393
  _this5._shouldScheduleGC = false;
389
394
  }
@@ -406,12 +411,12 @@ var RelayModernStore = /*#__PURE__*/function () {
406
411
  // latest update, or null if it was not affected.
407
412
  ;
408
413
 
409
- _proto._updateSubscription = function _updateSubscription(source, subscription) {
414
+ _proto._updateSubscription = function _updateSubscription(source, subscription, hasUpdatedRecords) {
410
415
  var backup = subscription.backup,
411
416
  callback = subscription.callback,
412
417
  snapshot = subscription.snapshot,
413
418
  stale = subscription.stale;
414
- var hasOverlappingUpdates = hasOverlappingIDs(snapshot.seenRecords, this._updatedRecordIDs);
419
+ var hasOverlappingUpdates = hasUpdatedRecords && hasOverlappingIDs(snapshot.seenRecords, this._updatedRecordIDs);
415
420
 
416
421
  if (!stale && !hasOverlappingUpdates) {
417
422
  return;
@@ -423,7 +428,8 @@ var RelayModernStore = /*#__PURE__*/function () {
423
428
  data: nextData,
424
429
  isMissingData: nextSnapshot.isMissingData,
425
430
  seenRecords: nextSnapshot.seenRecords,
426
- selector: nextSnapshot.selector
431
+ selector: nextSnapshot.selector,
432
+ missingRequiredFields: nextSnapshot.missingRequiredFields
427
433
  };
428
434
 
429
435
  if (process.env.NODE_ENV !== "production") {
@@ -582,7 +588,7 @@ var RelayModernStore = /*#__PURE__*/function () {
582
588
  this._optimisticSource = null;
583
589
 
584
590
  if (this._shouldScheduleGC) {
585
- this._scheduleGC();
591
+ this.scheduleGC();
586
592
  }
587
593
 
588
594
  this._subscriptions.forEach(function (subscription) {
@@ -598,7 +604,8 @@ var RelayModernStore = /*#__PURE__*/function () {
598
604
  data: subscription.snapshot.data,
599
605
  isMissingData: backup.isMissingData,
600
606
  seenRecords: backup.seenRecords,
601
- selector: backup.selector
607
+ selector: backup.selector,
608
+ missingRequiredFields: backup.missingRequiredFields
602
609
  };
603
610
  } else {
604
611
  subscription.stale = true;
@@ -606,7 +613,7 @@ var RelayModernStore = /*#__PURE__*/function () {
606
613
  });
607
614
  };
608
615
 
609
- _proto._scheduleGC = function _scheduleGC() {
616
+ _proto.scheduleGC = function scheduleGC() {
610
617
  if (this._gcHoldCounter > 0) {
611
618
  this._shouldScheduleGC = true;
612
619
  return;
@@ -705,7 +712,7 @@ function initializeRecordSource(target) {
705
712
  /**
706
713
  * Updates the target with information from source, also updating a mapping of
707
714
  * which records in the target were changed as a result.
708
- * Additionally, will marc records as invalidated at the current write epoch
715
+ * Additionally, will mark records as invalidated at the current write epoch
709
716
  * given the set of record ids marked as stale in this update.
710
717
  */
711
718
 
@@ -767,7 +774,11 @@ function updateTargetFromSource(target, source, currentWriteEpoch, idsMarkedForI
767
774
  }
768
775
 
769
776
  if (sourceRecord && targetRecord) {
770
- var nextRecord = RelayModernRecord.update(targetRecord, sourceRecord);
777
+ // ReactFlightClientResponses are lazy and only materialize when readRoot
778
+ // is called when we read the field, so if the record is a Flight field
779
+ // we always use the new record's data regardless of whether
780
+ // it actually changed. Let React take care of reconciliation instead.
781
+ var nextRecord = RelayModernRecord.getType(targetRecord) === RelayStoreReactFlightUtils.REACT_FLIGHT_TYPE_NAME ? sourceRecord : RelayModernRecord.update(targetRecord, sourceRecord);
771
782
 
772
783
  if (nextRecord !== targetRecord) {
773
784
  // Prevent mutation of a record from outside the store.
@@ -10,9 +10,9 @@
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; } } }; }
13
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; 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 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
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); }
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(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
16
 
17
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
18
 
@@ -146,7 +146,7 @@ var RelayPublishQueue = /*#__PURE__*/function () {
146
146
 
147
147
  _proto.run = function run(sourceOperation) {
148
148
  if (process.env.NODE_ENV !== "production") {
149
- process.env.NODE_ENV !== "production" ? warning(this._isRunning !== true, 'A store update was detected within another store update. Please ' + 'make sure new store updates arent being executed within an ' + 'updater function for a different update.') : void 0;
149
+ process.env.NODE_ENV !== "production" ? warning(this._isRunning !== true, 'A store update was detected within another store update. Please ' + "make sure new store updates aren't being executed within an " + 'updater function for a different update.') : void 0;
150
150
  this._isRunning = true;
151
151
  }
152
152
 
@@ -20,28 +20,33 @@ var _require = require('../util/RelayConcreteNode'),
20
20
  CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
21
21
  CONDITION = _require.CONDITION,
22
22
  DEFER = _require.DEFER,
23
+ FLIGHT_FIELD = _require.FLIGHT_FIELD,
23
24
  FRAGMENT_SPREAD = _require.FRAGMENT_SPREAD,
24
25
  INLINE_DATA_FRAGMENT_SPREAD = _require.INLINE_DATA_FRAGMENT_SPREAD,
25
26
  INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
26
27
  LINKED_FIELD = _require.LINKED_FIELD,
27
28
  MODULE_IMPORT = _require.MODULE_IMPORT,
29
+ REQUIRED_FIELD = _require.REQUIRED_FIELD,
28
30
  SCALAR_FIELD = _require.SCALAR_FIELD,
29
31
  STREAM = _require.STREAM;
30
32
 
31
- var _require2 = require('./RelayStoreUtils'),
32
- FRAGMENTS_KEY = _require2.FRAGMENTS_KEY,
33
- FRAGMENT_OWNER_KEY = _require2.FRAGMENT_OWNER_KEY,
34
- FRAGMENT_PROP_NAME_KEY = _require2.FRAGMENT_PROP_NAME_KEY,
35
- ID_KEY = _require2.ID_KEY,
36
- IS_WITHIN_UNMATCHED_TYPE_REFINEMENT = _require2.IS_WITHIN_UNMATCHED_TYPE_REFINEMENT,
37
- MODULE_COMPONENT_KEY = _require2.MODULE_COMPONENT_KEY,
38
- ROOT_ID = _require2.ROOT_ID,
39
- getArgumentValues = _require2.getArgumentValues,
40
- getStorageKey = _require2.getStorageKey,
41
- getModuleComponentKey = _require2.getModuleComponentKey;
42
-
43
- var _require3 = require('./TypeID'),
44
- generateTypeID = _require3.generateTypeID;
33
+ var _require2 = require('./RelayStoreReactFlightUtils'),
34
+ getReactFlightClientResponse = _require2.getReactFlightClientResponse;
35
+
36
+ var _require3 = require('./RelayStoreUtils'),
37
+ FRAGMENTS_KEY = _require3.FRAGMENTS_KEY,
38
+ FRAGMENT_OWNER_KEY = _require3.FRAGMENT_OWNER_KEY,
39
+ FRAGMENT_PROP_NAME_KEY = _require3.FRAGMENT_PROP_NAME_KEY,
40
+ ID_KEY = _require3.ID_KEY,
41
+ IS_WITHIN_UNMATCHED_TYPE_REFINEMENT = _require3.IS_WITHIN_UNMATCHED_TYPE_REFINEMENT,
42
+ MODULE_COMPONENT_KEY = _require3.MODULE_COMPONENT_KEY,
43
+ ROOT_ID = _require3.ROOT_ID,
44
+ getArgumentValues = _require3.getArgumentValues,
45
+ getStorageKey = _require3.getStorageKey,
46
+ getModuleComponentKey = _require3.getModuleComponentKey;
47
+
48
+ var _require4 = require('./TypeID'),
49
+ generateTypeID = _require4.generateTypeID;
45
50
 
46
51
  function read(recordSource, selector) {
47
52
  var reader = new RelayReader(recordSource, selector);
@@ -56,6 +61,7 @@ var RelayReader = /*#__PURE__*/function () {
56
61
  function RelayReader(recordSource, selector) {
57
62
  this._isMissingData = false;
58
63
  this._isWithinUnmatchedTypeRefinement = false;
64
+ this._missingRequiredFields = null;
59
65
  this._owner = selector.owner;
60
66
  this._recordSource = recordSource;
61
67
  this._seenRecords = {};
@@ -124,7 +130,8 @@ var RelayReader = /*#__PURE__*/function () {
124
130
  data: data,
125
131
  isMissingData: this._isMissingData && isDataExpectedToBePresent,
126
132
  seenRecords: this._seenRecords,
127
- selector: this._selector
133
+ selector: this._selector,
134
+ missingRequiredFields: this._missingRequiredFields
128
135
  };
129
136
  };
130
137
 
@@ -143,9 +150,9 @@ var RelayReader = /*#__PURE__*/function () {
143
150
 
144
151
  var data = prevData || {};
145
152
 
146
- this._traverseSelections(node.selections, record, data);
153
+ var hadRequiredData = this._traverseSelections(node.selections, record, data);
147
154
 
148
- return data;
155
+ return hadRequiredData ? data : null;
149
156
  };
150
157
 
151
158
  _proto._getVariableValue = function _getVariableValue(name) {
@@ -153,11 +160,76 @@ var RelayReader = /*#__PURE__*/function () {
153
160
  return this._variables[name];
154
161
  };
155
162
 
156
- _proto._traverseSelections = function _traverseSelections(selections, record, data) {
163
+ _proto._maybeReportUnexpectedNull = function _maybeReportUnexpectedNull(fieldPath, action, record) {
164
+ var _this$_missingRequire;
165
+
166
+ if (((_this$_missingRequire = this._missingRequiredFields) === null || _this$_missingRequire === void 0 ? void 0 : _this$_missingRequire.action) === 'THROW') {
167
+ // Chained @required directives may cause a parent `@required(action:
168
+ // THROW)` field to become null, so the first missing field we
169
+ // encounter is likely to be the root cause of the error.
170
+ return;
171
+ }
172
+
173
+ var owner = this._selector.node.name;
174
+
175
+ switch (action) {
176
+ case 'THROW':
177
+ this._missingRequiredFields = {
178
+ action: action,
179
+ field: {
180
+ path: fieldPath,
181
+ owner: owner
182
+ }
183
+ };
184
+ return;
185
+
186
+ case 'LOG':
187
+ if (this._missingRequiredFields == null) {
188
+ this._missingRequiredFields = {
189
+ action: action,
190
+ fields: []
191
+ };
192
+ }
193
+
194
+ this._missingRequiredFields.fields.push({
195
+ path: fieldPath,
196
+ owner: owner
197
+ });
198
+
199
+ return;
200
+
201
+ default:
202
+ action;
203
+ }
204
+ };
205
+
206
+ _proto._traverseSelections = function _traverseSelections(selections, record, data)
207
+ /* had all expected data */
208
+ {
157
209
  for (var i = 0; i < selections.length; i++) {
158
210
  var selection = selections[i];
159
211
 
160
212
  switch (selection.kind) {
213
+ case REQUIRED_FIELD:
214
+ !RelayFeatureFlags.ENABLE_REQUIRED_DIRECTIVES ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Encountered a `@required` directive at path "%s" in `%s` without the `ENABLE_REQUIRED_DIRECTIVES` feature flag enabled.', selection.path, this._selector.node.name) : invariant(false) : void 0;
215
+
216
+ var fieldValue = this._readRequiredField(selection, record, data);
217
+
218
+ if (fieldValue == null) {
219
+ var action = selection.action;
220
+
221
+ if (action !== 'NONE') {
222
+ this._maybeReportUnexpectedNull(selection.path, action, record);
223
+ } // We are going to throw, or our parent is going to get nulled out.
224
+ // Either way, sibling values are going to be ignored, so we can
225
+ // bail early here as an optimization.
226
+
227
+
228
+ return false;
229
+ }
230
+
231
+ break;
232
+
161
233
  case SCALAR_FIELD:
162
234
  this._readScalar(selection, record, data);
163
235
 
@@ -176,7 +248,11 @@ var RelayReader = /*#__PURE__*/function () {
176
248
  var conditionValue = this._getVariableValue(selection.condition);
177
249
 
178
250
  if (conditionValue === selection.passingValue) {
179
- this._traverseSelections(selection.selections, record, data);
251
+ var hasExpectedData = this._traverseSelections(selection.selections, record, data);
252
+
253
+ if (!hasExpectedData) {
254
+ return false;
255
+ }
180
256
  }
181
257
 
182
258
  break;
@@ -190,7 +266,11 @@ var RelayReader = /*#__PURE__*/function () {
190
266
  var typeName = RelayModernRecord.getType(record);
191
267
 
192
268
  if (typeName != null && typeName === selection.type) {
193
- this._traverseSelections(selection.selections, record, data);
269
+ var _hasExpectedData = this._traverseSelections(selection.selections, record, data);
270
+
271
+ if (!_hasExpectedData) {
272
+ return false;
273
+ }
194
274
  }
195
275
  } else if (RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
196
276
  // Similar to the logic in read(): data is only expected to be present
@@ -246,15 +326,37 @@ var RelayReader = /*#__PURE__*/function () {
246
326
 
247
327
  case DEFER:
248
328
  case CLIENT_EXTENSION:
249
- var isMissingData = this._isMissingData;
329
+ {
330
+ var isMissingData = this._isMissingData;
250
331
 
251
- this._traverseSelections(selection.selections, record, data);
332
+ var _hasExpectedData2 = this._traverseSelections(selection.selections, record, data);
252
333
 
253
- this._isMissingData = isMissingData;
254
- break;
334
+ this._isMissingData = isMissingData;
335
+
336
+ if (!_hasExpectedData2) {
337
+ return false;
338
+ }
339
+
340
+ break;
341
+ }
255
342
 
256
343
  case STREAM:
257
- this._traverseSelections(selection.selections, record, data);
344
+ {
345
+ var _hasExpectedData3 = this._traverseSelections(selection.selections, record, data);
346
+
347
+ if (!_hasExpectedData3) {
348
+ return false;
349
+ }
350
+
351
+ break;
352
+ }
353
+
354
+ case FLIGHT_FIELD:
355
+ if (RelayFeatureFlags.ENABLE_REACT_FLIGHT_COMPONENT_FIELD) {
356
+ this._readFlightField(selection, record, data);
357
+ } else {
358
+ throw new Error('Flight fields are not yet supported.');
359
+ }
258
360
 
259
361
  break;
260
362
 
@@ -263,13 +365,69 @@ var RelayReader = /*#__PURE__*/function () {
263
365
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
264
366
  }
265
367
  }
368
+
369
+ return true;
266
370
  };
267
371
 
268
- _proto._readScalar = function _readScalar(field, record, data) {
372
+ _proto._readRequiredField = function _readRequiredField(selection, record, data) {
373
+ switch (selection.field.kind) {
374
+ case SCALAR_FIELD:
375
+ return this._readScalar(selection.field, record, data);
376
+
377
+ case LINKED_FIELD:
378
+ if (selection.field.plural) {
379
+ return this._readPluralLink(selection.field, record, data);
380
+ } else {
381
+ return this._readLink(selection.field, record, data);
382
+ }
383
+
384
+ default:
385
+ selection.field.kind;
386
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
387
+ }
388
+ };
389
+
390
+ _proto._readFlightField = function _readFlightField(field, record, data) {
269
391
  var _field$alias;
270
392
 
271
393
  var applicationName = (_field$alias = field.alias) !== null && _field$alias !== void 0 ? _field$alias : field.name;
272
394
  var storageKey = getStorageKey(field, this._variables);
395
+ var reactFlightClientResponseRecordID = RelayModernRecord.getLinkedRecordID(record, storageKey);
396
+
397
+ if (reactFlightClientResponseRecordID == null) {
398
+ data[applicationName] = reactFlightClientResponseRecordID;
399
+
400
+ if (reactFlightClientResponseRecordID === undefined) {
401
+ this._isMissingData = true;
402
+ }
403
+
404
+ return reactFlightClientResponseRecordID;
405
+ }
406
+
407
+ var reactFlightClientResponseRecord = this._recordSource.get(reactFlightClientResponseRecordID);
408
+
409
+ this._seenRecords[reactFlightClientResponseRecordID] = reactFlightClientResponseRecord;
410
+
411
+ if (reactFlightClientResponseRecord == null) {
412
+ data[applicationName] = reactFlightClientResponseRecord;
413
+
414
+ if (reactFlightClientResponseRecord === undefined) {
415
+ this._isMissingData = true;
416
+ }
417
+
418
+ return reactFlightClientResponseRecord;
419
+ }
420
+
421
+ var clientResponse = getReactFlightClientResponse(reactFlightClientResponseRecord);
422
+ data[applicationName] = clientResponse;
423
+ return clientResponse;
424
+ };
425
+
426
+ _proto._readScalar = function _readScalar(field, record, data) {
427
+ var _field$alias2;
428
+
429
+ var applicationName = (_field$alias2 = field.alias) !== null && _field$alias2 !== void 0 ? _field$alias2 : field.name;
430
+ var storageKey = getStorageKey(field, this._variables);
273
431
  var value = RelayModernRecord.getValue(record, storageKey);
274
432
 
275
433
  if (value === undefined) {
@@ -277,12 +435,13 @@ var RelayReader = /*#__PURE__*/function () {
277
435
  }
278
436
 
279
437
  data[applicationName] = value;
438
+ return value;
280
439
  };
281
440
 
282
441
  _proto._readLink = function _readLink(field, record, data) {
283
- var _field$alias2;
442
+ var _field$alias3;
284
443
 
285
- var applicationName = (_field$alias2 = field.alias) !== null && _field$alias2 !== void 0 ? _field$alias2 : field.name;
444
+ var applicationName = (_field$alias3 = field.alias) !== null && _field$alias3 !== void 0 ? _field$alias3 : field.name;
286
445
  var storageKey = getStorageKey(field, this._variables);
287
446
  var linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
288
447
 
@@ -293,21 +452,24 @@ var RelayReader = /*#__PURE__*/function () {
293
452
  this._isMissingData = true;
294
453
  }
295
454
 
296
- return;
455
+ return linkedID;
297
456
  }
298
457
 
299
458
  var prevData = data[applicationName];
300
459
  !(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]
301
460
 
302
- data[applicationName] = this._traverse(field, linkedID, prevData);
461
+ var value = this._traverse(field, linkedID, prevData);
462
+
463
+ data[applicationName] = value;
464
+ return value;
303
465
  };
304
466
 
305
467
  _proto._readPluralLink = function _readPluralLink(field, record, data) {
306
468
  var _this = this;
307
469
 
308
- var _field$alias3;
470
+ var _field$alias4;
309
471
 
310
- var applicationName = (_field$alias3 = field.alias) !== null && _field$alias3 !== void 0 ? _field$alias3 : field.name;
472
+ var applicationName = (_field$alias4 = field.alias) !== null && _field$alias4 !== void 0 ? _field$alias4 : field.name;
311
473
  var storageKey = getStorageKey(field, this._variables);
312
474
  var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
313
475
 
@@ -318,7 +480,7 @@ var RelayReader = /*#__PURE__*/function () {
318
480
  this._isMissingData = true;
319
481
  }
320
482
 
321
- return;
483
+ return linkedIDs;
322
484
  }
323
485
 
324
486
  var prevData = data[applicationName];
@@ -342,6 +504,7 @@ var RelayReader = /*#__PURE__*/function () {
342
504
  linkedArray[nextIndex] = _this._traverse(field, linkedID, prevItem);
343
505
  });
344
506
  data[applicationName] = linkedArray;
507
+ return linkedArray;
345
508
  }
346
509
  /**
347
510
  * Reads a ReaderModuleImport, which was generated from using the @module
@@ -10,9 +10,9 @@
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; } } }; }
13
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; 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 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
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); }
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(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
16
 
17
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
18