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
@@ -14,10 +14,20 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
14
14
 
15
15
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
16
16
 
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
+
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
+
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
+
23
+ var RelayFeatureFlags = require('../util/RelayFeatureFlags');
24
+
17
25
  var RelayModernRecord = require('./RelayModernRecord');
18
26
 
19
27
  var RelayProfiler = require('../util/RelayProfiler');
20
28
 
29
+ var areEqual = require("fbjs/lib/areEqual");
30
+
21
31
  var invariant = require("fbjs/lib/invariant");
22
32
 
23
33
  var warning = require("fbjs/lib/warning");
@@ -26,13 +36,15 @@ var _require = require('../util/RelayConcreteNode'),
26
36
  CONDITION = _require.CONDITION,
27
37
  CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
28
38
  DEFER = _require.DEFER,
39
+ FLIGHT_FIELD = _require.FLIGHT_FIELD,
29
40
  INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
30
41
  LINKED_FIELD = _require.LINKED_FIELD,
31
42
  LINKED_HANDLE = _require.LINKED_HANDLE,
32
43
  MODULE_IMPORT = _require.MODULE_IMPORT,
33
44
  SCALAR_FIELD = _require.SCALAR_FIELD,
34
45
  SCALAR_HANDLE = _require.SCALAR_HANDLE,
35
- STREAM = _require.STREAM;
46
+ STREAM = _require.STREAM,
47
+ TYPE_DISCRIMINATOR = _require.TYPE_DISCRIMINATOR;
36
48
 
37
49
  var _require2 = require('./ClientID'),
38
50
  generateClientID = _require2.generateClientID,
@@ -41,13 +53,25 @@ var _require2 = require('./ClientID'),
41
53
  var _require3 = require('./RelayModernSelector'),
42
54
  createNormalizationSelector = _require3.createNormalizationSelector;
43
55
 
44
- var _require4 = require('./RelayStoreUtils'),
45
- getArgumentValues = _require4.getArgumentValues,
46
- getHandleStorageKey = _require4.getHandleStorageKey,
47
- getModuleComponentKey = _require4.getModuleComponentKey,
48
- getModuleOperationKey = _require4.getModuleOperationKey,
49
- getStorageKey = _require4.getStorageKey,
50
- TYPENAME_KEY = _require4.TYPENAME_KEY;
56
+ var _require4 = require('./RelayStoreReactFlightUtils'),
57
+ refineToReactFlightPayloadData = _require4.refineToReactFlightPayloadData,
58
+ REACT_FLIGHT_QUERIES_STORAGE_KEY = _require4.REACT_FLIGHT_QUERIES_STORAGE_KEY,
59
+ REACT_FLIGHT_TREE_STORAGE_KEY = _require4.REACT_FLIGHT_TREE_STORAGE_KEY,
60
+ REACT_FLIGHT_TYPE_NAME = _require4.REACT_FLIGHT_TYPE_NAME;
61
+
62
+ var _require5 = require('./RelayStoreUtils'),
63
+ getArgumentValues = _require5.getArgumentValues,
64
+ getHandleStorageKey = _require5.getHandleStorageKey,
65
+ getModuleComponentKey = _require5.getModuleComponentKey,
66
+ getModuleOperationKey = _require5.getModuleOperationKey,
67
+ getStorageKey = _require5.getStorageKey,
68
+ TYPENAME_KEY = _require5.TYPENAME_KEY,
69
+ ROOT_ID = _require5.ROOT_ID,
70
+ ROOT_TYPE = _require5.ROOT_TYPE;
71
+
72
+ var _require6 = require('./TypeID'),
73
+ generateTypeID = _require6.generateTypeID,
74
+ TYPE_SCHEMA_TYPE = _require6.TYPE_SCHEMA_TYPE;
51
75
 
52
76
  /**
53
77
  * Normalizes the results of a query and standard GraphQL response, writing the
@@ -67,19 +91,19 @@ function normalize(recordSource, selector, response, options) {
67
91
  */
68
92
 
69
93
 
