relay-runtime 9.0.0 → 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 (142) hide show
  1. package/handlers/RelayDefaultHandlerProvider.js.flow +47 -0
  2. package/handlers/connection/ConnectionHandler.js.flow +549 -0
  3. package/handlers/connection/ConnectionInterface.js.flow +92 -0
  4. package/handlers/connection/MutationHandlers.js.flow +199 -0
  5. package/index.js +1 -1
  6. package/index.js.flow +335 -0
  7. package/lib/handlers/RelayDefaultHandlerProvider.js +20 -0
  8. package/lib/handlers/connection/ConnectionHandler.js +1 -3
  9. package/lib/handlers/connection/MutationHandlers.js +212 -0
  10. package/lib/index.js +14 -2
  11. package/lib/mutations/RelayDeclarativeMutationConfig.js +22 -45
  12. package/lib/mutations/RelayRecordProxy.js +1 -3
  13. package/lib/mutations/RelayRecordSourceMutator.js +1 -3
  14. package/lib/mutations/RelayRecordSourceProxy.js +1 -3
  15. package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -3
  16. package/lib/mutations/commitMutation.js +2 -3
  17. package/lib/mutations/validateMutation.js +40 -9
  18. package/lib/network/RelayObservable.js +9 -9
  19. package/lib/network/RelayQueryResponseCache.js +8 -6
  20. package/lib/query/GraphQLTag.js +2 -1
  21. package/lib/query/PreloadableQueryRegistry.js +70 -0
  22. package/lib/query/fetchQuery.js +2 -3
  23. package/lib/query/fetchQueryInternal.js +5 -14
  24. package/lib/store/DataChecker.js +200 -71
  25. package/lib/store/RelayConcreteVariables.js +6 -2
  26. package/lib/store/RelayModernEnvironment.js +124 -65
  27. package/lib/store/RelayModernFragmentSpecResolver.js +19 -14
  28. package/lib/store/RelayModernOperationDescriptor.js +6 -5
  29. package/lib/store/RelayModernQueryExecutor.js +122 -73
  30. package/lib/store/RelayModernRecord.js +14 -9
  31. package/lib/store/RelayModernSelector.js +6 -2
  32. package/lib/store/RelayModernStore.js +281 -131
  33. package/lib/store/RelayOperationTracker.js +35 -78
  34. package/lib/store/RelayOptimisticRecordSource.js +7 -5
  35. package/lib/store/RelayPublishQueue.js +2 -4
  36. package/lib/store/RelayReader.js +304 -52
  37. package/lib/store/RelayRecordSource.js +1 -3
  38. package/lib/store/RelayRecordSourceMapImpl.js +13 -18
  39. package/lib/store/RelayReferenceMarker.js +125 -14
  40. package/lib/store/RelayResponseNormalizer.js +261 -66
  41. package/lib/store/RelayStoreReactFlightUtils.js +47 -0
  42. package/lib/store/RelayStoreUtils.js +1 -0
  43. package/lib/store/StoreInspector.js +8 -8
  44. package/lib/store/TypeID.js +28 -0
  45. package/lib/store/cloneRelayScalarHandleSourceField.js +44 -0
  46. package/lib/store/defaultRequiredFieldLogger.js +18 -0
  47. package/lib/store/normalizeRelayPayload.js +6 -2
  48. package/lib/store/readInlineData.js +1 -1
  49. package/lib/subscription/requestSubscription.js +4 -3
  50. package/lib/util/NormalizationNode.js +1 -5
  51. package/lib/util/RelayConcreteNode.js +11 -6
  52. package/lib/util/RelayError.js +39 -9
  53. package/lib/util/RelayFeatureFlags.js +6 -3
  54. package/lib/util/RelayReplaySubject.js +3 -3
  55. package/lib/util/createPayloadFor3DField.js +7 -2
  56. package/lib/util/getFragmentIdentifier.js +12 -3
  57. package/lib/util/getOperation.js +33 -0
  58. package/lib/util/getRequestIdentifier.js +2 -2
  59. package/lib/util/isEmptyObject.js +25 -0
  60. package/lib/util/recycleNodesInto.js +6 -7
  61. package/lib/util/reportMissingRequiredFields.js +48 -0
  62. package/mutations/RelayDeclarativeMutationConfig.js.flow +380 -0
  63. package/mutations/RelayRecordProxy.js.flow +165 -0
  64. package/mutations/RelayRecordSourceMutator.js.flow +238 -0
  65. package/mutations/RelayRecordSourceProxy.js.flow +164 -0
  66. package/mutations/RelayRecordSourceSelectorProxy.js.flow +119 -0
  67. package/mutations/applyOptimisticMutation.js.flow +76 -0
  68. package/mutations/commitLocalUpdate.js.flow +24 -0
  69. package/mutations/commitMutation.js.flow +181 -0
  70. package/mutations/validateMutation.js.flow +242 -0
  71. package/network/ConvertToExecuteFunction.js.flow +49 -0
  72. package/network/RelayNetwork.js.flow +84 -0
  73. package/network/RelayNetworkTypes.js.flow +145 -0
  74. package/network/RelayObservable.js.flow +634 -0
  75. package/network/RelayQueryResponseCache.js.flow +111 -0
  76. package/package.json +2 -2
  77. package/query/GraphQLTag.js.flow +168 -0
  78. package/query/PreloadableQueryRegistry.js.flow +65 -0
  79. package/query/fetchQuery.js.flow +47 -0
  80. package/query/fetchQueryInternal.js.flow +343 -0
  81. package/relay-runtime.js +2 -2
  82. package/relay-runtime.min.js +2 -2
  83. package/store/ClientID.js.flow +43 -0
  84. package/store/DataChecker.js.flow +568 -0
  85. package/store/RelayConcreteVariables.js.flow +96 -0
  86. package/store/RelayModernEnvironment.js.flow +571 -0
  87. package/store/RelayModernFragmentSpecResolver.js.flow +438 -0
  88. package/store/RelayModernOperationDescriptor.js.flow +92 -0
  89. package/store/RelayModernQueryExecutor.js.flow +1345 -0
  90. package/store/RelayModernRecord.js.flow +403 -0
  91. package/store/RelayModernSelector.js.flow +455 -0
  92. package/store/RelayModernStore.js.flow +858 -0
  93. package/store/RelayOperationTracker.js.flow +164 -0
  94. package/store/RelayOptimisticRecordSource.js.flow +119 -0
  95. package/store/RelayPublishQueue.js.flow +401 -0
  96. package/store/RelayReader.js.flow +638 -0
  97. package/store/RelayRecordSource.js.flow +29 -0
  98. package/store/RelayRecordSourceMapImpl.js.flow +87 -0
  99. package/store/RelayRecordState.js.flow +37 -0
  100. package/store/RelayReferenceMarker.js.flow +324 -0
  101. package/store/RelayResponseNormalizer.js.flow +791 -0
  102. package/store/RelayStoreReactFlightUtils.js.flow +64 -0
  103. package/store/RelayStoreTypes.js.flow +958 -0
  104. package/store/RelayStoreUtils.js.flow +219 -0
  105. package/store/StoreInspector.js.flow +171 -0
  106. package/store/TypeID.js.flow +28 -0
  107. package/store/ViewerPattern.js.flow +26 -0
  108. package/store/cloneRelayHandleSourceField.js.flow +66 -0
  109. package/store/cloneRelayScalarHandleSourceField.js.flow +62 -0
  110. package/store/createFragmentSpecResolver.js.flow +55 -0
  111. package/store/createRelayContext.js.flow +44 -0
  112. package/store/defaultGetDataID.js.flow +27 -0
  113. package/store/defaultRequiredFieldLogger.js.flow +23 -0
  114. package/store/hasOverlappingIDs.js.flow +34 -0
  115. package/store/isRelayModernEnvironment.js.flow +27 -0
  116. package/store/normalizeRelayPayload.js.flow +51 -0
  117. package/store/readInlineData.js.flow +75 -0
  118. package/subscription/requestSubscription.js.flow +103 -0
  119. package/util/JSResourceTypes.flow.js.flow +20 -0
  120. package/util/NormalizationNode.js.flow +213 -0
  121. package/util/ReaderNode.js.flow +227 -0
  122. package/util/RelayConcreteNode.js.flow +99 -0
  123. package/util/RelayDefaultHandleKey.js.flow +17 -0
  124. package/util/RelayError.js.flow +62 -0
  125. package/util/RelayFeatureFlags.js.flow +37 -0
  126. package/util/RelayProfiler.js.flow +284 -0
  127. package/util/RelayReplaySubject.js.flow +135 -0
  128. package/util/RelayRuntimeTypes.js.flow +72 -0
  129. package/util/createPayloadFor3DField.js.flow +43 -0
  130. package/util/deepFreeze.js.flow +36 -0
  131. package/util/generateID.js.flow +21 -0
  132. package/util/getFragmentIdentifier.js.flow +76 -0
  133. package/util/getOperation.js.flow +40 -0
  134. package/util/getRelayHandleKey.js.flow +41 -0
  135. package/util/getRequestIdentifier.js.flow +42 -0
  136. package/util/isEmptyObject.js.flow +25 -0
  137. package/util/isPromise.js.flow +21 -0
  138. package/util/isScalarAndEqual.js.flow +26 -0
  139. package/util/recycleNodesInto.js.flow +87 -0
  140. package/util/reportMissingRequiredFields.js.flow +51 -0
  141. package/util/resolveImmediate.js.flow +30 -0
  142. package/util/stableCopy.js.flow +35 -0
