relay-runtime 1.3.0 → 1.5.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/LICENSE +16 -26
- package/index.js +3 -6
- package/lib/ConvertToExecuteFunction.js +73 -0
- package/lib/RelayConcreteNode.js +31 -14
- package/lib/RelayConcreteVariables.js +11 -6
- package/lib/RelayConnectionHandler.js +2 -4
- package/lib/RelayConnectionInterface.js +3 -5
- package/lib/RelayCore.js +4 -6
- package/lib/RelayDataLoader.js +2 -4
- package/lib/RelayDeclarativeMutationConfig.js +316 -0
- package/lib/RelayDefaultHandleKey.js +2 -4
- package/lib/RelayDefaultHandlerProvider.js +2 -4
- package/lib/RelayError.js +2 -6
- package/lib/RelayInMemoryRecordSource.js +2 -4
- package/lib/RelayInternalTypes.js +2 -5
- package/lib/RelayInternals.js +2 -5
- package/lib/RelayMarkSweepStore.js +22 -5
- package/lib/RelayMetricsRecorder.js +9 -9
- package/lib/RelayMockRenderer.js +3 -8
- package/lib/RelayModernEnvironment.js +120 -135
- package/lib/RelayModernFragmentSpecResolver.js +81 -55
- package/lib/RelayModernGraphQLTag.js +8 -17
- package/lib/RelayModernOperationSelector.js +8 -8
- package/lib/RelayModernRecord.js +8 -8
- package/lib/RelayModernSelector.js +54 -43
- package/lib/RelayNetwork.js +9 -11
- package/lib/RelayNetworkDebug.js +4 -7
- package/lib/RelayNetworkLogger.js +2 -4
- package/lib/RelayNetworkLoggerTransaction.js +18 -20
- package/lib/RelayNetworkTypes.js +2 -4
- package/lib/RelayObservable.js +193 -120
- package/lib/RelayProfiler.js +7 -7
- package/lib/RelayPublishQueue.js +17 -9
- package/lib/RelayQueryCaching.js +2 -5
- package/lib/RelayQueryResponseCache.js +3 -5
- package/lib/RelayReader.js +18 -8
- package/lib/RelayRecordProxy.js +12 -11
- package/lib/RelayRecordSourceMutator.js +9 -9
- package/lib/RelayRecordSourceProxy.js +15 -13
- package/lib/RelayRecordSourceSelectorProxy.js +2 -4
- package/lib/RelayRecordState.js +2 -4
- package/lib/RelayReferenceMarker.js +2 -4
- package/lib/RelayResponseNormalizer.js +34 -25
- package/lib/RelayRuntime.js +25 -14
- package/lib/RelayRuntimeTypes.js +22 -0
- package/lib/RelayShallowMock.js +4 -7
- package/lib/RelayStoreTypes.js +2 -4
- package/lib/RelayStoreUtils.js +66 -26
- package/lib/RelayTaskQueue.js +2 -5
- package/lib/RelayTypes.js +2 -5
- package/lib/RelayViewerHandler.js +4 -5
- package/lib/applyRelayModernOptimisticMutation.js +9 -8
- package/lib/cloneRelayHandleSourceField.js +4 -11
- package/lib/commitLocalUpdate.js +2 -4
- package/lib/commitRelayModernMutation.js +24 -22
- package/lib/createRelayNetworkLogger.js +25 -27
- package/lib/dedent.js +2 -5
- package/lib/deepFreeze.js +3 -5
- package/lib/deferrableFragmentKey.js +21 -0
- package/lib/fetchRelayModernQuery.js +13 -21
- package/lib/generateRelayClientID.js +2 -4
- package/lib/getRelayHandleKey.js +2 -4
- package/lib/hasOverlappingIDs.js +2 -4
- package/lib/isCompatibleRelayFragmentType.js +2 -5
- package/lib/isPromise.js +2 -5
- package/lib/isRelayModernEnvironment.js +2 -4
- package/lib/isScalarAndEqual.js +3 -5
- package/lib/normalizePayload.js +10 -13
- package/lib/normalizeRelayPayload.js +8 -5
- package/lib/recycleNodesInto.js +2 -4
- package/lib/relayUnstableBatchedUpdates.js +2 -5
- package/lib/relayUnstableBatchedUpdates.native.js +2 -5
- package/lib/requestRelaySubscription.js +20 -34
- package/lib/simpleClone.js +2 -4
- package/lib/stableCopy.js +35 -0
- package/lib/testEditDistance.js +2 -5
- package/lib/throwFailedPromise.js +2 -5
- package/package.json +4 -5
- package/relay-runtime.js +2307 -2665
- package/relay-runtime.min.js +6 -9
- package/ARCHITECTURE.md +0 -232
- package/PATENTS +0 -33
- package/lib/ConvertToObserveFunction.js +0 -39
- package/lib/RelayDebugger.js +0 -199
- package/lib/RelayRecordSourceInspector.js +0 -289
- package/lib/RelayStoreProxyDebugger.js +0 -44
- package/lib/formatStorageKey.js +0 -37
- package/lib/prettyStringify.js +0 -35
- package/lib/setRelayModernMutationConfigs.js +0 -302
- package/lib/stableJSONStringify.js +0 -45
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
* @providesModule setRelayModernMutationConfigs
|
|
10
|
-
*
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
function setRelayModernMutationConfigs(configs, operation, optimisticUpdater, updater) {
|
|
17
|
-
var configOptimisticUpdates = optimisticUpdater ? [optimisticUpdater] : [];
|
|
18
|
-
var configUpdates = updater ? [updater] : [];
|
|
19
|
-
configs.forEach(function (config) {
|
|
20
|
-
switch (config.type) {
|
|
21
|
-
case 'NODE_DELETE':
|
|
22
|
-
var nodeDeleteResult = nodeDelete(config, operation);
|
|
23
|
-
if (nodeDeleteResult) {
|
|
24
|
-
configOptimisticUpdates.push(nodeDeleteResult);
|
|
25
|
-
configUpdates.push(nodeDeleteResult);
|
|
26
|
-
}
|
|
27
|
-
break;
|
|
28
|
-
case 'RANGE_ADD':
|
|
29
|
-
var rangeAddResult = rangeAdd(config, operation);
|
|
30
|
-
if (rangeAddResult) {
|
|
31
|
-
configOptimisticUpdates.push(rangeAddResult);
|
|
32
|
-
configUpdates.push(rangeAddResult);
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
case 'RANGE_DELETE':
|
|
36
|
-
var rangeDeleteResult = rangeDelete(config, operation);
|
|
37
|
-
if (rangeDeleteResult) {
|
|
38
|
-
configOptimisticUpdates.push(rangeDeleteResult);
|
|
39
|
-
configUpdates.push(rangeDeleteResult);
|
|
40
|
-
}
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
optimisticUpdater = function optimisticUpdater(store, data) {
|
|
45
|
-
configOptimisticUpdates.forEach(function (eachOptimisticUpdater) {
|
|
46
|
-
eachOptimisticUpdater(store, data);
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
updater = function updater(store, data) {
|
|
50
|
-
configUpdates.forEach(function (eachUpdater) {
|
|
51
|
-
eachUpdater(store, data);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
return { optimisticUpdater: optimisticUpdater, updater: updater };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function nodeDelete(config, operation) {
|
|
58
|
-
var updater = void 0;
|
|
59
|
-
if (config.type !== 'NODE_DELETE') {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
var deletedIDFieldName = config.deletedIDFieldName;
|
|
63
|
-
|
|
64
|
-
var rootField = getRootField(operation);
|
|
65
|
-
if (rootField) {
|
|
66
|
-
updater = function updater(store, data) {
|
|
67
|
-
var payload = store.getRootField(rootField);
|
|
68
|
-
if (!payload) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
var deleteID = payload.getValue(deletedIDFieldName);
|
|
72
|
-
var deleteIDs = Array.isArray(deleteID) ? deleteID : [deleteID];
|
|
73
|
-
deleteIDs.forEach(function (id) {
|
|
74
|
-
if (id && typeof id === 'string') {
|
|
75
|
-
store['delete'](id);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return updater;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function rangeAdd(config, operation) {
|
|
84
|
-
var updater = void 0;
|
|
85
|
-
if (config.type !== 'RANGE_ADD') {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
var parentID = config.parentID,
|
|
89
|
-
connectionInfo = config.connectionInfo,
|
|
90
|
-
edgeName = config.edgeName;
|
|
91
|
-
|
|
92
|
-
if (!parentID) {
|
|
93
|
-
require('fbjs/lib/warning')(false, 'setRelayModernMutationConfigs: For mutation config RANGE_ADD ' + 'to work you must include a parentID');
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
var rootField = getRootField(operation);
|
|
97
|
-
if (connectionInfo && rootField) {
|
|
98
|
-
updater = function updater(store, data) {
|
|
99
|
-
var parent = store.get(parentID);
|
|
100
|
-
if (parent) {
|
|
101
|
-
var payload = store.getRootField(rootField);
|
|
102
|
-
if (!payload) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
var serverEdge = payload.getLinkedRecord(edgeName);
|
|
106
|
-
var _iteratorNormalCompletion = true;
|
|
107
|
-
var _didIteratorError = false;
|
|
108
|
-
var _iteratorError = undefined;
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
for (var _iterator = connectionInfo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
112
|
-
var info = _step.value;
|
|
113
|
-
|
|
114
|
-
if (serverEdge) {
|
|
115
|
-
var connection = require('./RelayConnectionHandler').getConnection(parent, info.key, info.filters);
|
|
116
|
-
if (!connection) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
var clientEdge = require('./RelayConnectionHandler').buildConnectionEdge(store, connection, serverEdge);
|
|
120
|
-
if (!clientEdge) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
switch (info.rangeBehavior) {
|
|
124
|
-
case 'append':
|
|
125
|
-
require('./RelayConnectionHandler').insertEdgeAfter(connection, clientEdge);
|
|
126
|
-
break;
|
|
127
|
-
case 'ignore':
|
|
128
|
-
// Do nothing
|
|
129
|
-
break;
|
|
130
|
-
case 'prepend':
|
|
131
|
-
require('./RelayConnectionHandler').insertEdgeBefore(connection, clientEdge);
|
|
132
|
-
break;
|
|
133
|
-
default:
|
|
134
|
-
require('fbjs/lib/warning')(false, 'setRelayModernMutationConfigs: RANGE_ADD range behavior ' + ('\'' + info.rangeBehavior + '\' will not work as expected in RelayModern, ') + "supported range behaviors are 'append', 'prepend', and " + "'ignore'");
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
} catch (err) {
|
|
140
|
-
_didIteratorError = true;
|
|
141
|
-
_iteratorError = err;
|
|
142
|
-
} finally {
|
|
143
|
-
try {
|
|
144
|
-
if (!_iteratorNormalCompletion && _iterator['return']) {
|
|
145
|
-
_iterator['return']();
|
|
146
|
-
}
|
|
147
|
-
} finally {
|
|
148
|
-
if (_didIteratorError) {
|
|
149
|
-
throw _iteratorError;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
return updater;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function rangeDelete(config, operation) {
|
|
160
|
-
var updater = void 0;
|
|
161
|
-
if (config.type !== 'RANGE_DELETE') {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
var parentID = config.parentID,
|
|
165
|
-
connectionKeys = config.connectionKeys,
|
|
166
|
-
pathToConnection = config.pathToConnection,
|
|
167
|
-
deletedIDFieldName = config.deletedIDFieldName;
|
|
168
|
-
|
|
169
|
-
if (!parentID) {
|
|
170
|
-
require('fbjs/lib/warning')(false, 'setRelayModernMutationConfigs: For mutation config RANGE_DELETE ' + 'to work you must include a parentID');
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
var rootField = getRootField(operation);
|
|
174
|
-
if (rootField) {
|
|
175
|
-
updater = function updater(store, data) {
|
|
176
|
-
if (data) {
|
|
177
|
-
var deleteIDs = [];
|
|
178
|
-
var deletedIDField = data[rootField];
|
|
179
|
-
if (deletedIDField && Array.isArray(deletedIDFieldName)) {
|
|
180
|
-
var _iteratorNormalCompletion2 = true;
|
|
181
|
-
var _didIteratorError2 = false;
|
|
182
|
-
var _iteratorError2 = undefined;
|
|
183
|
-
|
|
184
|
-
try {
|
|
185
|
-
for (var _iterator2 = deletedIDFieldName[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
186
|
-
var eachField = _step2.value;
|
|
187
|
-
|
|
188
|
-
if (deletedIDField && typeof deletedIDField === 'object') {
|
|
189
|
-
deletedIDField = deletedIDField[eachField];
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
} catch (err) {
|
|
193
|
-
_didIteratorError2 = true;
|
|
194
|
-
_iteratorError2 = err;
|
|
195
|
-
} finally {
|
|
196
|
-
try {
|
|
197
|
-
if (!_iteratorNormalCompletion2 && _iterator2['return']) {
|
|
198
|
-
_iterator2['return']();
|
|
199
|
-
}
|
|
200
|
-
} finally {
|
|
201
|
-
if (_didIteratorError2) {
|
|
202
|
-
throw _iteratorError2;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (Array.isArray(deletedIDField)) {
|
|
208
|
-
deletedIDField.forEach(function (idObject) {
|
|
209
|
-
if (idObject && idObject.id && typeof idObject === 'object' && typeof idObject.id === 'string') {
|
|
210
|
-
deleteIDs.push(idObject.id);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
} else if (deletedIDField && deletedIDField.id && typeof deletedIDField.id === 'string') {
|
|
214
|
-
deleteIDs.push(deletedIDField.id);
|
|
215
|
-
}
|
|
216
|
-
} else if (deletedIDField && typeof deletedIDFieldName === 'string' && typeof deletedIDField === 'object') {
|
|
217
|
-
deletedIDField = deletedIDField[deletedIDFieldName];
|
|
218
|
-
if (typeof deletedIDField === 'string') {
|
|
219
|
-
deleteIDs.push(deletedIDField);
|
|
220
|
-
} else if (Array.isArray(deletedIDField)) {
|
|
221
|
-
deletedIDField.forEach(function (id) {
|
|
222
|
-
if (typeof id === 'string') {
|
|
223
|
-
deleteIDs.push(id);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
deleteNode(parentID, connectionKeys, pathToConnection, store, deleteIDs);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
return updater;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function deleteNode(parentID, connectionKeys, pathToConnection, store, deleteIDs) {
|
|
236
|
-
require('fbjs/lib/warning')(connectionKeys, 'setRelayModernMutationConfigs: RANGE_DELETE must provide a ' + 'connectionKeys');
|
|
237
|
-
var parent = store.get(parentID);
|
|
238
|
-
if (!parent) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (pathToConnection.length >= 2) {
|
|
242
|
-
var recordProxy = parent;
|
|
243
|
-
for (var i = 1; i < pathToConnection.length - 1; i++) {
|
|
244
|
-
if (recordProxy) {
|
|
245
|
-
recordProxy = recordProxy.getLinkedRecord(pathToConnection[i]);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
// Should never enter loop except edge cases
|
|
249
|
-
if (connectionKeys && recordProxy) {
|
|
250
|
-
var _iteratorNormalCompletion3 = true;
|
|
251
|
-
var _didIteratorError3 = false;
|
|
252
|
-
var _iteratorError3 = undefined;
|
|
253
|
-
|
|
254
|
-
try {
|
|
255
|
-
var _loop = function _loop() {
|
|
256
|
-
var key = _step3.value;
|
|
257
|
-
|
|
258
|
-
var connection = require('./RelayConnectionHandler').getConnection(recordProxy, key.key, key.filters);
|
|
259
|
-
if (connection) {
|
|
260
|
-
deleteIDs.forEach(function (deleteID) {
|
|
261
|
-
require('./RelayConnectionHandler').deleteNode(connection, deleteID);
|
|
262
|
-
});
|
|
263
|
-
return 'break';
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
for (var _iterator3 = connectionKeys[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
268
|
-
var _ret = _loop();
|
|
269
|
-
|
|
270
|
-
if (_ret === 'break') break;
|
|
271
|
-
}
|
|
272
|
-
} catch (err) {
|
|
273
|
-
_didIteratorError3 = true;
|
|
274
|
-
_iteratorError3 = err;
|
|
275
|
-
} finally {
|
|
276
|
-
try {
|
|
277
|
-
if (!_iteratorNormalCompletion3 && _iterator3['return']) {
|
|
278
|
-
_iterator3['return']();
|
|
279
|
-
}
|
|
280
|
-
} finally {
|
|
281
|
-
if (_didIteratorError3) {
|
|
282
|
-
throw _iteratorError3;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
} else {
|
|
287
|
-
require('fbjs/lib/warning')(false, 'setRelayModernMutationConfigs: RANGE_DELETE ' + 'pathToConnection is incorrect. Unable to find connection with ' + 'parentID: %s and path: %s', parentID, pathToConnection.toString());
|
|
288
|
-
}
|
|
289
|
-
} else {
|
|
290
|
-
require('fbjs/lib/warning')(false, 'setRelayModernMutationConfigs: RANGE_DELETE ' + 'pathToConnection must include at least parent and connection');
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function getRootField(operation) {
|
|
295
|
-
var rootField = void 0;
|
|
296
|
-
if (operation.fragment && operation.fragment.selections && operation.fragment.selections.length > 0 && operation.fragment.selections[0].kind === 'LinkedField') {
|
|
297
|
-
rootField = operation.fragment.selections[0].name;
|
|
298
|
-
}
|
|
299
|
-
return rootField;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
module.exports = setRelayModernMutationConfigs;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @providesModule stableJSONStringify
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Simple recursive stringifier that produces a stable JSON string suitable for
|
|
18
|
-
* use as a cache key. Does not handle corner-cases such as circular references
|
|
19
|
-
* or exotic types.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
function stableJSONStringify(obj) {
|
|
23
|
-
if (Array.isArray(obj)) {
|
|
24
|
-
var result = [];
|
|
25
|
-
for (var ii = 0; ii < obj.length; ii++) {
|
|
26
|
-
var value = obj[ii] !== undefined ? obj[ii] : null;
|
|
27
|
-
result.push(stableJSONStringify(value));
|
|
28
|
-
}
|
|
29
|
-
return '[' + result.join(',') + ']';
|
|
30
|
-
} else if (typeof obj === 'object' && obj) {
|
|
31
|
-
var _result = [];
|
|
32
|
-
var keys = Object.keys(obj);
|
|
33
|
-
keys.sort();
|
|
34
|
-
for (var _ii = 0; _ii < keys.length; _ii++) {
|
|
35
|
-
var key = keys[_ii];
|
|
36
|
-
var _value = stableJSONStringify(obj[key]);
|
|
37
|
-
_result.push('"' + key + '":' + _value);
|
|
38
|
-
}
|
|
39
|
-
return '{' + _result.join(',') + '}';
|
|
40
|
-
} else {
|
|
41
|
-
return JSON.stringify(obj);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
module.exports = stableJSONStringify;
|