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.
- package/index.js +1 -1
- package/lib/{generateRelayClientID.js → ClientID.js} +10 -3
- package/lib/ConvertToExecuteFunction.js +6 -4
- package/lib/DataChecker.js +88 -69
- package/lib/NormalizationNode.js +1 -1
- package/lib/ReaderNode.js +1 -1
- package/lib/RelayCombinedEnvironmentTypes.js +1 -1
- package/lib/RelayConcreteNode.js +5 -2
- package/lib/RelayConcreteVariables.js +15 -9
- package/lib/RelayConnectionHandler.js +27 -20
- package/lib/RelayConnectionInterface.js +4 -2
- package/lib/RelayCore.js +48 -15
- package/lib/RelayDeclarativeMutationConfig.js +16 -15
- package/lib/RelayDefaultHandleKey.js +1 -1
- package/lib/RelayDefaultHandlerProvider.js +7 -6
- package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
- package/lib/RelayError.js +7 -2
- package/lib/RelayFeatureFlags.js +16 -0
- package/lib/RelayInMemoryRecordSource.js +8 -2
- package/lib/RelayModernEnvironment.js +159 -237
- package/lib/RelayModernFragmentOwner.js +72 -0
- package/lib/RelayModernFragmentSpecResolver.js +66 -15
- package/lib/RelayModernGraphQLTag.js +9 -5
- package/lib/RelayModernOperationDescriptor.js +9 -6
- package/lib/RelayModernQueryExecutor.js +791 -0
- package/lib/RelayModernRecord.js +44 -24
- package/lib/RelayModernSelector.js +208 -82
- package/lib/RelayModernStore.js +66 -34
- package/lib/RelayNetwork.js +14 -7
- package/lib/RelayNetworkLogger.js +6 -2
- package/lib/RelayNetworkLoggerTransaction.js +8 -4
- package/lib/RelayNetworkTypes.js +1 -1
- package/lib/RelayObservable.js +72 -41
- package/lib/RelayOperationTracker.js +265 -0
- package/lib/RelayProfiler.js +10 -6
- package/lib/RelayPublishQueue.js +66 -47
- package/lib/RelayQueryResponseCache.js +11 -5
- package/lib/RelayReader.js +135 -126
- package/lib/RelayRecordProxy.js +24 -20
- package/lib/RelayRecordSourceMutator.js +88 -25
- package/lib/RelayRecordSourceProxy.js +38 -19
- package/lib/RelayRecordSourceSelectorProxy.js +10 -7
- package/lib/RelayRecordState.js +1 -1
- package/lib/RelayReferenceMarker.js +66 -55
- package/lib/RelayReplaySubject.js +134 -0
- package/lib/RelayResponseNormalizer.js +245 -134
- package/lib/RelayRuntimeTypes.js +1 -1
- package/lib/RelayStoreUtils.js +55 -16
- package/lib/RelayViewerHandler.js +8 -50
- package/lib/StoreInspector.js +171 -0
- package/lib/applyRelayModernOptimisticMutation.js +8 -2
- package/lib/cloneRelayHandleSourceField.js +17 -7
- package/lib/commitLocalUpdate.js +1 -1
- package/lib/commitRelayModernMutation.js +33 -13
- package/lib/createRelayContext.js +27 -0
- package/lib/createRelayNetworkLogger.js +8 -2
- package/lib/deepFreeze.js +1 -1
- package/lib/defaultGetDataID.js +24 -0
- package/lib/fetchQueryInternal.js +232 -0
- package/lib/fetchRelayModernQuery.js +5 -3
- package/lib/getFragmentIdentifier.js +52 -0
- package/lib/getFragmentSpecIdentifier.js +26 -0
- package/lib/getRelayHandleKey.js +8 -2
- package/lib/getRequestParametersIdentifier.js +26 -0
- package/lib/hasOverlappingIDs.js +1 -1
- package/lib/index.js +155 -53
- package/lib/isPromise.js +1 -1
- package/lib/isScalarAndEqual.js +1 -1
- package/lib/normalizeRelayPayload.js +19 -10
- package/lib/recycleNodesInto.js +23 -5
- package/lib/requestRelaySubscription.js +9 -3
- package/lib/validateMutation.js +13 -6
- package/package.json +2 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/lib/normalizePayload.js +0 -37
- package/lib/simpleClone.js +0 -27
package/index.js
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
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';
|
|
11
11
|
|
|
12
12
|
var PREFIX = 'client:';
|
|
13
13
|
|
|
14
|
-
function
|
|
14
|
+
function generateClientID(id, storageKey, index) {
|
|
15
15
|
var key = id + ':' + storageKey;
|
|
16
16
|
|
|
17
17
|
if (index != null) {
|
|
@@ -25,4 +25,11 @@ function generateRelayClientID(id, storageKey, index) {
|
|
|
25
25
|
return key;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
function isClientID(id) {
|
|
29
|
+
return id.indexOf(PREFIX) === 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
generateClientID: generateClientID,
|
|
34
|
+
isClientID: isClientID
|
|
35
|
+
};
|
|
@@ -4,11 +4,13 @@
|
|
|
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';
|
|
11
11
|
|
|
12
|
+
var RelayObservable = require("./RelayObservable");
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Converts a FetchFunction into an ExecuteFunction for use by RelayNetwork.
|
|
14
16
|
*/
|
|
@@ -19,12 +21,12 @@ function convertFetch(fn) {
|
|
|
19
21
|
// Relay codebase, it is explicitly handled here.
|
|
20
22
|
|
|
21
23
|
if (result instanceof Error) {
|
|
22
|
-
return
|
|
24
|
+
return RelayObservable.create(function (sink) {
|
|
23
25
|
return sink.error(result);
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
return
|
|
29
|
+
return RelayObservable.from(result);
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
@@ -34,7 +36,7 @@ function convertFetch(fn) {
|
|
|
34
36
|
|
|
35
37
|
function convertSubscribe(fn) {
|
|
36
38
|
return function subscribe(operation, variables, cacheConfig) {
|
|
37
|
-
return
|
|
39
|
+
return RelayObservable.fromLegacy(function (observer) {
|
|
38
40
|
return fn(operation, variables, cacheConfig, observer);
|
|
39
41
|
});
|
|
40
42
|
};
|
package/lib/DataChecker.js
CHANGED
|
@@ -4,12 +4,42 @@
|
|
|
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
|
* @emails oncall+relay
|
|
10
10
|
*/
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
var RelayConcreteNode = require("./RelayConcreteNode");
|
|
14
|
+
|
|
15
|
+
var RelayRecordSourceMutator = require("./RelayRecordSourceMutator");
|
|
16
|
+
|
|
17
|
+
var RelayRecordSourceProxy = require("./RelayRecordSourceProxy");
|
|
18
|
+
|
|
19
|
+
var RelayStoreUtils = require("./RelayStoreUtils");
|
|
20
|
+
|
|
21
|
+
var cloneRelayHandleSourceField = require("./cloneRelayHandleSourceField");
|
|
22
|
+
|
|
23
|
+
var invariant = require("fbjs/lib/invariant");
|
|
24
|
+
|
|
25
|
+
var _require = require("./RelayRecordState"),
|
|
26
|
+
EXISTENT = _require.EXISTENT,
|
|
27
|
+
UNKNOWN = _require.UNKNOWN;
|
|
28
|
+
|
|
29
|
+
var CONDITION = RelayConcreteNode.CONDITION,
|
|
30
|
+
CLIENT_EXTENSION = RelayConcreteNode.CLIENT_EXTENSION,
|
|
31
|
+
DEFER = RelayConcreteNode.DEFER,
|
|
32
|
+
FRAGMENT_SPREAD = RelayConcreteNode.FRAGMENT_SPREAD,
|
|
33
|
+
INLINE_FRAGMENT = RelayConcreteNode.INLINE_FRAGMENT,
|
|
34
|
+
LINKED_FIELD = RelayConcreteNode.LINKED_FIELD,
|
|
35
|
+
LINKED_HANDLE = RelayConcreteNode.LINKED_HANDLE,
|
|
36
|
+
MODULE_IMPORT = RelayConcreteNode.MODULE_IMPORT,
|
|
37
|
+
SCALAR_FIELD = RelayConcreteNode.SCALAR_FIELD,
|
|
38
|
+
SCALAR_HANDLE = RelayConcreteNode.SCALAR_HANDLE,
|
|
39
|
+
STREAM = RelayConcreteNode.STREAM;
|
|
40
|
+
var getModuleOperationKey = RelayStoreUtils.getModuleOperationKey,
|
|
41
|
+
getStorageKey = RelayStoreUtils.getStorageKey,
|
|
42
|
+
getArgumentValues = RelayStoreUtils.getArgumentValues;
|
|
13
43
|
/**
|
|
14
44
|
* Synchronously check whether the records required to fulfill the given
|
|
15
45
|
* `selector` are present in `source`.
|
|
@@ -20,11 +50,12 @@
|
|
|
20
50
|
*
|
|
21
51
|
* If all records are present, returns `true`, otherwise `false`.
|
|
22
52
|
*/
|
|
23
|
-
|
|
53
|
+
|
|
54
|
+
function check(source, target, selector, handlers, operationLoader, getDataID) {
|
|
24
55
|
var dataID = selector.dataID,
|
|
25
56
|
node = selector.node,
|
|
26
57
|
variables = selector.variables;
|
|
27
|
-
var checker = new DataChecker(source, target, variables, handlers, operationLoader);
|
|
58
|
+
var checker = new DataChecker(source, target, variables, handlers, operationLoader, getDataID);
|
|
28
59
|
return checker.check(node, dataID);
|
|
29
60
|
}
|
|
30
61
|
/**
|
|
@@ -35,16 +66,16 @@ function check(source, target, selector, handlers, operationLoader) {
|
|
|
35
66
|
var DataChecker =
|
|
36
67
|
/*#__PURE__*/
|
|
37
68
|
function () {
|
|
38
|
-
function DataChecker(source, target, variables, handlers, operationLoader) {
|
|
69
|
+
function DataChecker(source, target, variables, handlers, operationLoader, getDataID) {
|
|
39
70
|
var _operationLoader;
|
|
40
71
|
|
|
41
72
|
this._operationLoader = (_operationLoader = operationLoader) !== null && _operationLoader !== void 0 ? _operationLoader : null;
|
|
42
73
|
this._handlers = handlers;
|
|
43
|
-
this._mutator = new
|
|
74
|
+
this._mutator = new RelayRecordSourceMutator(source, target);
|
|
44
75
|
this._recordWasMissing = false;
|
|
45
76
|
this._source = source;
|
|
46
77
|
this._variables = variables;
|
|
47
|
-
this._recordSourceProxy = new
|
|
78
|
+
this._recordSourceProxy = new RelayRecordSourceProxy(this._mutator, getDataID);
|
|
48
79
|
}
|
|
49
80
|
|
|
50
81
|
var _proto = DataChecker.prototype;
|
|
@@ -56,7 +87,7 @@ function () {
|
|
|
56
87
|
};
|
|
57
88
|
|
|
58
89
|
_proto._getVariableValue = function _getVariableValue(name) {
|
|
59
|
-
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ?
|
|
90
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayAsyncLoader(): Undefined variable `%s`.', name) : invariant(false) : void 0;
|
|
60
91
|
return this._variables[name];
|
|
61
92
|
};
|
|
62
93
|
|
|
@@ -66,7 +97,7 @@ function () {
|
|
|
66
97
|
|
|
67
98
|
_proto._getDataForHandlers = function _getDataForHandlers(field, dataID) {
|
|
68
99
|
return {
|
|
69
|
-
args: field.args ?
|
|
100
|
+
args: field.args ? getArgumentValues(field.args, this._variables) : {},
|
|
70
101
|
// Getting a snapshot of the record state is potentially expensive since
|
|
71
102
|
// we will need to merge the sink and source records. Since we do not create
|
|
72
103
|
// any new records in this process, it is probably reasonable to provide
|
|
@@ -132,7 +163,7 @@ function () {
|
|
|
132
163
|
if (handler.kind === 'linked') {
|
|
133
164
|
var newValue = handler.handle(field, record, args, this._recordSourceProxy);
|
|
134
165
|
|
|
135
|
-
if (newValue != null && this._mutator.getStatus(newValue) ===
|
|
166
|
+
if (newValue != null && this._mutator.getStatus(newValue) === EXISTENT) {
|
|
136
167
|
return newValue;
|
|
137
168
|
}
|
|
138
169
|
}
|
|
@@ -175,7 +206,7 @@ function () {
|
|
|
175
206
|
|
|
176
207
|
if (newValue != null) {
|
|
177
208
|
return newValue.filter(function (linkedID) {
|
|
178
|
-
return linkedID != null && _this._mutator.getStatus(linkedID) ===
|
|
209
|
+
return linkedID != null && _this._mutator.getStatus(linkedID) === EXISTENT;
|
|
179
210
|
});
|
|
180
211
|
}
|
|
181
212
|
}
|
|
@@ -201,11 +232,11 @@ function () {
|
|
|
201
232
|
_proto._traverse = function _traverse(node, dataID) {
|
|
202
233
|
var status = this._mutator.getStatus(dataID);
|
|
203
234
|
|
|
204
|
-
if (status ===
|
|
235
|
+
if (status === UNKNOWN) {
|
|
205
236
|
this._handleMissing();
|
|
206
237
|
}
|
|
207
238
|
|
|
208
|
-
if (status ===
|
|
239
|
+
if (status === EXISTENT) {
|
|
209
240
|
this._traverseSelections(node.selections, dataID);
|
|
210
241
|
}
|
|
211
242
|
};
|
|
@@ -215,12 +246,12 @@ function () {
|
|
|
215
246
|
|
|
216
247
|
selections.forEach(function (selection) {
|
|
217
248
|
switch (selection.kind) {
|
|
218
|
-
case
|
|
249
|
+
case SCALAR_FIELD:
|
|
219
250
|
_this2._checkScalar(selection, dataID);
|
|
220
251
|
|
|
221
252
|
break;
|
|
222
253
|
|
|
223
|
-
case
|
|
254
|
+
case LINKED_FIELD:
|
|
224
255
|
if (selection.plural) {
|
|
225
256
|
_this2._checkPluralLink(selection, dataID);
|
|
226
257
|
} else {
|
|
@@ -229,7 +260,7 @@ function () {
|
|
|
229
260
|
|
|
230
261
|
break;
|
|
231
262
|
|
|
232
|
-
case
|
|
263
|
+
case CONDITION:
|
|
233
264
|
var conditionValue = _this2._getVariableValue(selection.condition);
|
|
234
265
|
|
|
235
266
|
if (conditionValue === selection.passingValue) {
|
|
@@ -238,7 +269,7 @@ function () {
|
|
|
238
269
|
|
|
239
270
|
break;
|
|
240
271
|
|
|
241
|
-
case
|
|
272
|
+
case INLINE_FRAGMENT:
|
|
242
273
|
var typeName = _this2._mutator.getType(dataID);
|
|
243
274
|
|
|
244
275
|
if (typeName != null && typeName === selection.type) {
|
|
@@ -247,10 +278,10 @@ function () {
|
|
|
247
278
|
|
|
248
279
|
break;
|
|
249
280
|
|
|
250
|
-
case
|
|
281
|
+
case LINKED_HANDLE:
|
|
251
282
|
// Handles have no selections themselves; traverse the original field
|
|
252
283
|
// where the handle was set-up instead.
|
|
253
|
-
var handleField =
|
|
284
|
+
var handleField = cloneRelayHandleSourceField(selection, selections, _this2._variables);
|
|
254
285
|
|
|
255
286
|
if (handleField.plural) {
|
|
256
287
|
_this2._checkPluralLink(handleField, dataID);
|
|
@@ -260,78 +291,66 @@ function () {
|
|
|
260
291
|
|
|
261
292
|
break;
|
|
262
293
|
|
|
263
|
-
case
|
|
264
|
-
_this2.
|
|
294
|
+
case MODULE_IMPORT:
|
|
295
|
+
_this2._checkModuleImport(selection, dataID);
|
|
265
296
|
|
|
266
297
|
break;
|
|
267
298
|
|
|
268
|
-
case
|
|
269
|
-
case
|
|
270
|
-
|
|
299
|
+
case DEFER:
|
|
300
|
+
case STREAM:
|
|
301
|
+
_this2._traverseSelections(selection.selections, dataID);
|
|
271
302
|
|
|
272
303
|
break;
|
|
273
304
|
|
|
305
|
+
case SCALAR_HANDLE:
|
|
306
|
+
case FRAGMENT_SPREAD:
|
|
307
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayAsyncLoader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0; // $FlowExpectedError - we need the break; for OSS linter
|
|
308
|
+
|
|
309
|
+
break;
|
|
310
|
+
|
|
311
|
+
case CLIENT_EXTENSION:
|
|
312
|
+
var recordWasMissing = _this2._recordWasMissing;
|
|
313
|
+
|
|
314
|
+
_this2._traverseSelections(selection.selections, dataID);
|
|
315
|
+
|
|
316
|
+
_this2._recordWasMissing = recordWasMissing;
|
|
317
|
+
break;
|
|
318
|
+
|
|
274
319
|
default:
|
|
275
320
|
selection;
|
|
276
|
-
!false ? process.env.NODE_ENV !== "production" ?
|
|
321
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayAsyncLoader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
|
|
277
322
|
}
|
|
278
323
|
});
|
|
279
324
|
};
|
|
280
325
|
|
|
281
|
-
_proto.
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
var
|
|
326
|
+
_proto._checkModuleImport = function _checkModuleImport(moduleImport, dataID) {
|
|
327
|
+
var operationLoader = this._operationLoader;
|
|
328
|
+
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DataChecker: Expected an operationLoader to be configured when using `@module`.') : invariant(false) : void 0;
|
|
329
|
+
var operationKey = getModuleOperationKey(moduleImport.documentName);
|
|
285
330
|
|
|
286
|
-
|
|
287
|
-
this._handleMissing();
|
|
288
|
-
} else if (linkedID !== null) {
|
|
289
|
-
var status = this._mutator.getStatus(linkedID);
|
|
331
|
+
var operationReference = this._mutator.getValue(dataID, operationKey);
|
|
290
332
|
|
|
291
|
-
|
|
333
|
+
if (operationReference == null) {
|
|
334
|
+
if (operationReference === undefined) {
|
|
292
335
|
this._handleMissing();
|
|
293
|
-
|
|
294
|
-
return;
|
|
295
336
|
}
|
|
296
337
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
var typeName = this._mutator.getType(linkedID);
|
|
302
|
-
|
|
303
|
-
var match = typeName != null ? field.matchesByType[typeName] : null;
|
|
304
|
-
|
|
305
|
-
if (match != null) {
|
|
306
|
-
var operationLoader = this._operationLoader;
|
|
307
|
-
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'DataChecker: Expected an operationLoader to be configured when using `@match`.') : require("fbjs/lib/invariant")(false) : void 0;
|
|
308
|
-
|
|
309
|
-
var operationReference = this._mutator.getValue(linkedID, require("./RelayStoreUtils").MATCH_FRAGMENT_KEY);
|
|
310
|
-
|
|
311
|
-
if (operationReference === undefined) {
|
|
312
|
-
this._handleMissing();
|
|
313
|
-
|
|
314
|
-
return;
|
|
315
|
-
} else if (operationReference === null) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
318
340
|
|
|
319
|
-
|
|
341
|
+
var operation = operationLoader.get(operationReference);
|
|
320
342
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
} else {// TODO: warn: store is corrupt: the field should be null if the typename did not match
|
|
329
|
-
}
|
|
343
|
+
if (operation != null) {
|
|
344
|
+
this._traverse(operation, dataID);
|
|
345
|
+
} else {
|
|
346
|
+
// If the fragment is not available, we assume that the data cannot have been
|
|
347
|
+
// processed yet and must therefore be missing.
|
|
348
|
+
this._handleMissing();
|
|
330
349
|
}
|
|
331
350
|
};
|
|
332
351
|
|
|
333
352
|
_proto._checkScalar = function _checkScalar(field, dataID) {
|
|
334
|
-
var storageKey =
|
|
353
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
335
354
|
|
|
336
355
|
var fieldValue = this._mutator.getValue(dataID, storageKey);
|
|
337
356
|
|
|
@@ -345,7 +364,7 @@ function () {
|
|
|
345
364
|
};
|
|
346
365
|
|
|
347
366
|
_proto._checkLink = function _checkLink(field, dataID) {
|
|
348
|
-
var storageKey =
|
|
367
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
349
368
|
|
|
350
369
|
var linkedID = this._mutator.getLinkedRecordID(dataID, storageKey);
|
|
351
370
|
|
|
@@ -365,7 +384,7 @@ function () {
|
|
|
365
384
|
_proto._checkPluralLink = function _checkPluralLink(field, dataID) {
|
|
366
385
|
var _this3 = this;
|
|
367
386
|
|
|
368
|
-
var storageKey =
|
|
387
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
369
388
|
|
|
370
389
|
var linkedIDs = this._mutator.getLinkedRecordIDs(dataID, storageKey);
|
|
371
390
|
|
package/lib/NormalizationNode.js
CHANGED
package/lib/ReaderNode.js
CHANGED
package/lib/RelayConcreteNode.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';
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
*/
|
|
23
23
|
var RelayConcreteNode = {
|
|
24
24
|
CONDITION: 'Condition',
|
|
25
|
+
CLIENT_EXTENSION: 'ClientExtension',
|
|
26
|
+
DEFER: 'Defer',
|
|
25
27
|
FRAGMENT: 'Fragment',
|
|
26
28
|
FRAGMENT_SPREAD: 'FragmentSpread',
|
|
27
29
|
INLINE_FRAGMENT: 'InlineFragment',
|
|
@@ -29,13 +31,14 @@ var RelayConcreteNode = {
|
|
|
29
31
|
LINKED_HANDLE: 'LinkedHandle',
|
|
30
32
|
LITERAL: 'Literal',
|
|
31
33
|
LOCAL_ARGUMENT: 'LocalArgument',
|
|
32
|
-
|
|
34
|
+
MODULE_IMPORT: 'ModuleImport',
|
|
33
35
|
OPERATION: 'Operation',
|
|
34
36
|
REQUEST: 'Request',
|
|
35
37
|
ROOT_ARGUMENT: 'RootArgument',
|
|
36
38
|
SCALAR_FIELD: 'ScalarField',
|
|
37
39
|
SCALAR_HANDLE: 'ScalarHandle',
|
|
38
40
|
SPLIT_OPERATION: 'SplitOperation',
|
|
41
|
+
STREAM: 'Stream',
|
|
39
42
|
VARIABLE: 'Variable'
|
|
40
43
|
};
|
|
41
44
|
module.exports = RelayConcreteNode;
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
13
|
+
|
|
14
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
|
15
|
+
|
|
16
|
+
var invariant = require("fbjs/lib/invariant");
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Determines the variables that are in scope for a fragment given the variables
|
|
@@ -35,10 +39,15 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
|
|
|
35
39
|
case 'RootArgument':
|
|
36
40
|
if (!rootVariables.hasOwnProperty(definition.name)) {
|
|
37
41
|
/*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
42
|
+
* Global variables passed as values of @arguments are not required to
|
|
43
|
+
* be declared unless they are used by the callee fragment or a
|
|
44
|
+
* descendant. In this case, the root variable may not be defined when
|
|
45
|
+
* resolving the callee's variables. The value is explicitly set to
|
|
46
|
+
* undefined to conform to the check in
|
|
47
|
+
* RelayStoreUtils.getStableVariableValue() that variable keys are all
|
|
48
|
+
* present.
|
|
41
49
|
*/
|
|
50
|
+
variables[definition.name] = undefined;
|
|
42
51
|
break;
|
|
43
52
|
}
|
|
44
53
|
|
|
@@ -46,7 +55,8 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
|
|
|
46
55
|
break;
|
|
47
56
|
|
|
48
57
|
default:
|
|
49
|
-
|
|
58
|
+
definition;
|
|
59
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayConcreteVariables: Unexpected node kind `%s` in fragment `%s`.', definition.kind, fragment.name) : invariant(false) : void 0;
|
|
50
60
|
}
|
|
51
61
|
});
|
|
52
62
|
return variables || argumentVariables;
|
|
@@ -69,10 +79,6 @@ function getOperationVariables(operation, variables) {
|
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
operationVariables[def.name] = value;
|
|
72
|
-
|
|
73
|
-
if (process.env.NODE_ENV !== "production") {
|
|
74
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(value != null || def.type[def.type.length - 1] !== '!', 'RelayConcreteVariables: Expected a value for non-nullable variable ' + '`$%s: %s` on operation `%s`, got `%s`. Make sure you supply a ' + 'value for all non-nullable arguments.', def.name, def.type, operation.name, JSON.stringify(value)) : void 0;
|
|
75
|
-
}
|
|
76
82
|
});
|
|
77
83
|
return operationVariables;
|
|
78
84
|
}
|
|
@@ -9,6 +9,17 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
+
var RelayConnectionInterface = require("./RelayConnectionInterface");
|
|
13
|
+
|
|
14
|
+
var getRelayHandleKey = require("./getRelayHandleKey");
|
|
15
|
+
|
|
16
|
+
var invariant = require("fbjs/lib/invariant");
|
|
17
|
+
|
|
18
|
+
var warning = require("fbjs/lib/warning");
|
|
19
|
+
|
|
20
|
+
var _require = require("./ClientID"),
|
|
21
|
+
generateClientID = _require.generateClientID;
|
|
22
|
+
|
|
12
23
|
var CONNECTION = 'connection'; // Per-instance incrementing index used to generate unique edge IDs
|
|
13
24
|
|
|
14
25
|
var NEXT_EDGE_INDEX = '__connection_next_edge_index';
|
|
@@ -27,7 +38,7 @@ function update(store, payload) {
|
|
|
27
38
|
return;
|
|
28
39
|
}
|
|
29
40
|
|
|
30
|
-
var _RelayConnectionInter =
|
|
41
|
+
var _RelayConnectionInter = RelayConnectionInterface.get(),
|
|
31
42
|
EDGES = _RelayConnectionInter.EDGES,
|
|
32
43
|
END_CURSOR = _RelayConnectionInter.END_CURSOR,
|
|
33
44
|
HAS_NEXT_PAGE = _RelayConnectionInter.HAS_NEXT_PAGE,
|
|
@@ -49,7 +60,7 @@ function update(store, payload) {
|
|
|
49
60
|
|
|
50
61
|
if (!clientConnection) {
|
|
51
62
|
// Initial fetch with data: copy fields from the server record
|
|
52
|
-
var connection = store.create(
|
|
63
|
+
var connection = store.create(generateClientID(record.getDataID(), payload.handleKey), serverConnection.getType());
|
|
53
64
|
connection.setValue(0, NEXT_EDGE_INDEX);
|
|
54
65
|
connection.copyFieldsFrom(serverConnection);
|
|
55
66
|
var serverEdges = serverConnection.getLinkedRecords(EDGES);
|
|
@@ -62,7 +73,7 @@ function update(store, payload) {
|
|
|
62
73
|
}
|
|
63
74
|
|
|
64
75
|
record.setLinkedRecord(connection, payload.handleKey);
|
|
65
|
-
clientPageInfo = store.create(
|
|
76
|
+
clientPageInfo = store.create(generateClientID(connection.getDataID(), PAGE_INFO), PAGE_INFO_TYPE);
|
|
66
77
|
clientPageInfo.setValue(false, HAS_NEXT_PAGE);
|
|
67
78
|
clientPageInfo.setValue(false, HAS_PREV_PAGE);
|
|
68
79
|
clientPageInfo.setValue(null, END_CURSOR);
|
|
@@ -113,7 +124,7 @@ function update(store, payload) {
|
|
|
113
124
|
mergeEdges(prevEdges, nextEdges, nodeIDs);
|
|
114
125
|
mergeEdges(_serverEdges, nextEdges, nodeIDs);
|
|
115
126
|
} else {
|
|
116
|
-
process.env.NODE_ENV !== "production" ?
|
|
127
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'RelayConnectionHandler: Unexpected after cursor `%s`, edges must ' + 'be fetched from the end of the list (`%s`).', args.after, clientPageInfo && clientPageInfo.getValue(END_CURSOR)) : void 0;
|
|
117
128
|
return;
|
|
118
129
|
}
|
|
119
130
|
} else if (args.before != null) {
|
|
@@ -124,7 +135,7 @@ function update(store, payload) {
|
|
|
124
135
|
mergeEdges(_serverEdges, nextEdges, _nodeIDs);
|
|
125
136
|
mergeEdges(prevEdges, nextEdges, _nodeIDs);
|
|
126
137
|
} else {
|
|
127
|
-
process.env.NODE_ENV !== "production" ?
|
|
138
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'RelayConnectionHandler: Unexpected before cursor `%s`, edges must ' + 'be fetched from the beginning of the list (`%s`).', args.before, clientPageInfo && clientPageInfo.getValue(START_CURSOR)) : void 0;
|
|
128
139
|
return;
|
|
129
140
|
}
|
|
130
141
|
} else {
|
|
@@ -208,8 +219,7 @@ function update(store, payload) {
|
|
|
208
219
|
|
|
209
220
|
|
|
210
221
|
function getConnection(record, key, filters) {
|
|
211
|
-
var handleKey =
|
|
212
|
-
|
|
222
|
+
var handleKey = getRelayHandleKey(CONNECTION, key, null);
|
|
213
223
|
return record.getLinkedRecord(handleKey, filters);
|
|
214
224
|
}
|
|
215
225
|
/**
|
|
@@ -249,7 +259,7 @@ function getConnection(record, key, filters) {
|
|
|
249
259
|
|
|
250
260
|
|
|
251
261
|
function insertEdgeAfter(record, newEdge, cursor) {
|
|
252
|
-
var _RelayConnectionInter2 =
|
|
262
|
+
var _RelayConnectionInter2 = RelayConnectionInterface.get(),
|
|
253
263
|
CURSOR = _RelayConnectionInter2.CURSOR,
|
|
254
264
|
EDGES = _RelayConnectionInter2.EDGES;
|
|
255
265
|
|
|
@@ -299,7 +309,7 @@ function insertEdgeAfter(record, newEdge, cursor) {
|
|
|
299
309
|
|
|
300
310
|
|
|
301
311
|
function createEdge(store, record, node, edgeType) {
|
|
302
|
-
var _RelayConnectionInter3 =
|
|
312
|
+
var _RelayConnectionInter3 = RelayConnectionInterface.get(),
|
|
303
313
|
NODE = _RelayConnectionInter3.NODE; // An index-based client ID could easily conflict (unless it was
|
|
304
314
|
// auto-incrementing, but there is nowhere to the store the id)
|
|
305
315
|
// Instead, construct a client ID based on the connection ID and node ID,
|
|
@@ -308,8 +318,7 @@ function createEdge(store, record, node, edgeType) {
|
|
|
308
318
|
// duplicates.
|
|
309
319
|
|
|
310
320
|
|
|
311
|
-
var edgeID =
|
|
312
|
-
|
|
321
|
+
var edgeID = generateClientID(record.getDataID(), node.getDataID());
|
|
313
322
|
var edge = store.get(edgeID);
|
|
314
323
|
|
|
315
324
|
if (!edge) {
|
|
@@ -356,7 +365,7 @@ function createEdge(store, record, node, edgeType) {
|
|
|
356
365
|
|
|
357
366
|
|
|
358
367
|
function insertEdgeBefore(record, newEdge, cursor) {
|
|
359
|
-
var _RelayConnectionInter4 =
|
|
368
|
+
var _RelayConnectionInter4 = RelayConnectionInterface.get(),
|
|
360
369
|
CURSOR = _RelayConnectionInter4.CURSOR,
|
|
361
370
|
EDGES = _RelayConnectionInter4.EDGES;
|
|
362
371
|
|
|
@@ -405,7 +414,7 @@ function insertEdgeBefore(record, newEdge, cursor) {
|
|
|
405
414
|
|
|
406
415
|
|
|
407
416
|
function deleteNode(record, nodeID) {
|
|
408
|
-
var _RelayConnectionInter5 =
|
|
417
|
+
var _RelayConnectionInter5 = RelayConnectionInterface.get(),
|
|
409
418
|
EDGES = _RelayConnectionInter5.EDGES,
|
|
410
419
|
NODE = _RelayConnectionInter5.NODE;
|
|
411
420
|
|
|
@@ -454,14 +463,12 @@ function buildConnectionEdge(store, connection, edge) {
|
|
|
454
463
|
return edge;
|
|
455
464
|
}
|
|
456
465
|
|
|
457
|
-
var _RelayConnectionInter6 =
|
|
466
|
+
var _RelayConnectionInter6 = RelayConnectionInterface.get(),
|
|
458
467
|
EDGES = _RelayConnectionInter6.EDGES;
|
|
459
468
|
|
|
460
469
|
var edgeIndex = connection.getValue(NEXT_EDGE_INDEX);
|
|
461
|
-
!(typeof edgeIndex === 'number') ? process.env.NODE_ENV !== "production" ?
|
|
462
|
-
|
|
463
|
-
var edgeID = require("./generateRelayClientID")(connection.getDataID(), EDGES, edgeIndex);
|
|
464
|
-
|
|
470
|
+
!(typeof edgeIndex === 'number') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayConnectionHandler: Expected %s to be a number, got `%s`.', NEXT_EDGE_INDEX, edgeIndex) : invariant(false) : void 0;
|
|
471
|
+
var edgeID = generateClientID(connection.getDataID(), EDGES, edgeIndex);
|
|
465
472
|
var connectionEdge = store.create(edgeID, edge.getType());
|
|
466
473
|
connectionEdge.copyFieldsFrom(edge);
|
|
467
474
|
connection.setValue(edgeIndex + 1, NEXT_EDGE_INDEX);
|
|
@@ -476,7 +483,7 @@ function buildConnectionEdge(store, connection, edge) {
|
|
|
476
483
|
|
|
477
484
|
|
|
478
485
|
function mergeEdges(sourceEdges, targetEdges, nodeIDs) {
|
|
479
|
-
var _RelayConnectionInter7 =
|
|
486
|
+
var _RelayConnectionInter7 = RelayConnectionInterface.get(),
|
|
480
487
|
NODE = _RelayConnectionInter7.NODE;
|
|
481
488
|
|
|
482
489
|
for (var ii = 0; ii < sourceEdges.length; ii++) {
|
|
@@ -487,7 +494,7 @@ function mergeEdges(sourceEdges, targetEdges, nodeIDs) {
|
|
|
487
494
|
}
|
|
488
495
|
|
|
489
496
|
var node = edge.getLinkedRecord(NODE);
|
|
490
|
-
var nodeID = node && node.
|
|
497
|
+
var nodeID = node && node.getDataID();
|
|
491
498
|
|
|
492
499
|
if (nodeID) {
|
|
493
500
|
if (nodeIDs.has(nodeID)) {
|
|
@@ -4,12 +4,14 @@
|
|
|
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';
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
15
|
|
|
14
16
|
var CONNECTION_CALLS = {
|
|
15
17
|
after: true,
|