@@ -10,6 +10,8 @@
10
10
  // flowlint ambiguous-object-type:error
11
11
  'use strict';
12
12
 
13
+ var RelayFeatureFlags = require('../util/RelayFeatureFlags');
14
+
13
15
  var RelayModernRecord = require('./RelayModernRecord');
14
16
 
15
17
  var invariant = require("fbjs/lib/invariant");
@@ -18,23 +20,33 @@ var _require = require('../util/RelayConcreteNode'),
18
20
  CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
19
21
  CONDITION = _require.CONDITION,
20
22
  DEFER = _require.DEFER,
23
+ FLIGHT_FIELD = _require.FLIGHT_FIELD,
21
24
  FRAGMENT_SPREAD = _require.FRAGMENT_SPREAD,
22
25
  INLINE_DATA_FRAGMENT_SPREAD = _require.INLINE_DATA_FRAGMENT_SPREAD,
23
26
  INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
24
27
  LINKED_FIELD = _require.LINKED_FIELD,
25
28
  MODULE_IMPORT = _require.MODULE_IMPORT,
29
+ REQUIRED_FIELD = _require.REQUIRED_FIELD,
26
30
  SCALAR_FIELD = _require.SCALAR_FIELD,
27
31
  STREAM = _require.STREAM;
28
32
 
