relay-runtime 2.0.0-rc.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/index.js +1 -1
  2. package/lib/{generateRelayClientID.js → ClientID.js} +10 -3
  3. package/lib/ConvertToExecuteFunction.js +6 -4
  4. package/lib/DataChecker.js +88 -69
  5. package/lib/NormalizationNode.js +1 -1
  6. package/lib/ReaderNode.js +1 -1
  7. package/lib/RelayCombinedEnvironmentTypes.js +1 -1
  8. package/lib/RelayConcreteNode.js +5 -2
  9. package/lib/RelayConcreteVariables.js +15 -9
  10. package/lib/RelayConnectionHandler.js +27 -20
  11. package/lib/RelayConnectionInterface.js +4 -2
  12. package/lib/RelayCore.js +48 -15
  13. package/lib/RelayDeclarativeMutationConfig.js +16 -15
  14. package/lib/RelayDefaultHandleKey.js +1 -1
  15. package/lib/RelayDefaultHandlerProvider.js +7 -6
  16. package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
  17. package/lib/RelayError.js +7 -2
  18. package/lib/RelayFeatureFlags.js +16 -0
  19. package/lib/RelayInMemoryRecordSource.js +8 -2
  20. package/lib/RelayModernEnvironment.js +159 -237
  21. package/lib/RelayModernFragmentOwner.js +72 -0
  22. package/lib/RelayModernFragmentSpecResolver.js +66 -15
  23. package/lib/RelayModernGraphQLTag.js +9 -5
  24. package/lib/RelayModernOperationDescriptor.js +9 -6
  25. package/lib/RelayModernQueryExecutor.js +791 -0
  26. package/lib/RelayModernRecord.js +44 -24
  27. package/lib/RelayModernSelector.js +208 -82
  28. package/lib/RelayModernStore.js +66 -34
  29. package/lib/RelayNetwork.js +14 -7
  30. package/lib/RelayNetworkLogger.js +6 -2
  31. package/lib/RelayNetworkLoggerTransaction.js +8 -4
  32. package/lib/RelayNetworkTypes.js +1 -1
  33. package/lib/RelayObservable.js +72 -41
  34. package/lib/RelayOperationTracker.js +265 -0
  35. package/lib/RelayProfiler.js +10 -6
  36. package/lib/RelayPublishQueue.js +66 -47
  37. package/lib/RelayQueryResponseCache.js +11 -5
  38. package/lib/RelayReader.js +135 -126
  39. package/lib/RelayRecordProxy.js +24 -20
  40. package/lib/RelayRecordSourceMutator.js +88 -25
  41. package/lib/RelayRecordSourceProxy.js +38 -19
  42. package/lib/RelayRecordSourceSelectorProxy.js +10 -7
  43. package/lib/RelayRecordState.js +1 -1
  44. package/lib/RelayReferenceMarker.js +66 -55
  45. package/lib/RelayReplaySubject.js +134 -0
  46. package/lib/RelayResponseNormalizer.js +245 -134
  47. package/lib/RelayRuntimeTypes.js +1 -1
  48. package/lib/RelayStoreUtils.js +55 -16
  49. package/lib/RelayViewerHandler.js +8 -50
  50. package/lib/StoreInspector.js +171 -0
  51. package/lib/applyRelayModernOptimisticMutation.js +8 -2
  52. package/lib/cloneRelayHandleSourceField.js +17 -7
  53. package/lib/commitLocalUpdate.js +1 -1
  54. package/lib/commitRelayModernMutation.js +33 -13
  55. package/lib/createRelayContext.js +27 -0
  56. package/lib/createRelayNetworkLogger.js +8 -2
  57. package/lib/deepFreeze.js +1 -1
  58. package/lib/defaultGetDataID.js +24 -0
  59. package/lib/fetchQueryInternal.js +232 -0
  60. package/lib/fetchRelayModernQuery.js +5 -3
  61. package/lib/getFragmentIdentifier.js +52 -0
  62. package/lib/getFragmentSpecIdentifier.js +26 -0
  63. package/lib/getRelayHandleKey.js +8 -2
  64. package/lib/getRequestParametersIdentifier.js +26 -0
  65. package/lib/hasOverlappingIDs.js +1 -1
  66. package/lib/index.js +155 -53
  67. package/lib/isPromise.js +1 -1
  68. package/lib/isScalarAndEqual.js +1 -1
  69. package/lib/normalizeRelayPayload.js +19 -10
  70. package/lib/recycleNodesInto.js +23 -5
  71. package/lib/requestRelaySubscription.js +9 -3
  72. package/lib/validateMutation.js +13 -6
  73. package/package.json +2 -2
  74. package/relay-runtime.js +2 -2
  75. package/relay-runtime.min.js +2 -2
  76. package/lib/normalizePayload.js +0 -37
  77. package/lib/simpleClone.js +0 -27
