relay-runtime 4.0.0 → 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.
- package/index.js +1 -1
- package/lib/ClientID.js +1 -1
- package/lib/ConvertToExecuteFunction.js +1 -1
- package/lib/DataChecker.js +10 -9
- package/lib/NormalizationNode.js +1 -1
- package/lib/ReaderNode.js +1 -1
- package/lib/RelayCombinedEnvironmentTypes.js +1 -1
- package/lib/RelayConcreteNode.js +1 -1
- package/lib/RelayConnectionHandler.js +1 -1
- package/lib/RelayConnectionInterface.js +1 -1
- package/lib/RelayDefaultHandleKey.js +1 -1
- package/lib/RelayDefaultHandlerProvider.js +1 -6
- package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
- package/lib/RelayFeatureFlags.js +3 -5
- package/lib/RelayModernEnvironment.js +30 -20
- package/lib/RelayModernFragmentOwner.js +1 -1
- package/lib/RelayModernFragmentSpecResolver.js +36 -49
- package/lib/RelayModernOperationDescriptor.js +1 -1
- package/lib/RelayModernQueryExecutor.js +200 -92
- package/lib/RelayModernSelector.js +36 -16
- package/lib/RelayModernStore.js +14 -8
- package/lib/RelayNetwork.js +1 -1
- package/lib/RelayNetworkLogger.js +1 -1
- package/lib/RelayNetworkTypes.js +1 -1
- package/lib/RelayObservable.js +69 -40
- package/lib/RelayOperationTracker.js +26 -39
- package/lib/RelayPublishQueue.js +24 -19
- package/lib/RelayQueryResponseCache.js +1 -1
- package/lib/RelayReader.js +23 -5
- package/lib/RelayRecordProxy.js +7 -3
- package/lib/RelayRecordSourceMutator.js +1 -1
- package/lib/RelayRecordSourceProxy.js +5 -2
- package/lib/RelayRecordSourceSelectorProxy.js +1 -1
- package/lib/RelayRecordState.js +1 -1
- package/lib/RelayReferenceMarker.js +4 -3
- package/lib/RelayReplaySubject.js +1 -1
- package/lib/RelayResponseNormalizer.js +57 -19
- package/lib/RelayRuntimeTypes.js +1 -1
- package/lib/RelayStoreUtils.js +39 -9
- package/lib/RelayViewerHandler.js +2 -49
- package/lib/StoreInspector.js +1 -1
- package/lib/cloneRelayHandleSourceField.js +1 -1
- package/lib/commitLocalUpdate.js +1 -1
- package/lib/createRelayContext.js +1 -1
- package/lib/deepFreeze.js +1 -1
- package/lib/defaultGetDataID.js +24 -0
- package/lib/fetchQueryInternal.js +1 -1
- package/lib/fetchRelayModernQuery.js +1 -1
- package/lib/getFragmentIdentifier.js +1 -1
- package/lib/getFragmentSpecIdentifier.js +1 -1
- package/lib/getRequestParametersIdentifier.js +1 -1
- package/lib/hasOverlappingIDs.js +1 -1
- package/lib/index.js +5 -0
- package/lib/isPromise.js +1 -1
- package/lib/isScalarAndEqual.js +1 -1
- package/lib/normalizeRelayPayload.js +2 -5
- package/lib/recycleNodesInto.js +7 -1
- package/package.json +2 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
package/lib/RelayReader.js
CHANGED
|
@@ -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
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -29,7 +29,8 @@ var _require2 = require("./RelayStoreUtils"),
|
|
|
29
29
|
ID_KEY = _require2.ID_KEY,
|
|
30
30
|
MODULE_COMPONENT_KEY = _require2.MODULE_COMPONENT_KEY,
|
|
31
31
|
getArgumentValues = _require2.getArgumentValues,
|
|
32
|
-
getStorageKey = _require2.getStorageKey
|
|
32
|
+
getStorageKey = _require2.getStorageKey,
|
|
33
|
+
getModuleComponentKey = _require2.getModuleComponentKey;
|
|
33
34
|
|
|
34
35
|
function read(recordSource, selector, owner) {
|
|
35
36
|
var _owner;
|
|
@@ -192,6 +193,10 @@ function () {
|
|
|
192
193
|
|
|
193
194
|
var prevData = data[applicationName];
|
|
194
195
|
!(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;
|
|
196
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
197
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the error
|
|
198
|
+
* delete this comment and run Flow. */
|
|
199
|
+
|
|
195
200
|
data[applicationName] = this._traverse(field, linkedID, prevData);
|
|
196
201
|
};
|
|
197
202
|
|
|
@@ -222,6 +227,10 @@ function () {
|
|
|
222
227
|
if (linkedID === undefined) {
|
|
223
228
|
_this._isMissingData = true;
|
|
224
229
|
}
|
|
230
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
231
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
232
|
+
* error delete this comment and run Flow. */
|
|
233
|
+
|
|
225
234
|
|
|
226
235
|
linkedArray[nextIndex] = linkedID;
|
|
227
236
|
return;
|
|
@@ -229,20 +238,25 @@ function () {
|
|
|
229
238
|
|
|
230
239
|
var prevItem = linkedArray[nextIndex];
|
|
231
240
|
!(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;
|
|
241
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
242
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
243
|
+
* error delete this comment and run Flow. */
|
|
244
|
+
|
|
232
245
|
linkedArray[nextIndex] = _this._traverse(field, linkedID, prevItem);
|
|
233
246
|
});
|
|
234
247
|
data[applicationName] = linkedArray;
|
|
235
|
-
}
|
|
248
|
+
}
|
|
236
249
|
/**
|
|
237
250
|
* Reads a ReaderModuleImport, which was generated from using the @module
|
|
238
251
|
* directive.
|
|
239
252
|
*/
|
|
240
|
-
|
|
253
|
+
;
|
|
241
254
|
|
|
242
255
|
_proto._readModuleImport = function _readModuleImport(moduleImport, record, data) {
|
|
243
256
|
// Determine the component module from the store: if the field is missing
|
|
244
257
|
// it means we don't know what component to render the match with.
|
|
245
|
-
var
|
|
258
|
+
var componentKey = getModuleComponentKey(moduleImport.documentName);
|
|
259
|
+
var component = RelayModernRecord.getValue(record, componentKey);
|
|
246
260
|
|
|
247
261
|
if (component == null) {
|
|
248
262
|
if (component === undefined) {
|
|
@@ -279,6 +293,10 @@ function () {
|
|
|
279
293
|
if (data[ID_KEY] == null) {
|
|
280
294
|
data[ID_KEY] = RelayModernRecord.getDataID(record);
|
|
281
295
|
}
|
|
296
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
297
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the error
|
|
298
|
+
* delete this comment and run Flow. */
|
|
299
|
+
|
|
282
300
|
|
|
283
301
|
fragmentPointers[fragmentSpread.name] = fragmentSpread.args ? getArgumentValues(fragmentSpread.args, this._variables) : {};
|
|
284
302
|
data[FRAGMENT_OWNER_KEY] = this._owner;
|
package/lib/RelayRecordProxy.js
CHANGED
|
@@ -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
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -85,9 +85,13 @@ function () {
|
|
|
85
85
|
var linkedRecord = this.getLinkedRecord(name, args);
|
|
86
86
|
|
|
87
87
|
if (!linkedRecord) {
|
|
88
|
+
var _this$_source$get;
|
|
89
|
+
|
|
88
90
|
var storageKey = getStableStorageKey(name, args);
|
|
89
|
-
var clientID = generateClientID(this.getDataID(), storageKey);
|
|
90
|
-
|
|
91
|
+
var clientID = generateClientID(this.getDataID(), storageKey); // NOTE: it's possible that a client record for this field exists
|
|
92
|
+
// but the field itself was unset.
|
|
93
|
+
|
|
94
|
+
linkedRecord = (_this$_source$get = this._source.get(clientID)) !== null && _this$_source$get !== void 0 ? _this$_source$get : this._source.create(clientID, typeName);
|
|
91
95
|
this.setLinkedRecord(linkedRecord, name, args);
|
|
92
96
|
}
|
|
93
97
|
|
|
@@ -35,10 +35,11 @@ var _require2 = require("./RelayStoreUtils"),
|
|
|
35
35
|
var RelayRecordSourceProxy =
|
|
36
36
|
/*#__PURE__*/
|
|
37
37
|
function () {
|
|
38
|
-
function RelayRecordSourceProxy(mutator, handlerProvider) {
|
|
38
|
+
function RelayRecordSourceProxy(mutator, getDataID, handlerProvider) {
|
|
39
39
|
this.__mutator = mutator;
|
|
40
40
|
this._handlerProvider = handlerProvider || null;
|
|
41
41
|
this._proxies = {};
|
|
42
|
+
this._getDataID = getDataID;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
var _proto = RelayRecordSourceProxy.prototype;
|
|
@@ -80,7 +81,9 @@ function () {
|
|
|
80
81
|
return new RelayRecordSourceSelectorProxy(this, operation.fragment);
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
var _normalizeRelayPayloa = normalizeRelayPayload(operation.root, response
|
|
84
|
+
var _normalizeRelayPayloa = normalizeRelayPayload(operation.root, response, null, {
|
|
85
|
+
getDataID: this._getDataID
|
|
86
|
+
}),
|
|
84
87
|
source = _normalizeRelayPayloa.source,
|
|
85
88
|
fieldPayloads = _normalizeRelayPayloa.fieldPayloads;
|
|
86
89
|
|
package/lib/RelayRecordState.js
CHANGED
|
@@ -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
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -31,7 +31,7 @@ var CONDITION = RelayConcreteNode.CONDITION,
|
|
|
31
31
|
SCALAR_HANDLE = RelayConcreteNode.SCALAR_HANDLE,
|
|
32
32
|
STREAM = RelayConcreteNode.STREAM;
|
|
33
33
|
var getStorageKey = RelayStoreUtils.getStorageKey,
|
|
34
|
-
|
|
34
|
+
getModuleOperationKey = RelayStoreUtils.getModuleOperationKey;
|
|
35
35
|
|
|
36
36
|
function mark(recordSource, selector, references, operationLoader) {
|
|
37
37
|
var dataID = selector.dataID,
|
|
@@ -166,7 +166,8 @@ function () {
|
|
|
166
166
|
_proto._traverseModuleImport = function _traverseModuleImport(moduleImport, record) {
|
|
167
167
|
var operationLoader = this._operationLoader;
|
|
168
168
|
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker: Expected an operationLoader to be configured when using `@module`.') : invariant(false) : void 0;
|
|
169
|
-
var
|
|
169
|
+
var operationKey = getModuleOperationKey(moduleImport.documentName);
|
|
170
|
+
var operationReference = RelayModernRecord.getValue(record, operationKey);
|
|
170
171
|
|
|
171
172
|
if (operationReference == null) {
|
|
172
173
|
return;
|
|
@@ -40,8 +40,9 @@ var _require2 = require("./ClientID"),
|
|
|
40
40
|
var _require3 = require("./RelayStoreUtils"),
|
|
41
41
|
getArgumentValues = _require3.getArgumentValues,
|
|
42
42
|
getHandleStorageKey = _require3.getHandleStorageKey,
|
|
43
|
+
getModuleComponentKey = _require3.getModuleComponentKey,
|
|
44
|
+
getModuleOperationKey = _require3.getModuleOperationKey,
|
|
43
45
|
getStorageKey = _require3.getStorageKey,
|
|
44
|
-
MODULE_OPERATION_KEY = _require3.MODULE_OPERATION_KEY,
|
|
45
46
|
TYPENAME_KEY = _require3.TYPENAME_KEY;
|
|
46
47
|
|
|
47
48
|
/**
|
|
@@ -51,10 +52,7 @@ var _require3 = require("./RelayStoreUtils"),
|
|
|
51
52
|
* If handleStrippedNulls is true, will replace fields on the Selector that
|
|
52
53
|
* are not present in the response with null. Otherwise will leave fields unset.
|
|
53
54
|
*/
|
|
54
|
-
function normalize(recordSource, selector, response) {
|
|
55
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
56
|
-
handleStrippedNulls: false
|
|
57
|
-
};
|
|
55
|
+
function normalize(recordSource, selector, response, options) {
|
|
58
56
|
var dataID = selector.dataID,
|
|
59
57
|
node = selector.node,
|
|
60
58
|
variables = selector.variables;
|
|
@@ -72,6 +70,7 @@ var RelayResponseNormalizer =
|
|
|
72
70
|
/*#__PURE__*/
|
|
73
71
|
function () {
|
|
74
72
|
function RelayResponseNormalizer(recordSource, variables, options) {
|
|
73
|
+
this._getDataId = options.getDataID;
|
|
75
74
|
this._handleFieldPayloads = [];
|
|
76
75
|
this._handleStrippedNulls = options.handleStrippedNulls === true;
|
|
77
76
|
this._incrementalPlaceholders = [];
|
|
@@ -129,9 +128,9 @@ function () {
|
|
|
129
128
|
break;
|
|
130
129
|
|
|
131
130
|
case INLINE_FRAGMENT:
|
|
132
|
-
var
|
|
131
|
+
var _typeName = RelayModernRecord.getType(record);
|
|
133
132
|
|
|
134
|
-
if (
|
|
133
|
+
if (_typeName === selection.type) {
|
|
135
134
|
this._traverseSelections(selection, record, data);
|
|
136
135
|
}
|
|
137
136
|
|
|
@@ -239,11 +238,16 @@ function () {
|
|
|
239
238
|
};
|
|
240
239
|
|
|
241
240
|
_proto._normalizeModuleImport = function _normalizeModuleImport(parent, moduleImport, record, data) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var typeName = this._getRecordType(data);
|
|
241
|
+
var _componentReference, _operationReference;
|
|
245
242
|
|
|
246
|
-
|
|
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);
|
|
247
251
|
|
|
248
252
|
if (operationReference != null) {
|
|
249
253
|
this._moduleImportPayloads.push({
|
|
@@ -296,8 +300,18 @@ function () {
|
|
|
296
300
|
};
|
|
297
301
|
|
|
298
302
|
_proto._normalizeLink = function _normalizeLink(field, record, storageKey, fieldValue) {
|
|
303
|
+
var _field$concreteType;
|
|
304
|
+
|
|
299
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;
|
|
300
|
-
var nextID =
|
|
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
|
|
301
315
|
RelayModernRecord.getLinkedRecordID(record, storageKey) || generateClientID(RelayModernRecord.getDataID(record), storageKey);
|
|
302
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;
|
|
303
317
|
RelayModernRecord.setLinkedRecordID(record, storageKey, nextID);
|
|
@@ -305,14 +319,21 @@ function () {
|
|
|
305
319
|
var nextRecord = this._recordSource.get(nextID);
|
|
306
320
|
|
|
307
321
|
if (!nextRecord) {
|
|
308
|
-
|
|
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);
|
|
309
326
|
|
|
310
|
-
nextRecord = RelayModernRecord.create(nextID,
|
|
327
|
+
nextRecord = RelayModernRecord.create(nextID, _typeName2);
|
|
311
328
|
|
|
312
329
|
this._recordSource.set(nextID, nextRecord);
|
|
313
330
|
} else if (process.env.NODE_ENV !== "production") {
|
|
314
331
|
this._validateRecordType(nextRecord, field, fieldValue);
|
|
315
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
|
+
|
|
316
337
|
|
|
317
338
|
this._traverseSelections(field, nextRecord, fieldValue);
|
|
318
339
|
};
|
|
@@ -324,6 +345,8 @@ function () {
|
|
|
324
345
|
var prevIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
|
|
325
346
|
var nextIDs = [];
|
|
326
347
|
fieldValue.forEach(function (item, nextIndex) {
|
|
348
|
+
var _field$concreteType2;
|
|
349
|
+
|
|
327
350
|
// validate response data
|
|
328
351
|
if (item == null) {
|
|
329
352
|
nextIDs.push(item);
|
|
@@ -333,7 +356,15 @@ function () {
|
|
|
333
356
|
_this._path.push(String(nextIndex));
|
|
334
357
|
|
|
335
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;
|
|
336
|
-
var nextID =
|
|
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:
|
|
337
368
|
generateClientID(RelayModernRecord.getDataID(record), storageKey, nextIndex);
|
|
338
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;
|
|
339
370
|
nextIDs.push(nextID);
|
|
@@ -341,25 +372,32 @@ function () {
|
|
|
341
372
|
var nextRecord = _this._recordSource.get(nextID);
|
|
342
373
|
|
|
343
374
|
if (!nextRecord) {
|
|
344
|
-
|
|
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);
|
|
345
379
|
|
|
346
|
-
nextRecord = RelayModernRecord.create(nextID,
|
|
380
|
+
nextRecord = RelayModernRecord.create(nextID, _typeName3);
|
|
347
381
|
|
|
348
382
|
_this._recordSource.set(nextID, nextRecord);
|
|
349
383
|
} else if (process.env.NODE_ENV !== "production") {
|
|
350
384
|
_this._validateRecordType(nextRecord, field, item);
|
|
351
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. */
|
|
389
|
+
|
|
352
390
|
|
|
353
391
|
_this._traverseSelections(field, nextRecord, item);
|
|
354
392
|
|
|
355
393
|
_this._path.pop();
|
|
356
394
|
});
|
|
357
395
|
RelayModernRecord.setLinkedRecordIDs(record, storageKey, nextIDs);
|
|
358
|
-
}
|
|
396
|
+
}
|
|
359
397
|
/**
|
|
360
398
|
* Warns if the type of the record does not match the type of the field/payload.
|
|
361
399
|
*/
|
|
362
|
-
|
|
400
|
+
;
|
|
363
401
|
|
|
364
402
|
_proto._validateRecordType = function _validateRecordType(record, field, payload) {
|
|
365
403
|
var typeName = field.kind === 'LinkedField' ? field.concreteType || this._getRecordType(payload) : this._getRecordType(payload);
|
package/lib/RelayRuntimeTypes.js
CHANGED
package/lib/RelayStoreUtils.js
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
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
|
+
|
|
12
16
|
var RelayConcreteNode = require("./RelayConcreteNode");
|
|
13
17
|
|
|
14
18
|
var getRelayHandleKey = require("./getRelayHandleKey");
|
|
@@ -18,6 +22,8 @@ var invariant = require("fbjs/lib/invariant");
|
|
|
18
22
|
var stableCopy = require("./stableCopy");
|
|
19
23
|
|
|
20
24
|
var VARIABLE = RelayConcreteNode.VARIABLE;
|
|
25
|
+
var MODULE_COMPONENT_KEY_PREFIX = '__module_component_';
|
|
26
|
+
var MODULE_OPERATION_KEY_PREFIX = '__module_operation_';
|
|
21
27
|
/**
|
|
22
28
|
* Returns the values of field/fragment arguments as an object keyed by argument
|
|
23
29
|
* names. Guaranteed to return a result with stable ordered nested values.
|
|
@@ -48,21 +54,35 @@ function getArgumentValues(args, variables) {
|
|
|
48
54
|
|
|
49
55
|
|
|
50
56
|
function getHandleStorageKey(handleField, variables) {
|
|
51
|
-
var
|
|
57
|
+
var dynamicKey = handleField.dynamicKey,
|
|
58
|
+
handle = handleField.handle,
|
|
52
59
|
key = handleField.key,
|
|
53
60
|
name = handleField.name,
|
|
54
61
|
args = handleField.args,
|
|
55
62
|
filters = handleField.filters;
|
|
56
63
|
var handleName = getRelayHandleKey(handle, key, name);
|
|
64
|
+
var filterArgs = null;
|
|
57
65
|
|
|
58
|
-
if (
|
|
59
|
-
|
|
66
|
+
if (args && filters && args.length !== 0 && filters.length !== 0) {
|
|
67
|
+
filterArgs = args.filter(function (arg) {
|
|
68
|
+
return filters.indexOf(arg.name) > -1;
|
|
69
|
+
});
|
|
60
70
|
}
|
|
61
71
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
if (dynamicKey) {
|
|
73
|
+
// "Sort" the arguments by argument name: this is done by the compiler for
|
|
74
|
+
// user-supplied arguments but the dynamic argument must also be in sorted
|
|
75
|
+
// order. Note that dynamic key argument name is double-underscore-
|
|
76
|
+
// -prefixed, and a double-underscore prefix is disallowed for user-supplied
|
|
77
|
+
// argument names, so there's no need to actually sort.
|
|
78
|
+
filterArgs = filterArgs != null ? [dynamicKey].concat((0, _toConsumableArray2["default"])(filterArgs)) : [dynamicKey];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (filterArgs === null) {
|
|
82
|
+
return handleName;
|
|
83
|
+
} else {
|
|
84
|
+
return formatStorageKey(handleName, getArgumentValues(filterArgs, variables));
|
|
85
|
+
}
|
|
66
86
|
}
|
|
67
87
|
/**
|
|
68
88
|
* Given a field and variable values, returns a key that can be used to
|
|
@@ -136,6 +156,14 @@ function getStableVariableValue(name, variables) {
|
|
|
136
156
|
!variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'getVariableValue(): Undefined variable `%s`.', name) : invariant(false) : void 0;
|
|
137
157
|
return stableCopy(variables[name]);
|
|
138
158
|
}
|
|
159
|
+
|
|
160
|
+
function getModuleComponentKey(documentName) {
|
|
161
|
+
return "".concat(MODULE_COMPONENT_KEY_PREFIX).concat(documentName);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getModuleOperationKey(documentName) {
|
|
165
|
+
return "".concat(MODULE_OPERATION_KEY_PREFIX).concat(documentName);
|
|
166
|
+
}
|
|
139
167
|
/**
|
|
140
168
|
* Constants shared by all implementations of RecordSource/MutableRecordSource/etc.
|
|
141
169
|
*/
|
|
@@ -146,7 +174,7 @@ var RelayStoreUtils = {
|
|
|
146
174
|
FRAGMENT_OWNER_KEY: '__fragmentOwner',
|
|
147
175
|
FRAGMENT_PROP_NAME_KEY: '__fragmentPropName',
|
|
148
176
|
MODULE_COMPONENT_KEY: '__module_component',
|
|
149
|
-
|
|
177
|
+
// alias returned by Reader
|
|
150
178
|
ID_KEY: '__id',
|
|
151
179
|
REF_KEY: '__ref',
|
|
152
180
|
REFS_KEY: '__refs',
|
|
@@ -162,6 +190,8 @@ var RelayStoreUtils = {
|
|
|
162
190
|
getArgumentValues: getArgumentValues,
|
|
163
191
|
getHandleStorageKey: getHandleStorageKey,
|
|
164
192
|
getStorageKey: getStorageKey,
|
|
165
|
-
getStableStorageKey: getStableStorageKey
|
|
193
|
+
getStableStorageKey: getStableStorageKey,
|
|
194
|
+
getModuleComponentKey: getModuleComponentKey,
|
|
195
|
+
getModuleOperationKey: getModuleOperationKey
|
|
166
196
|
};
|
|
167
197
|
module.exports = RelayStoreUtils;
|
|
@@ -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
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -17,54 +17,7 @@ var _require2 = require("./RelayStoreUtils"),
|
|
|
17
17
|
|
|
18
18
|
var VIEWER_ID = generateClientID(ROOT_ID, 'viewer');
|
|
19
19
|
var VIEWER_TYPE = 'Viewer';
|
|
20
|
-
/**
|
|
21
|
-
* A runtime handler for the `viewer` field. The actual viewer record will
|
|
22
|
-
* *never* be accessed at runtime because all fragments that reference it will
|
|
23
|
-
* delegate to the handle field. So in order to prevent GC from having to check
|
|
24
|
-
* both the original server field *and* the handle field (which would be almost
|
|
25
|
-
* duplicate work), the handler copies server fields and then deletes the server
|
|
26
|
-
* record.
|
|
27
|
-
*
|
|
28
|
-
* NOTE: This means other handles may not be added on viewer, since they may
|
|
29
|
-
* execute after this handle when the server record is already deleted.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
function update(store, payload) {
|
|
33
|
-
var record = store.get(payload.dataID);
|
|
34
|
-
|
|
35
|
-
if (!record) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var serverViewer = record.getLinkedRecord(payload.fieldKey);
|
|
40
|
-
|
|
41
|
-
if (!serverViewer) {
|
|
42
|
-
// If `serverViewer` is null, `viewer` key for `client:root` should already
|
|
43
|
-
// be null, so no need to `setValue` again.
|
|
44
|
-
return;
|
|
45
|
-
} // Server data already has viewer data at `client:root:viewer`, so link the
|
|
46
|
-
// handle field to the server viewer record.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (serverViewer.getDataID() === VIEWER_ID) {
|
|
50
|
-
record.setValue(null, payload.fieldKey);
|
|
51
|
-
record.setLinkedRecord(serverViewer, payload.handleKey);
|
|
52
|
-
return;
|
|
53
|
-
} // Other ways to access viewer such as mutations may have a different id for
|
|
54
|
-
// viewer: synthesize a record at the canonical viewer id, copy its fields
|
|
55
|
-
// from the server record, and delete the server record link to speed up GC.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var clientViewer = store.get(VIEWER_ID) || store.create(VIEWER_ID, VIEWER_TYPE);
|
|
59
|
-
clientViewer.copyFieldsFrom(serverViewer);
|
|
60
|
-
record.setValue(null, payload.fieldKey);
|
|
61
|
-
record.setLinkedRecord(clientViewer, payload.handleKey); // Make sure the root object points to the viewer object as well
|
|
62
|
-
|
|
63
|
-
var root = store.getRoot();
|
|
64
|
-
root.setLinkedRecord(clientViewer, payload.handleKey);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
20
|
module.exports = {
|
|
68
21
|
VIEWER_ID: VIEWER_ID,
|
|
69
|
-
|
|
22
|
+
VIEWER_TYPE: VIEWER_TYPE
|
|
70
23
|
};
|
package/lib/StoreInspector.js
CHANGED
package/lib/commitLocalUpdate.js
CHANGED
package/lib/deepFreeze.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var _require = require("./RelayViewerHandler"),
|
|
13
|
+
VIEWER_ID = _require.VIEWER_ID,
|
|
14
|
+
VIEWER_TYPE = _require.VIEWER_TYPE;
|
|
15
|
+
|
|
16
|
+
function defaultGetDataID(fieldValue, typeName) {
|
|
17
|
+
if (typeName === VIEWER_TYPE) {
|
|
18
|
+
return fieldValue.id == null ? VIEWER_ID : fieldValue.id;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return fieldValue.id;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = defaultGetDataID;
|