70
- var RelayResponseNormalizer =
71
- /*#__PURE__*/
72
- function () {
94
+ var RelayResponseNormalizer = /*#__PURE__*/function () {
73
95
  function RelayResponseNormalizer(recordSource, variables, options) {
74
96
  this._getDataId = options.getDataID;
75
97
  this._handleFieldPayloads = [];
98
+ this._treatMissingFieldsAsNull = options.treatMissingFieldsAsNull;
76
99
  this._incrementalPlaceholders = [];
77
100
  this._isClientExtension = false;
101
+ this._isUnmatchedAbstractType = false;
78
102
  this._moduleImportPayloads = [];
79
103
  this._path = options.path ? (0, _toConsumableArray2["default"])(options.path) : [];
80
104
  this._recordSource = recordSource;
81
- this._request = options.request;
82
105
  this._variables = variables;
106
+ this._reactFlightPayloadDeserializer = options.reactFlightPayloadDeserializer;
83
107
  }
84
108
 
85
109
  var _proto = RelayResponseNormalizer.prototype;
@@ -133,13 +157,76 @@ function () {
133
157
  break;
134
158
 
135
159
  case INLINE_FRAGMENT:
136
- var _typeName = RelayModernRecord.getType(record);
160
+ {
161
+ var abstractKey = selection.abstractKey;
137
162
 
138
- if (_typeName === selection.type) {
139
- this._traverseSelections(selection, record, data);
163
+ if (abstractKey == null) {
164
+ var _typeName = RelayModernRecord.getType(record);
165
+
166
+ if (_typeName === selection.type) {
167
+ this._traverseSelections(selection, record, data);
168
+ }
169
+ } else if (RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
170
+ var implementsInterface = data.hasOwnProperty(abstractKey);
171
+
172
+ var _typeName2 = RelayModernRecord.getType(record);
173
+
174
+ var typeID = generateTypeID(_typeName2);
175
+
176
+ var typeRecord = this._recordSource.get(typeID);
177
+
178
+ if (typeRecord == null) {
179
+ typeRecord = RelayModernRecord.create(typeID, TYPE_SCHEMA_TYPE);
180
+
181
+ this._recordSource.set(typeID, typeRecord);
182
+ }
183
+
184
+ RelayModernRecord.setValue(typeRecord, abstractKey, implementsInterface);
185
+
186
+ if (implementsInterface) {
187
+ this._traverseSelections(selection, record, data);
188
+ }
189
+ } else {
190
+ // legacy behavior for abstract refinements: always normalize even
191
+ // if the type doesn't conform, but track if the type matches or not
192
+ // for determining whether response fields are expected to be present
193
+ var _implementsInterface = data.hasOwnProperty(abstractKey);
194
+
195
+ var parentIsUnmatchedAbstractType = this._isUnmatchedAbstractType;
196
+ this._isUnmatchedAbstractType = this._isUnmatchedAbstractType || !_implementsInterface;
197
+
198
+ this._traverseSelections(selection, record, data);
199
+
200
+ this._isUnmatchedAbstractType = parentIsUnmatchedAbstractType;
201
+ }
202
+
203
+ break;
140
204
  }
141
205
 
142
- break;
206
+ case TYPE_DISCRIMINATOR:
207
+ {
208
+ if (RelayFeatureFlags.ENABLE_PRECISE_TYPE_REFINEMENT) {
209
+ var _abstractKey = selection.abstractKey;
210
+
211
+ var _implementsInterface2 = data.hasOwnProperty(_abstractKey);
212
+
213
+ var _typeName3 = RelayModernRecord.getType(record);
214
+
215
+ var _typeID = generateTypeID(_typeName3);
216
+
217
+ var _typeRecord = this._recordSource.get(_typeID);
218
+
219
+ if (_typeRecord == null) {
220
+ _typeRecord = RelayModernRecord.create(_typeID, TYPE_SCHEMA_TYPE);
221
+
222
+ this._recordSource.set(_typeID, _typeRecord);
223
+ }
224
+
225
+ RelayModernRecord.setValue(_typeRecord, _abstractKey, _implementsInterface2);
226
+ }
227
+
228
+ break;
229
+ }
143
230
 
144
231
  case LINKED_HANDLE:
145
232
  case SCALAR_HANDLE:
@@ -152,7 +239,8 @@ function () {
152
239
  dataID: RelayModernRecord.getDataID(record),
153
240
  fieldKey: fieldKey,
154
241
  handle: selection.handle,
155
- handleKey: handleKey
242
+ handleKey: handleKey,
243
+ handleArgs: selection.handleArgs ? getArgumentValues(selection.handleArgs, this._variables) : {}
156
244
  });
157
245
 
158
246
  break;
@@ -181,6 +269,15 @@ function () {
181
269
  this._isClientExtension = isClientExtension;
182
270
  break;
183
271
 
272
+ case FLIGHT_FIELD:
273
+ if (RelayFeatureFlags.ENABLE_REACT_FLIGHT_COMPONENT_FIELD) {
274
+ this._normalizeFlightField(node, selection, record, data);
275
+ } else {
276
+ throw new Error('Flight fields are not yet supported.');
277
+ }
278
+
279
+ break;
280
+
184
281
  default:
185
282
  selection;
186
283
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
@@ -240,16 +337,14 @@ function () {
240
337
  };
241
338
 
242
339
  _proto._normalizeModuleImport = function _normalizeModuleImport(parent, moduleImport, record, data) {
243
- var _componentReference, _operationReference;
244
-
245
340
  !(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected data for @module to be an object.') : invariant(false) : void 0;
246
341
  var typeName = RelayModernRecord.getType(record);
247
342
  var componentKey = getModuleComponentKey(moduleImport.documentName);
248
343
  var componentReference = data[componentKey];
249
- RelayModernRecord.setValue(record, componentKey, (_componentReference = componentReference) !== null && _componentReference !== void 0 ? _componentReference : null);
344
+ RelayModernRecord.setValue(record, componentKey, componentReference !== null && componentReference !== void 0 ? componentReference : null);
250
345
  var operationKey = getModuleOperationKey(moduleImport.documentName);
251
346
  var operationReference = data[operationKey];
252
- RelayModernRecord.setValue(record, operationKey, (_operationReference = operationReference) !== null && _operationReference !== void 0 ? _operationReference : null);
347
+ RelayModernRecord.setValue(record, operationKey, operationReference !== null && operationReference !== void 0 ? operationReference : null);
253
348
 
254
349
  if (operationReference != null) {
255
350
  this._moduleImportPayloads.push({
@@ -271,20 +366,36 @@ function () {
271
366
 
272
367
  if (fieldValue == null) {
273
368
  if (fieldValue === undefined) {
274
- // Fields that are missing in the response are not set on the record.
275
- // There are three main cases where this can occur:
369
+ // Fields may be missing in the response in two main cases:
276
370
  // - Inside a client extension: the server will not generally return
277
371
  // values for these fields, but a local update may provide them.
278
- // - Fields on abstract types: these may be missing if the concrete
279
- // response type does not match the abstract type.
280
- //
281
- // Otherwise, missing fields usually indicate a server or user error (
282
- // the latter for manually constructed payloads).
283
- if (process.env.NODE_ENV !== "production") {
284
- process.env.NODE_ENV !== "production" ? warning(this._isClientExtension || parent.kind === LINKED_FIELD && parent.concreteType == null ? true : Object.prototype.hasOwnProperty.call(data, responseKey), 'RelayResponseNormalizer: Payload did not contain a value ' + 'for field `%s: %s`. Check that you are parsing with the same ' + 'query that was used to fetch the payload.', responseKey, storageKey) : void 0;
372
+ // - Inside an abstract type refinement where the concrete type does
373
+ // not conform to the interface/union.
374
+ // However an otherwise-required field may also be missing if the server
375
+ // is configured to skip fields with `null` values, in which case the
376
+ // client is assumed to be correctly configured with
377
+ // treatMissingFieldsAsNull=true.
378
+ var isOptionalField = this._isClientExtension || this._isUnmatchedAbstractType;
379
+
380
+ if (isOptionalField) {
381
+ // Field not expected to exist regardless of whether the server is pruning null
382
+ // fields or not.
383
+ return;
384
+ } else if (!this._treatMissingFieldsAsNull) {
385
+ // Not optional and the server is not pruning null fields: field is expected
386
+ // to be present
387
+ if (process.env.NODE_ENV !== "production") {
388
+ process.env.NODE_ENV !== "production" ? warning(false, 'RelayResponseNormalizer: Payload did not contain a value ' + 'for field `%s: %s`. Check that you are parsing with the same ' + 'query that was used to fetch the payload.', responseKey, storageKey) : void 0;
389
+ }
390
+
391
+ return;
285
392
  }
393
+ }
286
394
 
287
- return;
395
+ if (process.env.NODE_ENV !== "production") {
396
+ if (selection.kind === SCALAR_FIELD) {
397
+ this._validateConflictingFieldsWithIdenticalId(record, storageKey, fieldValue);
398
+ }
288
399
  }
289
400
 
290
401
  RelayModernRecord.setValue(record, storageKey, null);
@@ -292,6 +403,10 @@ function () {
292
403
  }
293
404
 
294
405
  if (selection.kind === SCALAR_FIELD) {
406
+ if (process.env.NODE_ENV !== "production") {
407
+ this._validateConflictingFieldsWithIdenticalId(record, storageKey, fieldValue);
408
+ }
409
+
295
410
  RelayModernRecord.setValue(record, storageKey, fieldValue);
296
411
  } else if (selection.kind === LINKED_FIELD) {
297
412
  this._path.push(responseKey);
@@ -309,40 +424,98 @@ function () {
309
424
  }
310
425
  };
311
426
 
427
+ _proto._normalizeFlightField = function _normalizeFlightField(parent, selection, record, data) {
428
+ var responseKey = selection.alias || selection.name;
429
+ var storageKey = getStorageKey(selection, this._variables);
430
+ var fieldValue = data[responseKey];
431
+
432
+ if (fieldValue == null) {
433
+ RelayModernRecord.setValue(record, storageKey, null);
434
+ return;
435
+ }
436
+
437
+ var reactFlightPayload = refineToReactFlightPayloadData(fieldValue);
438
+ !(reactFlightPayload != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Expected React Flight payload data ' + 'to be an object with `tree` and `queries` properties, got `%s`.', fieldValue) : invariant(false) : void 0;
439
+ !(typeof this._reactFlightPayloadDeserializer === 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected reactFlightPayloadDeserializer to ' + 'be a function, got `%s`.', this._reactFlightPayloadDeserializer) : invariant(false) : void 0; // We store the deserialized reactFlightClientResponse in a separate
440
+ // record and link it to the parent record. This is so we can GC the Flight
441
+ // tree later even if the parent record is still reachable.
442
+
443
+ var reactFlightClientResponse = this._reactFlightPayloadDeserializer(reactFlightPayload.tree);
444
+
445
+ var reactFlightID = generateClientID(RelayModernRecord.getDataID(record), getStorageKey(selection, this._variables));
446
+
447
+ var reactFlightClientResponseRecord = this._recordSource.get(reactFlightID);
448
+
449
+ if (reactFlightClientResponseRecord == null) {
450
+ reactFlightClientResponseRecord = RelayModernRecord.create(reactFlightID, REACT_FLIGHT_TYPE_NAME);
451
+
452
+ this._recordSource.set(reactFlightID, reactFlightClientResponseRecord);
453
+ }
454
+
455
+ RelayModernRecord.setValue(reactFlightClientResponseRecord, REACT_FLIGHT_TREE_STORAGE_KEY, reactFlightClientResponse);
456
+ var reachableQueries = [];
457
+
458
+ var _iterator = _createForOfIteratorHelper(reactFlightPayload.queries),
459
+ _step;
460
+
461
+ try {
462
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
463
+ var query = _step.value;
464
+
465
+ if (query.response.data != null) {
466
+ this._moduleImportPayloads.push({
467
+ data: query.response.data,
468
+ dataID: ROOT_ID,
469
+ operationReference: query.module,
470
+ path: [],
471
+ typeName: ROOT_TYPE,
472
+ variables: query.variables
473
+ });
474
+ }
475
+
476
+ reachableQueries.push({
477
+ module: query.module,
478
+ variables: query.variables
479
+ });
480
+ }
481
+ } catch (err) {
482
+ _iterator.e(err);
483
+ } finally {
484
+ _iterator.f();
485
+ }
486
+
487
+ RelayModernRecord.setValue(reactFlightClientResponseRecord, REACT_FLIGHT_QUERIES_STORAGE_KEY, reachableQueries);
488
+ RelayModernRecord.setLinkedRecordID(record, storageKey, reactFlightID);
489
+ };
490
+
312
491
  _proto._normalizeLink = function _normalizeLink(field, record, storageKey, fieldValue) {
313
492
  var _field$concreteType;
314
493
 
315
494
  !(typeof fieldValue === 'object' && fieldValue) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an object.', storageKey) : invariant(false) : void 0;
316
- var nextID = this._getDataId(
317
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
318
- * suppresses an error found when Flow v0.98 was deployed. To see the
319
- * error delete this comment and run Flow. */
320
- fieldValue,
321
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
322
- * suppresses an error found when Flow v0.98 was deployed. To see the
323
- * error delete this comment and run Flow. */
495
+ var nextID = this._getDataId( // $FlowFixMe[incompatible-variance]
496
+ fieldValue, // $FlowFixMe[incompatible-variance]
324
497
  (_field$concreteType = field.concreteType) !== null && _field$concreteType !== void 0 ? _field$concreteType : this._getRecordType(fieldValue)) || // Reuse previously generated client IDs
325
498
  RelayModernRecord.getLinkedRecordID(record, storageKey) || generateClientID(RelayModernRecord.getDataID(record), storageKey);
326
499
  !(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected id on field `%s` to be a string.', storageKey) : invariant(false) : void 0;
500
+
501
+ if (process.env.NODE_ENV !== "production") {
502
+ this._validateConflictingLinkedFieldsWithIdenticalId(record, RelayModernRecord.getLinkedRecordID(record, storageKey), nextID, storageKey);
503
+ }
504
+
327
505
  RelayModernRecord.setLinkedRecordID(record, storageKey, nextID);
328
506
 
329
507
  var nextRecord = this._recordSource.get(nextID);
330
508
 
331
509
  if (!nextRecord) {
332
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
333
- * suppresses an error found when Flow v0.98 was deployed. To see the
334
- * error delete this comment and run Flow. */
335
- var _typeName2 = field.concreteType || this._getRecordType(fieldValue);
510
+ // $FlowFixMe[incompatible-variance]
511
+ var _typeName4 = field.concreteType || this._getRecordType(fieldValue);
336
512
 
337
- nextRecord = RelayModernRecord.create(nextID, _typeName2);
513
+ nextRecord = RelayModernRecord.create(nextID, _typeName4);
338
514
 
339
515
  this._recordSource.set(nextID, nextRecord);
340
516
  } else if (process.env.NODE_ENV !== "production") {
341
517
  this._validateRecordType(nextRecord, field, fieldValue);
342
- }
343
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
344
- * suppresses an error found when Flow v0.98 was deployed. To see the error
345
- * delete this comment and run Flow. */
518
+ } // $FlowFixMe[incompatible-variance]
346
519
 
347
520
 
348
521
  this._traverseSelections(field, nextRecord, fieldValue);
@@ -366,14 +539,8 @@ function () {
366
539
  _this._path.push(String(nextIndex));
367
540
 
368
541
  !(typeof item === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected elements for field `%s` to be ' + 'objects.', storageKey) : invariant(false) : void 0;
369
- var nextID = _this._getDataId(
370
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
371
- * suppresses an error found when Flow v0.98 was deployed. To see the
372
- * error delete this comment and run Flow. */
373
- item,
374
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
375
- * suppresses an error found when Flow v0.98 was deployed. To see the
376
- * error delete this comment and run Flow. */
542
+ var nextID = _this._getDataId( // $FlowFixMe[incompatible-variance]
543
+ item, // $FlowFixMe[incompatible-variance]
377
544
  (_field$concreteType2 = field.concreteType) !== null && _field$concreteType2 !== void 0 ? _field$concreteType2 : _this._getRecordType(item)) || prevIDs && prevIDs[nextIndex] || // Reuse previously generated client IDs:
378
545
  generateClientID(RelayModernRecord.getDataID(record), storageKey, nextIndex);
379
546
  !(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected id of elements of field `%s` to ' + 'be strings.', storageKey) : invariant(false) : void 0;
@@ -382,20 +549,23 @@ function () {
382
549
  var nextRecord = _this._recordSource.get(nextID);
383
550
 
384
551
  if (!nextRecord) {
385
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
386
- * suppresses an error found when Flow v0.98 was deployed. To see the
387
- * error delete this comment and run Flow. */
388
- var _typeName3 = field.concreteType || _this._getRecordType(item);
552
+ // $FlowFixMe[incompatible-variance]
553
+ var _typeName5 = field.concreteType || _this._getRecordType(item);
389
554
 
390
- nextRecord = RelayModernRecord.create(nextID, _typeName3);
555
+ nextRecord = RelayModernRecord.create(nextID, _typeName5);
391
556
 
392
557
  _this._recordSource.set(nextID, nextRecord);
393
558
  } else if (process.env.NODE_ENV !== "production") {
394
559
  _this._validateRecordType(nextRecord, field, item);
395
- }
396
- /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
397
- * suppresses an error found when Flow v0.98 was deployed. To see the
398
- * error delete this comment and run Flow. */
560
+ } // NOTE: the check to strip __DEV__ code only works for simple
561
+ // `if (__DEV__)`
562
+
563
+
564
+ if (process.env.NODE_ENV !== "production") {
565
+ if (prevIDs) {
566
+ _this._validateConflictingLinkedFieldsWithIdenticalId(record, prevIDs[nextIndex], nextID, storageKey);
567
+ }
568
+ } // $FlowFixMe[incompatible-variance]
399
569
 
400
570
 
401
571
  _this._traverseSelections(field, nextRecord, item);
@@ -413,7 +583,32 @@ function () {
413
583
  var _field$concreteType3;
414
584
 
415
585
  var typeName = (_field$concreteType3 = field.concreteType) !== null && _field$concreteType3 !== void 0 ? _field$concreteType3 : this._getRecordType(payload);
416
- process.env.NODE_ENV !== "production" ? warning(isClientID(RelayModernRecord.getDataID(record)) || RelayModernRecord.getType(record) === typeName, 'RelayResponseNormalizer: Invalid record `%s`. Expected %s to be ' + 'consistent, but the record was assigned conflicting types `%s` ' + 'and `%s`. The GraphQL server likely violated the globally unique ' + 'id requirement by returning the same id for different objects.', RelayModernRecord.getDataID(record), TYPENAME_KEY, RelayModernRecord.getType(record), typeName) : void 0;
586
+ var dataID = RelayModernRecord.getDataID(record);
587
+ process.env.NODE_ENV !== "production" ? warning(isClientID(dataID) && dataID !== ROOT_ID || RelayModernRecord.getType(record) === typeName, 'RelayResponseNormalizer: Invalid record `%s`. Expected %s to be ' + 'consistent, but the record was assigned conflicting types `%s` ' + 'and `%s`. The GraphQL server likely violated the globally unique ' + 'id requirement by returning the same id for different objects.', dataID, TYPENAME_KEY, RelayModernRecord.getType(record), typeName) : void 0;
588
+ }
589
+ /**
590
+ * Warns if a single response contains conflicting fields with the same id
591
+ */
592
+ ;
593
+
594
+ _proto._validateConflictingFieldsWithIdenticalId = function _validateConflictingFieldsWithIdenticalId(record, storageKey, fieldValue) {
595
+ // NOTE: Only call this function in DEV
596
+ if (process.env.NODE_ENV !== "production") {
597
+ var dataID = RelayModernRecord.getDataID(record);
598
+ var previousValue = RelayModernRecord.getValue(record, storageKey);
599
+ process.env.NODE_ENV !== "production" ? warning(storageKey === TYPENAME_KEY || previousValue === undefined || areEqual(previousValue, fieldValue), 'RelayResponseNormalizer: Invalid record. The record contains two ' + 'instances of the same id: `%s` with conflicting field, %s and its values: %s and %s. ' + 'If two fields are different but share ' + 'the same id, one field will overwrite the other.', dataID, storageKey, previousValue, fieldValue) : void 0;
600
+ }
601
+ }
602
+ /**
603
+ * Warns if a single response contains conflicting fields with the same id
604
+ */
605
+ ;
606
+
607
+ _proto._validateConflictingLinkedFieldsWithIdenticalId = function _validateConflictingLinkedFieldsWithIdenticalId(record, prevID, nextID, storageKey) {
608
+ // NOTE: Only call this function in DEV
609
+ if (process.env.NODE_ENV !== "production") {
610
+ process.env.NODE_ENV !== "production" ? warning(prevID === undefined || prevID === nextID, 'RelayResponseNormalizer: Invalid record. The record contains ' + 'references to the conflicting field, %s and its id values: %s and %s. ' + 'We need to make sure that the record the field points ' + 'to remains consistent or one field will overwrite the other.', storageKey, prevID, nextID) : void 0;
611
+ }
417
612
  };
418
613
 
419
614
  return RelayResponseNormalizer;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+ // flowlint ambiguous-object-type:error
11
+ 'use strict';
12
+
13
+ var invariant = require("fbjs/lib/invariant");
14
+
15
+ var _require = require('./RelayModernRecord'),
16
+ getType = _require.getType;
17
+
18
+ var REACT_FLIGHT_QUERIES_STORAGE_KEY = 'queries';
19
+ var REACT_FLIGHT_TREE_STORAGE_KEY = 'tree';
20
+ var REACT_FLIGHT_TYPE_NAME = 'ReactFlightComponent';
21
+
22
+ function refineToReactFlightPayloadData(payload) {
23
+ if (payload == null || typeof payload !== 'object' || !Array.isArray(payload.tree) || !Array.isArray(payload.queries)) {
24
+ return null;
25
+ }
26
+
27
+ return payload;
28
+ }
29
+
30
+ function getReactFlightClientResponse(record) {
31
+ !(getType(record) === REACT_FLIGHT_TYPE_NAME) ? process.env.NODE_ENV !== "production" ? invariant(false, 'getReactFlightClientResponse(): Expected a ReactFlightComponentRecord, ' + 'got %s.', record) : invariant(false) : void 0;
32
+ var response = record[REACT_FLIGHT_TREE_STORAGE_KEY];
33
+
34
+ if (response != null) {
35
+ return response;
36
+ }
37
+
38
+ return null;
39
+ }
40
+
41
+ module.exports = {
42
+ REACT_FLIGHT_QUERIES_STORAGE_KEY: REACT_FLIGHT_QUERIES_STORAGE_KEY,
43
+ REACT_FLIGHT_TREE_STORAGE_KEY: REACT_FLIGHT_TREE_STORAGE_KEY,
44
+ REACT_FLIGHT_TYPE_NAME: REACT_FLIGHT_TYPE_NAME,
45
+ getReactFlightClientResponse: getReactFlightClientResponse,
46
+ refineToReactFlightPayloadData: refineToReactFlightPayloadData
47
+ };
@@ -204,6 +204,7 @@ var RelayStoreUtils = {
204
204
  ROOT_TYPE: '__Root',
205
205
  TYPENAME_KEY: '__typename',
206
206
  INVALIDATED_AT_KEY: '__invalidated_at',
207
+ IS_WITHIN_UNMATCHED_TYPE_REFINEMENT: '__isWithinUnmatchedTypeRefinement',
207
208
  formatStorageKey: formatStorageKey,
208
209
  getArgumentValue: getArgumentValue,
209
210
  getArgumentValues: getArgumentValues,
@@ -13,10 +13,14 @@
13
13
 
14
14
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
15
15
 
16
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
17
 
18
18
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
19
19
 
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
21
+
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
+
20
24
  var inspect = function inspect() {};
21
25
 
22
26
  if (process.env.NODE_ENV !== "production") {
@@ -134,7 +138,7 @@ if (process.env.NODE_ENV !== "production") {
134
138
  return record;
135
139
  }
136
140
 
137
- return new Proxy((0, _objectSpread2["default"])({}, record), {
141
+ return new Proxy(_objectSpread({}, record), {
138
142
  get: function get(target, prop) {
139
143
  var value = target[prop];
140
144
 
@@ -148,9 +152,7 @@ if (process.env.NODE_ENV !== "production") {
148
152
  }
149
153
 
150
154
  if (Array.isArray(value.__refs)) {
151
- /* $FlowFixMe(>=0.111.0) This comment suppresses an error found
152
- * when Flow v0.111.0 was deployed. To see the error, delete this
153
- * comment and run Flow. */
155
+ // $FlowFixMe[incompatible-call]
154
156
  return value.__refs.map(function (ref) {
155
157
  return getWrappedRecord(source, ref);
156
158
  });
@@ -163,10 +165,8 @@ if (process.env.NODE_ENV !== "production") {
163
165
  };
164
166
 
165
167
  inspect = function inspect(environment, dataID) {
166
- var _dataID;
167
-
168
168
  installDevtoolFormatters();
169
- return getWrappedRecord(environment.getStore().getSource(), (_dataID = dataID) !== null && _dataID !== void 0 ? _dataID : 'client:root');
169
+ return getWrappedRecord(environment.getStore().getSource(), dataID !== null && dataID !== void 0 ? dataID : 'client:root');
170
170
  };
171
171
  }
172
172
 
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+ // flowlint ambiguous-object-type:error
11
+ 'use strict';
12
+
13
+ var PREFIX = 'client:__type:';
14
+ var TYPE_SCHEMA_TYPE = '__TypeSchema';
15
+
16
+ function generateTypeID(typeName) {
17
+ return PREFIX + typeName;
18
+ }
19
+
20
+ function isTypeID(id) {
21
+ return id.indexOf(PREFIX) === 0;
22
+ }
23
+
24
+ module.exports = {
25
+ generateTypeID: generateTypeID,
26
+ isTypeID: isTypeID,
27
+ TYPE_SCHEMA_TYPE: TYPE_SCHEMA_TYPE
28
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+ // flowlint ambiguous-object-type:error
11
+ 'use strict';
12
+
13
+ var areEqual = require("fbjs/lib/areEqual");
14
+
15
+ var invariant = require("fbjs/lib/invariant");
16
+
17
+ var _require = require('../util/RelayConcreteNode'),
18
+ SCALAR_FIELD = _require.SCALAR_FIELD;
19
+
20
+ var _require2 = require('./RelayStoreUtils'),
21
+ getHandleStorageKey = _require2.getHandleStorageKey;
22
+
23
+ /**
24
+ * @private
25
+ *
26
+ * Creates a clone of the supplied `handleField` by finding the original scalar
27
+ * field (on which the handle was declared) among the sibling `selections`.
28
+ */
29
+ function cloneRelayScalarHandleSourceField(handleField, selections, variables) {
30
+ var sourceField = selections.find(function (source) {
31
+ return source.kind === SCALAR_FIELD && source.name === handleField.name && source.alias === handleField.alias && areEqual(source.args, handleField.args);
32
+ });
33
+ !(sourceField && sourceField.kind === SCALAR_FIELD) ? process.env.NODE_ENV !== "production" ? invariant(false, 'cloneRelayScalarHandleSourceField: Expected a corresponding source field for ' + 'handle `%s`.', handleField.handle) : invariant(false) : void 0;
34
+ var handleKey = getHandleStorageKey(handleField, variables);
35
+ return {
36
+ kind: 'ScalarField',
37
+ alias: sourceField.alias,
38
+ name: handleKey,
39
+ storageKey: handleKey,
40
+ args: null
41
+ };
42
+ }
43
+
44
+ module.exports = cloneRelayScalarHandleSourceField;