@@ -9,6 +9,42 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
13
+
14
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
+
16
+ var RelayModernRecord = require("./RelayModernRecord");
17
+
18
+ var RelayProfiler = require("./RelayProfiler");
19
+
20
+ var invariant = require("fbjs/lib/invariant");
21
+
22
+ var warning = require("fbjs/lib/warning");
23
+
24
+ var _require = require("./RelayConcreteNode"),
25
+ CONDITION = _require.CONDITION,
26
+ CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
27
+ DEFER = _require.DEFER,
28
+ INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
29
+ LINKED_FIELD = _require.LINKED_FIELD,
30
+ LINKED_HANDLE = _require.LINKED_HANDLE,
31
+ MODULE_IMPORT = _require.MODULE_IMPORT,
32
+ SCALAR_FIELD = _require.SCALAR_FIELD,
33
+ SCALAR_HANDLE = _require.SCALAR_HANDLE,
34
+ STREAM = _require.STREAM;
35
+
36
+ var _require2 = require("./ClientID"),
37
+ generateClientID = _require2.generateClientID,
38
+ isClientID = _require2.isClientID;
39
+
40
+ var _require3 = require("./RelayStoreUtils"),
41
+ getArgumentValues = _require3.getArgumentValues,
42
+ getHandleStorageKey = _require3.getHandleStorageKey,
43
+ getModuleComponentKey = _require3.getModuleComponentKey,
44
+ getModuleOperationKey = _require3.getModuleOperationKey,
45
+ getStorageKey = _require3.getStorageKey,
46
+ TYPENAME_KEY = _require3.TYPENAME_KEY;
47
+
12
48
  /**
13
49
  * Normalizes the results of a query and standard GraphQL response, writing the
14
50
  * normalized records/fields into the given MutableRecordSource.
@@ -16,10 +52,7 @@
16
52
  * If handleStrippedNulls is true, will replace fields on the Selector that
17
53
  * are not present in the response with null. Otherwise will leave fields unset.
18
54
  */