29
- var _require2 = require('./RelayStoreUtils'),
30
- FRAGMENTS_KEY = _require2.FRAGMENTS_KEY,
31
- FRAGMENT_OWNER_KEY = _require2.FRAGMENT_OWNER_KEY,
32
- FRAGMENT_PROP_NAME_KEY = _require2.FRAGMENT_PROP_NAME_KEY,
33
- ID_KEY = _require2.ID_KEY,
34
- MODULE_COMPONENT_KEY = _require2.MODULE_COMPONENT_KEY,
35
- getArgumentValues = _require2.getArgumentValues,
36
- getStorageKey = _require2.getStorageKey,
37
- getModuleComponentKey = _require2.getModuleComponentKey;
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;
38
50
 
39
51
  function read(recordSource, selector) {
40
52
  var reader = new RelayReader(recordSource, selector);
@@ -45,11 +57,11 @@ function read(recordSource, selector) {
45
57
  */
46
58
 
47
59
 
48
- var RelayReader =
49
- /*#__PURE__*/
50
- function () {
60
+ var RelayReader = /*#__PURE__*/function () {
51
61
  function RelayReader(recordSource, selector) {
52
62
  this._isMissingData = false;
63
+ this._isWithinUnmatchedTypeRefinement = false;
64
+ this._missingRequiredFields = null;
53
65
  this._owner = selector.owner;
54
66
  this._recordSource = recordSource;
55
67
  this._seenRecords = {};
@@ -62,15 +74,64 @@ function () {
62
74
  _proto.read = function read() {
63
75
  var _this$_selector = this._selector,
64
76
  node = _this$_selector.node,
65
- dataID = _this$_selector.dataID;
77
+ dataID = _this$_selector.dataID,
78
+ isWithinUnmatchedTypeRefinement = _this$_selector.isWithinUnmatchedTypeRefinement;
79
+ var abstractKey = node.abstractKey;
80
+
81
+ var record = this._recordSource.get(dataID); // Relay historically allowed child fragments to be read even if the root object
82
+ // did not match the type of the fragment: either the root object has a different
83
+ // concrete type than the fragment (for concrete fragments) or the root object does
84
+ // not conform to the interface/union for abstract fragments.
85
+ // For suspense purposes, however, we want to accurately compute whether any data
86
+ // is missing: but if the fragment type doesn't match (or a parent type didn't
87
+ // match), then no data is expected to be present.
88
+ // By default data is expected to be present unless this selector was read out
89
+ // from within a non-matching type refinement in a parent fragment:
90
+
91
+
92
+ var isDataExpectedToBePresent = !isWithinUnmatchedTypeRefinement; // If this is a concrete fragment and the concrete type of the record does not
93
+ // match, then no data is expected to be present.
94
+
95
+ if (isDataExpectedToBePresent && abstractKey == null && record != null) {
96
+ var recordType = RelayModernRecord.getType(record);
97
+
98
+ if (recordType !== node.type && dataID !== ROOT_ID) {
99
+ isDataExpectedToBePresent = false;
100
+ }
101
+ } // If this is an abstract fragment (and the precise refinement GK is enabled)
102
+ // then data is only expected to be present if the record type is known to
103
+ // implement the interface. If we aren't sure whether the record implements
104
+ // the interface, that itself constitutes "expected" data being missing.
105
+
106
+
107
+ if (isDataExpectedToBePresent && abstractKey != null && record != null && RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
108
+ var _recordType = RelayModernRecord.getType(record);
109
+
110
+ var typeID = generateTypeID(_recordType);
111
+
112
+ var typeRecord = this._recordSource.get(typeID);
113
+
114
+ var implementsInterface = typeRecord != null ? RelayModernRecord.getValue(typeRecord, abstractKey) : null;
115
+
116
+ if (implementsInterface === false) {
117
+ // Type known to not implement the interface
118
+ isDataExpectedToBePresent = false;
119
+ } else if (implementsInterface == null) {
120
+ // Don't know if the type implements the interface or not
121
+ this._isMissingData = true;
122
+ }
123
+ }
124
+
125
+ this._isWithinUnmatchedTypeRefinement = !isDataExpectedToBePresent;
66
126
 
67
127
  var data = this._traverse(node, dataID, null);
68
128
 
69
129
  return {
70
130
  data: data,
71
- isMissingData: this._isMissingData,
131
+ isMissingData: this._isMissingData && isDataExpectedToBePresent,
72
132
  seenRecords: this._seenRecords,
73
- selector: this._selector
133
+ selector: this._selector,
134
+ missingRequiredFields: this._missingRequiredFields
74
135
  };
75
136
  };
76
137
 
@@ -89,9 +150,9 @@ function () {
89
150
 
90
151
  var data = prevData || {};
91
152
 
92
- this._traverseSelections(node.selections, record, data);
153
+ var hadRequiredData = this._traverseSelections(node.selections, record, data);
93
154
 
94
- return data;
155
+ return hadRequiredData ? data : null;
95
156
  };
96
157
 
97
158
  _proto._getVariableValue = function _getVariableValue(name) {
@@ -99,11 +160,76 @@ function () {
99
160
  return this._variables[name];
100
161
  };
101
162
 
102
- _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
+ {
103
209
  for (var i = 0; i < selections.length; i++) {
104
210
  var selection = selections[i];
105
211
 
106
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
+
107
233
  case SCALAR_FIELD:
108
234
  this._readScalar(selection, record, data);
109
235
 
@@ -122,20 +248,67 @@ function () {
122
248
  var conditionValue = this._getVariableValue(selection.condition);
123
249
 
124
250
  if (conditionValue === selection.passingValue) {
125
- this._traverseSelections(selection.selections, record, data);
251
+ var hasExpectedData = this._traverseSelections(selection.selections, record, data);
252
+
253
+ if (!hasExpectedData) {
254
+ return false;
255
+ }
126
256
  }
127
257
 
128
258
  break;
129
259
 
130
260
  case INLINE_FRAGMENT:
131
- var typeName = RelayModernRecord.getType(record);
132
-
133
- if (typeName != null && typeName === selection.type) {
134
- this._traverseSelections(selection.selections, record, data);
261
+ {
262
+ var abstractKey = selection.abstractKey;
263
+
264
+ if (abstractKey == null) {
265
+ // concrete type refinement: only read data if the type exactly matches
266
+ var typeName = RelayModernRecord.getType(record);
267
+
268
+ if (typeName != null && typeName === selection.type) {
269
+ var _hasExpectedData = this._traverseSelections(selection.selections, record, data);
270
+
271
+ if (!_hasExpectedData) {
272
+ return false;
273
+ }
274
+ }
275
+ } else if (RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
276
+ // Similar to the logic in read(): data is only expected to be present
277
+ // if the record is known to conform to the interface. If we don't know
278
+ // whether the type conforms or not, that constitutes missing data.
279
+ // store flags to reset after reading
280
+ var parentIsMissingData = this._isMissingData;
281
+ var parentIsWithinUnmatchedTypeRefinement = this._isWithinUnmatchedTypeRefinement;
282
+
283
+ var _typeName = RelayModernRecord.getType(record);
284
+
285
+ var typeID = generateTypeID(_typeName);
286
+
287
+ var typeRecord = this._recordSource.get(typeID);
288
+
289
+ var implementsInterface = typeRecord != null ? RelayModernRecord.getValue(typeRecord, abstractKey) : null;
290
+ this._isWithinUnmatchedTypeRefinement = parentIsWithinUnmatchedTypeRefinement || implementsInterface === false;
291
+
292
+ this._traverseSelections(selection.selections, record, data);
293
+
294
+ this._isWithinUnmatchedTypeRefinement = parentIsWithinUnmatchedTypeRefinement;
295
+
296
+ if (implementsInterface === false) {
297
+ // Type known to not implement the interface, no data expected
298
+ this._isMissingData = parentIsMissingData;
299
+ } else if (implementsInterface == null) {
300
+ // Don't know if the type implements the interface or not
301
+ this._isMissingData = true;
302
+ }
303
+ } else {
304
+ // legacy behavior for abstract refinements: always read even
305
+ // if the type doesn't conform and don't reset isMissingData
306
+ this._traverseSelections(selection.selections, record, data);
307
+ }
308
+
309
+ break;
135
310
  }
136
311
 
137
- break;
138
-
139
312
  case FRAGMENT_SPREAD:
140
313
  this._createFragmentPointer(selection, record, data);
141
314
 
@@ -153,15 +326,37 @@ function () {
153
326
 
154
327
  case DEFER:
155
328
  case CLIENT_EXTENSION:
156
- var isMissingData = this._isMissingData;
329
+ {
330
+ var isMissingData = this._isMissingData;
157
331
 
158
- this._traverseSelections(selection.selections, record, data);
332
+ var _hasExpectedData2 = this._traverseSelections(selection.selections, record, data);
159
333
 
160
- this._isMissingData = isMissingData;
161
- break;
334
+ this._isMissingData = isMissingData;
335
+
336
+ if (!_hasExpectedData2) {
337
+ return false;
338
+ }
339
+
340
+ break;
341
+ }
162
342
 
163
343
  case STREAM:
164
- 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
+ }
165
360
 
166
361
  break;
167
362
 
@@ -170,13 +365,69 @@ function () {
170
365
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
171
366
  }
172
367
  }
368
+
369
+ return true;
173
370
  };
174
371
 
175
- _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) {
176
391
  var _field$alias;
177
392
 
178
393
  var applicationName = (_field$alias = field.alias) !== null && _field$alias !== void 0 ? _field$alias : field.name;
179
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);
180
431
  var value = RelayModernRecord.getValue(record, storageKey);
181
432
 
182
433
  if (value === undefined) {
@@ -184,12 +435,13 @@ function () {
184
435
  }
185
436
 
186
437
  data[applicationName] = value;
438
+ return value;
187
439
  };
188
440
 
189
441
  _proto._readLink = function _readLink(field, record, data) {
190
- var _field$alias2;
442
+ var _field$alias3;
191
443
 
192
- 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;
193
445
  var storageKey = getStorageKey(field, this._variables);
194
446
  var linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
195
447
 
@@ -200,24 +452,24 @@ function () {
200
452
  this._isMissingData = true;
201
453
  }
202
454
 
203
- return;
455
+ return linkedID;
204
456
  }
205
457
 
206
458
  var prevData = data[applicationName];
207
- !(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;
208
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
209
- * suppresses an error found when Flow v0.98 was deployed. To see the error
210
- * delete this comment and run Flow. */
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]
460
+
461
+ var value = this._traverse(field, linkedID, prevData);
211
462
 
212
- data[applicationName] = this._traverse(field, linkedID, prevData);
463
+ data[applicationName] = value;
464
+ return value;
213
465
  };
214
466
 
215
467
  _proto._readPluralLink = function _readPluralLink(field, record, data) {
216
468
  var _this = this;
217
469
 
218
- var _field$alias3;
470
+ var _field$alias4;
219
471
 
220
- 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;
221
473
  var storageKey = getStorageKey(field, this._variables);
222
474
  var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
223
475
 
@@ -228,7 +480,7 @@ function () {
228
480
  this._isMissingData = true;
229
481
  }
230
482
 
231
- return;
483
+ return linkedIDs;
232
484
  }
233
485
 
234
486
  var prevData = data[applicationName];
@@ -238,10 +490,7 @@ function () {
238
490
  if (linkedID == null) {
239
491
  if (linkedID === undefined) {
240
492
  _this._isMissingData = true;
241
- }
242
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
243
- * suppresses an error found when Flow v0.98 was deployed. To see the
244
- * error delete this comment and run Flow. */
493
+ } // $FlowFixMe[cannot-write]
245
494
 
246
495
 
247
496
  linkedArray[nextIndex] = linkedID;
@@ -249,14 +498,13 @@ function () {
249
498
  }
250
499
 
251
500
  var prevItem = linkedArray[nextIndex];
252
- !(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevItem) : invariant(false) : void 0;
253
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
254
- * suppresses an error found when Flow v0.98 was deployed. To see the
255
- * error delete this comment and run Flow. */
501
+ !(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevItem) : invariant(false) : void 0; // $FlowFixMe[cannot-write]
502
+ // $FlowFixMe[incompatible-variance]
256
503
 
257
504
  linkedArray[nextIndex] = _this._traverse(field, linkedID, prevItem);
258
505
  });
259
506
  data[applicationName] = linkedArray;
507
+ return linkedArray;
260
508
  }
261
509
  /**
262
510
  * Reads a ReaderModuleImport, which was generated from using the @module
@@ -304,11 +552,15 @@ function () {
304
552
 
305
553
  if (data[ID_KEY] == null) {
306
554
  data[ID_KEY] = RelayModernRecord.getDataID(record);
307
- } // $FlowFixMe - writing into read-only field
555
+ } // $FlowFixMe[cannot-write] - writing into read-only field
308
556
 
309
557
 
310
558
  fragmentPointers[fragmentSpread.name] = fragmentSpread.args ? getArgumentValues(fragmentSpread.args, this._variables) : {};
311
559
  data[FRAGMENT_OWNER_KEY] = this._owner;
560
+
561
+ if (RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
562
+ data[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] = this._isWithinUnmatchedTypeRefinement;
563
+ }
312
564
  };
313
565
 
314
566
  _proto._createInlineDataFragmentPointer = function _createInlineDataFragmentPointer(inlineDataFragmentSpread, record, data) {
@@ -326,7 +578,7 @@ function () {
326
578
 
327
579
  var inlineData = {};
328
580
 
329
- this._traverseSelections(inlineDataFragmentSpread.selections, record, inlineData); // $FlowFixMe - writing into read-only field
581
+ this._traverseSelections(inlineDataFragmentSpread.selections, record, inlineData); // $FlowFixMe[cannot-write] - writing into read-only field
330
582
 
331
583
 
332
584
  fragmentPointers[inlineDataFragmentSpread.name] = inlineData;
@@ -12,9 +12,7 @@
12
12
 
13
13
  var RelayRecordSourceMapImpl = require('./RelayRecordSourceMapImpl');
14
14
 
15
- var RelayRecordSource =
16
- /*#__PURE__*/
17
- function () {
15
+ var RelayRecordSource = /*#__PURE__*/function () {
18
16
  function RelayRecordSource(records) {
19
17
  return RelayRecordSource.create(records);
20
18
  }
@@ -10,6 +10,12 @@
10
10
  // flowlint ambiguous-object-type:error
11
11
  'use strict';
12
12
 
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
+
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
+
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
+
13
19
  var RelayRecordState = require('./RelayRecordState');
14
20
 
15
21
  var EXISTENT = RelayRecordState.EXISTENT,
@@ -20,9 +26,7 @@ var EXISTENT = RelayRecordState.EXISTENT,
20
26
  * `RelayStoreTypes`) that holds all records in memory (JS Map).
21
27
  */
22
28
 
23
- var RelayMapRecordSourceMapImpl =
24
- /*#__PURE__*/
25
- function () {
29
+ var RelayMapRecordSourceMapImpl = /*#__PURE__*/function () {
26
30
  function RelayMapRecordSourceMapImpl(records) {
27
31
  var _this = this;
28
32
 
@@ -79,30 +83,21 @@ function () {
79
83
 
80
84
  _proto.toJSON = function toJSON() {
81
85
  var obj = {};
82
- var _iteratorNormalCompletion = true;
83
- var _didIteratorError = false;
84
- var _iteratorError = undefined;
86
+
87
+ var _iterator = _createForOfIteratorHelper(this._records),
88
+ _step;
85
89
 
86
90
  try {
87
- for (var _iterator = this._records[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
91
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
88
92
  var _step$value = _step.value,
89
93
  key = _step$value[0],
90
94
  value = _step$value[1];
91
95
  obj[key] = value;
92
96
  }
93
97
  } catch (err) {
94
- _didIteratorError = true;
95
- _iteratorError = err;
98
+ _iterator.e(err);
96
99
  } finally {
97
- try {
98
- if (!_iteratorNormalCompletion && _iterator["return"] != null) {
99
- _iterator["return"]();
100
- }
101
- } finally {
102
- if (_didIteratorError) {
103
- throw _iteratorError;
104
- }
105
- }
100
+ _iterator.f();
106
101
  }
107
102
 
108
103
  return obj;