19
- function normalize(recordSource, selector, response) {
20
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
21
- handleStrippedNulls: false
22
- };
55
+ function normalize(recordSource, selector, response, options) {
23
56
  var dataID = selector.dataID,
24
57
  node = selector.node,
25
58
  variables = selector.variables;
@@ -37,9 +70,12 @@ var RelayResponseNormalizer =
37
70
  /*#__PURE__*/
38
71
  function () {
39
72
  function RelayResponseNormalizer(recordSource, variables, options) {
73
+ this._getDataId = options.getDataID;
40
74
  this._handleFieldPayloads = [];
41
- this._handleStrippedNulls = options.handleStrippedNulls;
42
- this._matchFieldPayloads = [];
75
+ this._handleStrippedNulls = options.handleStrippedNulls === true;
76
+ this._incrementalPlaceholders = [];
77
+ this._moduleImportPayloads = [];
78
+ this._path = options.path ? (0, _toConsumableArray2["default"])(options.path) : [];
43
79
  this._recordSource = recordSource;
44
80
  this._variables = variables;
45
81
  }
@@ -49,130 +85,176 @@ function () {
49
85
  _proto.normalizeResponse = function normalizeResponse(node, dataID, data) {
50
86
  var record = this._recordSource.get(dataID);
51
87
 
52
- !record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Expected root record `%s` to exist.', dataID) : require("fbjs/lib/invariant")(false) : void 0;
88
+ !record ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Expected root record `%s` to exist.', dataID) : invariant(false) : void 0;
53
89
 
54
90
  this._traverseSelections(node, record, data);
55
91
 
56
92
  return {
93
+ incrementalPlaceholders: this._incrementalPlaceholders,
57
94
  fieldPayloads: this._handleFieldPayloads,
58
- matchPayloads: this._matchFieldPayloads
95
+ moduleImportPayloads: this._moduleImportPayloads
59
96
  };
60
97
  };
61
98
 
62
99
  _proto._getVariableValue = function _getVariableValue(name) {
63
- !this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Undefined variable `%s`.', name) : require("fbjs/lib/invariant")(false) : void 0;
100
+ !this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Undefined variable `%s`.', name) : invariant(false) : void 0;
64
101
  return this._variables[name];
65
102
  };
66
103
 
67
104
  _proto._getRecordType = function _getRecordType(data) {
68
- var typeName = data[require("./RelayStoreUtils").TYPENAME_KEY];
69
-
70
- !(typeName != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Expected a typename for record `%s`.', JSON.stringify(data, null, 2)) : require("fbjs/lib/invariant")(false) : void 0;
105
+ var typeName = data[TYPENAME_KEY];
106
+ !(typeName != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Expected a typename for record `%s`.', JSON.stringify(data, null, 2)) : invariant(false) : void 0;
71
107
  return typeName;
72
108
  };
73
109
 
74
110
  _proto._traverseSelections = function _traverseSelections(node, record, data) {
75
- var _this = this;
111
+ for (var i = 0; i < node.selections.length; i++) {
112
+ var selection = node.selections[i];
76
113
 
77
- node.selections.forEach(function (selection) {
78
- if (selection.kind === require("./RelayConcreteNode").SCALAR_FIELD || selection.kind === require("./RelayConcreteNode").LINKED_FIELD) {
79
- _this._normalizeField(node, selection, record, data);
80
- } else if (selection.kind === require("./RelayConcreteNode").CONDITION) {
81
- var conditionValue = _this._getVariableValue(selection.condition);
82
-
83
- if (conditionValue === selection.passingValue) {
84
- _this._traverseSelections(selection, record, data);
85
- }
86
- } else if (selection.kind === require("./RelayConcreteNode").INLINE_FRAGMENT) {
87
- var typeName = require("./RelayModernRecord").getType(record);
88
-
89
- if (typeName === selection.type) {
90
- _this._traverseSelections(selection, record, data);
91
- }
92
- } else if (selection.kind === require("./RelayConcreteNode").LINKED_HANDLE || selection.kind === require("./RelayConcreteNode").SCALAR_HANDLE) {
93
- var args = selection.args ? require("./RelayStoreUtils").getArgumentValues(selection.args, _this._variables) : {};
94
-
95
- var fieldKey = require("./RelayStoreUtils").getStorageKey(selection, _this._variables);
96
-
97
- var handleKey = require("./RelayStoreUtils").getHandleStorageKey(selection, _this._variables);
98
-
99
- _this._handleFieldPayloads.push({
100
- args: args,
101
- dataID: require("./RelayModernRecord").getDataID(record),
102
- fieldKey: fieldKey,
103
- handle: selection.handle,
104
- handleKey: handleKey
105
- });
106
- } else if (selection.kind === require("./RelayConcreteNode").MATCH_FIELD) {
107
- _this._normalizeMatchField(node, selection, record, data);
108
- } else if (selection.kind === require("./RelayConcreteNode").FRAGMENT || selection.kind === require("./RelayConcreteNode").FRAGMENT_SPREAD) {
109
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
110
- } else {
111
- selection;
112
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
113
- }
114
- });
115
- };
114
+ switch (selection.kind) {
115
+ case SCALAR_FIELD:
116
+ case LINKED_FIELD:
117
+ this._normalizeField(node, selection, record, data);
116
118
 
117
- _proto._normalizeMatchField = function _normalizeMatchField(parent, field, record, data) {
118
- !(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeField(): Expected data for field `%s` to be an object.', field.name) : require("fbjs/lib/invariant")(false) : void 0;
119
- var responseKey = field.alias || field.name;
119
+ break;
120
120
 
121
- var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
121
+ case CONDITION:
122
+ var conditionValue = this._getVariableValue(selection.condition);
122
123
 
123
- var fieldValue = data[responseKey];
124
+ if (conditionValue === selection.passingValue) {
125
+ this._traverseSelections(selection, record, data);
126
+ }
124
127
 
125
- if (fieldValue == null) {
126
- if (fieldValue === undefined && !this._handleStrippedNulls) {
127
- // If we're not stripping nulls, undefined fields are unset
128
- return;
129
- }
128
+ break;
130
129
 
131
- if (process.env.NODE_ENV !== "production") {
132
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(parent.kind === require("./RelayConcreteNode").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;
133
- }
130
+ case INLINE_FRAGMENT:
131
+ var _typeName = RelayModernRecord.getType(record);
134
132
 
135
- require("./RelayModernRecord").setValue(record, storageKey, null);
133
+ if (_typeName === selection.type) {
134
+ this._traverseSelections(selection, record, data);
135
+ }
136
136
 
137
- return;
138
- }
137
+ break;
139
138
 
140
- !(typeof fieldValue === 'object' && fieldValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an object.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
139
+ case LINKED_HANDLE:
140
+ case SCALAR_HANDLE:
141
+ var args = selection.args ? getArgumentValues(selection.args, this._variables) : {};
142
+ var fieldKey = getStorageKey(selection, this._variables);
143
+ var handleKey = getHandleStorageKey(selection, this._variables);
141
144
 
142
- var typeName = this._getRecordType(fieldValue);
145
+ this._handleFieldPayloads.push({
146
+ args: args,
147
+ dataID: RelayModernRecord.getDataID(record),
148
+ fieldKey: fieldKey,
149
+ handle: selection.handle,
150
+ handleKey: handleKey
151
+ });
143
152
 
144
- var match = field.matchesByType[typeName];
153
+ break;
145
154
 
146
- if (match == null) {
147
- require("./RelayModernRecord").setValue(record, storageKey, null);
155
+ case MODULE_IMPORT:
156
+ this._normalizeModuleImport(node, selection, record, data);
148
157
 
149
- return;
158
+ break;
159
+
160
+ case DEFER:
161
+ this._normalizeDefer(selection, record, data);
162
+
163
+ break;
164
+
165
+ case STREAM:
166
+ this._normalizeStream(selection, record, data);
167
+
168
+ break;
169
+
170
+ case CLIENT_EXTENSION:
171
+ var handleStrippedNulls = this._handleStrippedNulls;
172
+ this._handleStrippedNulls = false;
173
+
174
+ this._traverseSelections(selection, record, data);
175
+
176
+ this._handleStrippedNulls = handleStrippedNulls;
177
+ break;
178
+
179
+ default:
180
+ selection;
181
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
182
+ }
150
183
  }
184
+ };
151
185
 
152
- var nextID = fieldValue.id || // Reuse previously generated client IDs
153
- require("./RelayModernRecord").getLinkedRecordID(record, storageKey) || require("./generateRelayClientID")(require("./RelayModernRecord").getDataID(record), storageKey);
186
+ _proto._normalizeDefer = function _normalizeDefer(defer, record, data) {
187
+ var isDeferred = defer["if"] === null || this._getVariableValue(defer["if"]);
154
188
 
155
- !(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected id on field `%s` to be a string.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
189
+ if (process.env.NODE_ENV !== "production") {
190
+ process.env.NODE_ENV !== "production" ? warning(typeof isDeferred === 'boolean', 'RelayResponseNormalizer: Expected value for @defer `if` argument to ' + 'be a boolean, got `%s`.', isDeferred) : void 0;
191
+ }
156
192
 
157
- require("./RelayModernRecord").setLinkedRecordID(record, storageKey, nextID);
193
+ if (isDeferred === false) {
194
+ // If defer is disabled there will be no additional response chunk:
195
+ // normalize the data already present.
196
+ this._traverseSelections(defer, record, data);
197
+ } else {
198
+ // Otherwise data *for this selection* should not be present: enqueue
199
+ // metadata to process the subsequent response chunk.
200
+ this._incrementalPlaceholders.push({
201
+ kind: 'defer',
202
+ label: defer.label,
203
+ path: (0, _toConsumableArray2["default"])(this._path),
204
+ selector: {
205
+ dataID: RelayModernRecord.getDataID(record),
206
+ node: defer,
207
+ variables: this._variables
208
+ },
209
+ typeName: RelayModernRecord.getType(record)
210
+ });
211
+ }
212
+ };
158
213
 
159
- var nextRecord = this._recordSource.get(nextID);
214
+ _proto._normalizeStream = function _normalizeStream(stream, record, data) {
215
+ // Always normalize regardless of whether streaming is enabled or not,
216
+ // this populates the initial array value (including any items when
217
+ // initial_count > 0).
218
+ this._traverseSelections(stream, record, data);
160
219
 
161
- if (!nextRecord) {
162
- nextRecord = require("./RelayModernRecord").create(nextID, typeName);
220
+ var isStreamed = stream["if"] === null || this._getVariableValue(stream["if"]);
163
221
 
164
- this._recordSource.set(nextID, nextRecord);
165
- } else if (process.env.NODE_ENV !== "production") {
166
- this._validateRecordType(nextRecord, field, fieldValue);
222
+ if (process.env.NODE_ENV !== "production") {
223
+ process.env.NODE_ENV !== "production" ? warning(typeof isStreamed === 'boolean', 'RelayResponseNormalizer: Expected value for @stream `if` argument ' + 'to be a boolean, got `%s`.', isStreamed) : void 0;
167
224
  }
168
225
 
169
- var operationReference = fieldValue[require("./RelayStoreUtils").MATCH_FRAGMENT_KEY];
226
+ if (isStreamed === true) {
227
+ // If streaming is enabled, *also* emit metadata to process any
228
+ // response chunks that may be delivered.
229
+ this._incrementalPlaceholders.push({
230
+ kind: 'stream',
231
+ label: stream.label,
232
+ path: (0, _toConsumableArray2["default"])(this._path),
233
+ parentID: RelayModernRecord.getDataID(record),
234
+ node: stream,
235
+ variables: this._variables
236
+ });
237
+ }
238
+ };
239
+
240
+ _proto._normalizeModuleImport = function _normalizeModuleImport(parent, moduleImport, record, data) {
241
+ var _componentReference, _operationReference;
242
+
243
+ !(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected data for @module to be an object.') : invariant(false) : void 0;
244
+ var typeName = RelayModernRecord.getType(record);
245
+ var componentKey = getModuleComponentKey(moduleImport.documentName);
246
+ var componentReference = data[componentKey];
247
+ RelayModernRecord.setValue(record, componentKey, (_componentReference = componentReference) !== null && _componentReference !== void 0 ? _componentReference : null);
248
+ var operationKey = getModuleOperationKey(moduleImport.documentName);
249
+ var operationReference = data[operationKey];
250
+ RelayModernRecord.setValue(record, operationKey, (_operationReference = operationReference) !== null && _operationReference !== void 0 ? _operationReference : null);
170
251
 
171
252
  if (operationReference != null) {
172
- this._matchFieldPayloads.push({
253
+ this._moduleImportPayloads.push({
254
+ data: data,
255
+ dataID: RelayModernRecord.getDataID(record),
173
256
  operationReference: operationReference,
174
- dataID: nextID,
175
- data: fieldValue,
257
+ path: (0, _toConsumableArray2["default"])(this._path),
176
258
  typeName: typeName,
177
259
  variables: this._variables
178
260
  });
@@ -180,11 +262,9 @@ function () {
180
262
  };
181
263
 
182
264
  _proto._normalizeField = function _normalizeField(parent, selection, record, data) {
183
- !(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeField(): Expected data for field `%s` to be an object.', selection.name) : require("fbjs/lib/invariant")(false) : void 0;
265
+ !(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? invariant(false, 'writeField(): Expected data for field `%s` to be an object.', selection.name) : invariant(false) : void 0;
184
266
  var responseKey = selection.alias || selection.name;
185
-
186
- var storageKey = require("./RelayStoreUtils").getStorageKey(selection, this._variables);
187
-
267
+ var storageKey = getStorageKey(selection, this._variables);
188
268
  var fieldValue = data[responseKey];
189
269
 
190
270
  if (fieldValue == null) {
@@ -194,110 +274,141 @@ function () {
194
274
  }
195
275
 
196
276
  if (process.env.NODE_ENV !== "production") {
197
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(parent.kind === require("./RelayConcreteNode").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;
277
+ process.env.NODE_ENV !== "production" ? warning(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;
198
278
  }
199
279
 
200
- require("./RelayModernRecord").setValue(record, storageKey, null);
201
-
280
+ RelayModernRecord.setValue(record, storageKey, null);
202
281
  return;
203
282
  }
204
283
 
205
- if (selection.kind === require("./RelayConcreteNode").SCALAR_FIELD) {
206
- require("./RelayModernRecord").setValue(record, storageKey, fieldValue);
207
- } else if (selection.kind === require("./RelayConcreteNode").LINKED_FIELD) {
284
+ if (selection.kind === SCALAR_FIELD) {
285
+ RelayModernRecord.setValue(record, storageKey, fieldValue);
286
+ } else if (selection.kind === LINKED_FIELD) {
287
+ this._path.push(responseKey);
288
+
208
289
  if (selection.plural) {
209
290
  this._normalizePluralLink(selection, record, storageKey, fieldValue);
210
291
  } else {
211
292
  this._normalizeLink(selection, record, storageKey, fieldValue);
212
293
  }
213
- } else if (selection.kind === require("./RelayConcreteNode").MATCH_FIELD) {
214
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s` during normalization.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
294
+
295
+ this._path.pop();
215
296
  } else {
216
297
  selection;
217
- !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s` during normalization.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
298
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s` during normalization.', selection.kind) : invariant(false) : void 0;
218
299
  }
219
300
  };
220
301
 
221
302
  _proto._normalizeLink = function _normalizeLink(field, record, storageKey, fieldValue) {
222
- !(typeof fieldValue === 'object' && fieldValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an object.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
223
-
224
- var nextID = fieldValue.id || // Reuse previously generated client IDs
225
- require("./RelayModernRecord").getLinkedRecordID(record, storageKey) || require("./generateRelayClientID")(require("./RelayModernRecord").getDataID(record), storageKey);
226
-
227
- !(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected id on field `%s` to be a string.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
228
-
229
- require("./RelayModernRecord").setLinkedRecordID(record, storageKey, nextID);
303
+ var _field$concreteType;
304
+
305
+ !(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;
306
+ var nextID = this._getDataId(
307
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
308
+ * suppresses an error found when Flow v0.98 was deployed. To see the
309
+ * error delete this comment and run Flow. */
310
+ fieldValue,
311
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
312
+ * suppresses an error found when Flow v0.98 was deployed. To see the
313
+ * error delete this comment and run Flow. */
314
+ (_field$concreteType = field.concreteType) !== null && _field$concreteType !== void 0 ? _field$concreteType : this._getRecordType(fieldValue)) || // Reuse previously generated client IDs
315
+ RelayModernRecord.getLinkedRecordID(record, storageKey) || generateClientID(RelayModernRecord.getDataID(record), storageKey);
316
+ !(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;
317
+ RelayModernRecord.setLinkedRecordID(record, storageKey, nextID);
230
318
 
231
319
  var nextRecord = this._recordSource.get(nextID);
232
320
 
233
321
  if (!nextRecord) {
234
- var typeName = field.concreteType || this._getRecordType(fieldValue);
322
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
323
+ * suppresses an error found when Flow v0.98 was deployed. To see the
324
+ * error delete this comment and run Flow. */
325
+ var _typeName2 = field.concreteType || this._getRecordType(fieldValue);
235
326
 
236
- nextRecord = require("./RelayModernRecord").create(nextID, typeName);
327
+ nextRecord = RelayModernRecord.create(nextID, _typeName2);
237
328
 
238
329
  this._recordSource.set(nextID, nextRecord);
239
330
  } else if (process.env.NODE_ENV !== "production") {
240
331
  this._validateRecordType(nextRecord, field, fieldValue);
241
332
  }
333
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
334
+ * suppresses an error found when Flow v0.98 was deployed. To see the error
335
+ * delete this comment and run Flow. */
336
+
242
337
 
243
338
  this._traverseSelections(field, nextRecord, fieldValue);
244
339
  };
245
340
 
246
341
  _proto._normalizePluralLink = function _normalizePluralLink(field, record, storageKey, fieldValue) {
247
- var _this2 = this;
248
-
249
- !Array.isArray(fieldValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an array ' + 'of objects.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
250
-
251
- var prevIDs = require("./RelayModernRecord").getLinkedRecordIDs(record, storageKey);
342
+ var _this = this;
252
343
 
344
+ !Array.isArray(fieldValue) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an array ' + 'of objects.', storageKey) : invariant(false) : void 0;
345
+ var prevIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
253
346
  var nextIDs = [];
254
347
  fieldValue.forEach(function (item, nextIndex) {
348
+ var _field$concreteType2;
349
+
255
350
  // validate response data
256
351
  if (item == null) {
257
352
  nextIDs.push(item);
258
353
  return;
259
354
  }
260
355
 
261
- !(typeof item === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected elements for field `%s` to be ' + 'objects.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
262
-
263
- var nextID = item.id || prevIDs && prevIDs[nextIndex] || // Reuse previously generated client IDs
264
- require("./generateRelayClientID")(require("./RelayModernRecord").getDataID(record), storageKey, nextIndex);
265
-
266
- !(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected id of elements of field `%s` to ' + 'be strings.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
356
+ _this._path.push(String(nextIndex));
357
+
358
+ !(typeof item === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected elements for field `%s` to be ' + 'objects.', storageKey) : invariant(false) : void 0;
359
+ var nextID = _this._getDataId(
360
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
361
+ * suppresses an error found when Flow v0.98 was deployed. To see the
362
+ * error delete this comment and run Flow. */
363
+ item,
364
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
365
+ * suppresses an error found when Flow v0.98 was deployed. To see the
366
+ * error delete this comment and run Flow. */
367
+ (_field$concreteType2 = field.concreteType) !== null && _field$concreteType2 !== void 0 ? _field$concreteType2 : _this._getRecordType(item)) || prevIDs && prevIDs[nextIndex] || // Reuse previously generated client IDs:
368
+ generateClientID(RelayModernRecord.getDataID(record), storageKey, nextIndex);
369
+ !(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;
267
370
  nextIDs.push(nextID);
268
371
 
269
- var nextRecord = _this2._recordSource.get(nextID);
372
+ var nextRecord = _this._recordSource.get(nextID);
270
373
 
271
374
  if (!nextRecord) {
272
- var typeName = field.concreteType || _this2._getRecordType(item);
375
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
376
+ * suppresses an error found when Flow v0.98 was deployed. To see the
377
+ * error delete this comment and run Flow. */
378
+ var _typeName3 = field.concreteType || _this._getRecordType(item);
273
379
 
274
- nextRecord = require("./RelayModernRecord").create(nextID, typeName);
380
+ nextRecord = RelayModernRecord.create(nextID, _typeName3);
275
381
 
276
- _this2._recordSource.set(nextID, nextRecord);
382
+ _this._recordSource.set(nextID, nextRecord);
277
383
  } else if (process.env.NODE_ENV !== "production") {
278
- _this2._validateRecordType(nextRecord, field, item);
384
+ _this._validateRecordType(nextRecord, field, item);
279
385
  }
386
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
387
+ * suppresses an error found when Flow v0.98 was deployed. To see the
388
+ * error delete this comment and run Flow. */
280
389
 
281
- _this2._traverseSelections(field, nextRecord, item);
282
- });
283
390
 
284
- require("./RelayModernRecord").setLinkedRecordIDs(record, storageKey, nextIDs);
285
- };
391
+ _this._traverseSelections(field, nextRecord, item);
392
+
393
+ _this._path.pop();
394
+ });
395
+ RelayModernRecord.setLinkedRecordIDs(record, storageKey, nextIDs);
396
+ }
286
397
  /**
287
398
  * Warns if the type of the record does not match the type of the field/payload.
288
399
  */
289
-
400
+ ;
290
401
 
291
402
  _proto._validateRecordType = function _validateRecordType(record, field, payload) {
292
403
  var typeName = field.kind === 'LinkedField' ? field.concreteType || this._getRecordType(payload) : this._getRecordType(payload);
293
- process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(require("./RelayModernRecord").getType(record) === typeName, 'RelayResponseNormalizer: Invalid record `%s`. Expected %s to be ' + '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.', require("./RelayModernRecord").getDataID(record), require("./RelayStoreUtils").TYPENAME_KEY, require("./RelayModernRecord").getType(record), typeName) : void 0;
404
+ process.env.NODE_ENV !== "production" ? warning(isClientID(RelayModernRecord.getDataID(record)) || RelayModernRecord.getType(record) === typeName, 'RelayResponseNormalizer: Invalid record `%s`. Expected %s to be ' + '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;
294
405
  };
295
406
 
296
407
  return RelayResponseNormalizer;
297
408
  }(); // eslint-disable-next-line no-func-assign
298
409
 
299
410
 
300
- normalize = require("./RelayProfiler").instrument('RelayResponseNormalizer.normalize', normalize);
411
+ normalize = RelayProfiler.instrument('RelayResponseNormalizer.normalize', normalize);
301
412
  module.exports = {
302
413
  normalize: normalize
303
414
  };
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * strict
7
+ *
8
8
  * @format
9
9
  */
10
10
  'use strict';