relay-runtime 0.0.0-main-e3b13901 → 0.0.0-main-37527079
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/store/RelayReader.js +24 -13
- package/lib/store/ResolverCache.js +3 -1
- package/lib/store/ResolverFragments.js +13 -2
- package/lib/store/experimental-live-resolvers/LiveResolverCache.js +18 -29
- package/lib/store/experimental-live-resolvers/LiveResolverSuspenseSentinel.js +27 -0
- package/package.json +1 -1
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/RelayReader.js.flow +24 -10
- package/store/ResolverCache.js.flow +16 -8
- package/store/ResolverFragments.js.flow +22 -3
- package/store/experimental-live-resolvers/LiveResolverCache.js.flow +25 -39
- package/store/experimental-live-resolvers/LiveResolverStore.js.flow +0 -1
- package/store/experimental-live-resolvers/LiveResolverSuspenseSentinel.js.flow +28 -0
package/index.js
CHANGED
package/lib/store/RelayReader.js
CHANGED
|
@@ -65,6 +65,7 @@ var _require4 = require('./ResolverCache'),
|
|
|
65
65
|
NoopResolverCache = _require4.NoopResolverCache;
|
|
66
66
|
|
|
67
67
|
var _require5 = require('./ResolverFragments'),
|
|
68
|
+
RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL = _require5.RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL,
|
|
68
69
|
withResolverContext = _require5.withResolverContext;
|
|
69
70
|
|
|
70
71
|
var _require6 = require('./TypeID'),
|
|
@@ -492,11 +493,17 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
492
493
|
// It was already read when checking for input staleness; no need to read it again.
|
|
493
494
|
// Note that the variables like fragmentSeenRecordIDs in the outer closure will have
|
|
494
495
|
// already been set and will still be used in this case.
|
|
495
|
-
return
|
|
496
|
+
return {
|
|
497
|
+
data: snapshot.data,
|
|
498
|
+
isMissingData: snapshot.isMissingData
|
|
499
|
+
};
|
|
496
500
|
}
|
|
497
501
|
|
|
498
502
|
snapshot = read(_this._recordSource, singularReaderSelector, _this._resolverCache);
|
|
499
|
-
return
|
|
503
|
+
return {
|
|
504
|
+
data: snapshot.data,
|
|
505
|
+
isMissingData: snapshot.isMissingData
|
|
506
|
+
};
|
|
500
507
|
};
|
|
501
508
|
|
|
502
509
|
var resolverContext = {
|
|
@@ -521,17 +528,21 @@ var RelayReader = /*#__PURE__*/function () {
|
|
|
521
528
|
// $FlowFixMe[extra-arg]
|
|
522
529
|
args);
|
|
523
530
|
} catch (e) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
field
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
531
|
+
if (e === RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL) {
|
|
532
|
+
resolverResult = undefined;
|
|
533
|
+
} else {
|
|
534
|
+
var _field$path;
|
|
535
|
+
|
|
536
|
+
// `field.path` is typed as nullable while we rollout compiler changes.
|
|
537
|
+
var path = (_field$path = field.path) !== null && _field$path !== void 0 ? _field$path : '[UNKNOWN]';
|
|
538
|
+
resolverError = {
|
|
539
|
+
field: {
|
|
540
|
+
path: path,
|
|
541
|
+
owner: _this._fragmentName
|
|
542
|
+
},
|
|
543
|
+
error: e
|
|
544
|
+
};
|
|
545
|
+
}
|
|
535
546
|
}
|
|
536
547
|
|
|
537
548
|
return {
|
|
@@ -218,7 +218,9 @@ var RecordResolverCache = /*#__PURE__*/function () {
|
|
|
218
218
|
return true;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
var
|
|
221
|
+
var _getDataForResolverFr = getDataForResolverFragment(readerSelector),
|
|
222
|
+
latestValues = _getDataForResolverFr.data;
|
|
223
|
+
|
|
222
224
|
var recycled = recycleNodesInto(originalInputs, latestValues);
|
|
223
225
|
|
|
224
226
|
if (recycled !== originalInputs) {
|
|
@@ -52,10 +52,21 @@ function readFragment(fragmentInput, fragmentKey) {
|
|
|
52
52
|
var fragmentSelector = getSelector(fragmentNode, fragmentKey);
|
|
53
53
|
!(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Expected a selector for the fragment of the resolver ".concat(fragmentNode.name, ", but got null.")) : invariant(false) : void 0;
|
|
54
54
|
!(fragmentSelector.kind === 'SingularReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, "Expected a singular reader selector for the fragment of the resolver ".concat(fragmentNode.name, ", but it was plural.")) : invariant(false) : void 0;
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
var _context$getDataForRe = context.getDataForResolverFragment(fragmentSelector, fragmentKey),
|
|
57
|
+
data = _context$getDataForRe.data,
|
|
58
|
+
isMissingData = _context$getDataForRe.isMissingData;
|
|
59
|
+
|
|
60
|
+
if (isMissingData) {
|
|
61
|
+
throw RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return data;
|
|
56
65
|
}
|
|
57
66
|
|
|
67
|
+
var RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL = {};
|
|
58
68
|
module.exports = {
|
|
59
69
|
readFragment: readFragment,
|
|
60
|
-
withResolverContext: withResolverContext
|
|
70
|
+
withResolverContext: withResolverContext,
|
|
71
|
+
RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL: RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL
|
|
61
72
|
};
|
|
@@ -36,6 +36,9 @@ var _require3 = require('../RelayStoreUtils'),
|
|
|
36
36
|
|
|
37
37
|
var LiveResolverStore = require('./LiveResolverStore');
|
|
38
38
|
|
|
39
|
+
var _require4 = require('./LiveResolverSuspenseSentinel'),
|
|
40
|
+
isSuspenseSentinel = _require4.isSuspenseSentinel;
|
|
41
|
+
|
|
39
42
|
var invariant = require('invariant');
|
|
40
43
|
|
|
41
44
|
var warning = require("fbjs/lib/warning"); // When this experiment gets promoted to stable, these keys will move into
|
|
@@ -45,7 +48,6 @@ var warning = require("fbjs/lib/warning"); // When this experiment gets promoted
|
|
|
45
48
|
var RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY = '__resolverLieStateSubscription';
|
|
46
49
|
var RELAY_RESOLVER_LIVE_STATE_VALUE = '__resolverLiveStateValue';
|
|
47
50
|
var RELAY_RESOLVER_LIVE_STATE_DIRTY = '__resolverLiveStateDirty';
|
|
48
|
-
var LIVE_RESOLVER_SUSPENSE = {};
|
|
49
51
|
/**
|
|
50
52
|
* An experimental fork of store/ResolverCache.js intended to let us experiment
|
|
51
53
|
* with Live Resolvers.
|
|
@@ -89,14 +91,16 @@ var LiveResolverCache = /*#__PURE__*/function () {
|
|
|
89
91
|
var evaluationResult = evaluate();
|
|
90
92
|
|
|
91
93
|
if (field.kind === RELAY_LIVE_RESOLVER) {
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
if (evaluationResult.resolverResult !== undefined) {
|
|
95
|
+
if (process.env.NODE_ENV !== "production") {
|
|
96
|
+
!isLiveStateValue(evaluationResult.resolverResult) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected a @live Relay Resolver to return a value that implements LiveState.') : invariant(false) : void 0;
|
|
97
|
+
}
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
var liveState = // $FlowFixMe[incompatible-type] - casting mixed
|
|
100
|
+
evaluationResult.resolverResult;
|
|
98
101
|
|
|
99
|
-
|
|
102
|
+
this._setLiveStateValue(linkedRecord, linkedID, liveState);
|
|
103
|
+
}
|
|
100
104
|
} else {
|
|
101
105
|
RelayModernRecord.setValue(linkedRecord, RELAY_RESOLVER_VALUE_KEY, evaluationResult.resolverResult);
|
|
102
106
|
}
|
|
@@ -142,7 +146,7 @@ var LiveResolverCache = /*#__PURE__*/function () {
|
|
|
142
146
|
var _liveState = RelayModernRecord.getValue(linkedRecord, RELAY_RESOLVER_LIVE_STATE_VALUE); // Set the new value for this and future reads.
|
|
143
147
|
|
|
144
148
|
|
|
145
|
-
RelayModernRecord.setValue(linkedRecord, RELAY_RESOLVER_VALUE_KEY,
|
|
149
|
+
RelayModernRecord.setValue(linkedRecord, RELAY_RESOLVER_VALUE_KEY, _liveState.read()); // Mark the resolver as clean again.
|
|
146
150
|
|
|
147
151
|
RelayModernRecord.setValue(linkedRecord, RELAY_RESOLVER_LIVE_STATE_DIRTY, false);
|
|
148
152
|
recordSource.set(linkedID, linkedRecord);
|
|
@@ -156,7 +160,7 @@ var LiveResolverCache = /*#__PURE__*/function () {
|
|
|
156
160
|
var error = linkedRecord[RELAY_RESOLVER_ERROR_KEY];
|
|
157
161
|
var suspenseID = null;
|
|
158
162
|
|
|
159
|
-
if (answer
|
|
163
|
+
if (isSuspenseSentinel(answer)) {
|
|
160
164
|
var _linkedID3;
|
|
161
165
|
|
|
162
166
|
suspenseID = (_linkedID3 = linkedID) !== null && _linkedID3 !== void 0 ? _linkedID3 : generateClientID(recordID, storageKey);
|
|
@@ -201,7 +205,7 @@ var LiveResolverCache = /*#__PURE__*/function () {
|
|
|
201
205
|
|
|
202
206
|
RelayModernRecord.setValue(linkedRecord, RELAY_RESOLVER_LIVE_STATE_VALUE, liveState); // Store the current value, for this read, and future cached reads.
|
|
203
207
|
|
|
204
|
-
RelayModernRecord.setValue(linkedRecord, RELAY_RESOLVER_VALUE_KEY,
|
|
208
|
+
RelayModernRecord.setValue(linkedRecord, RELAY_RESOLVER_VALUE_KEY, liveState.read()); // Mark the field as clean.
|
|
205
209
|
|
|
206
210
|
RelayModernRecord.setValue(linkedRecord, RELAY_RESOLVER_LIVE_STATE_DIRTY, false); // Store our our unsubscribe function for future cleanup.
|
|
207
211
|
|
|
@@ -328,7 +332,9 @@ var LiveResolverCache = /*#__PURE__*/function () {
|
|
|
328
332
|
return true;
|
|
329
333
|
}
|
|
330
334
|
|
|
331
|
-
var
|
|
335
|
+
var _getDataForResolverFr = getDataForResolverFragment(readerSelector),
|
|
336
|
+
latestValues = _getDataForResolverFr.data;
|
|
337
|
+
|
|
332
338
|
var recycled = recycleNodesInto(originalInputs, latestValues);
|
|
333
339
|
|
|
334
340
|
if (recycled !== originalInputs) {
|
|
@@ -359,23 +365,6 @@ function isLiveStateValue(v) {
|
|
|
359
365
|
return v != null && typeof v === 'object' && typeof v.read === 'function' && typeof v.subscribe === 'function';
|
|
360
366
|
}
|
|
361
367
|
|
|
362
|
-
function suspenseSentinel() {
|
|
363
|
-
throw LIVE_RESOLVER_SUSPENSE;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
function readLiveStateValue(liveState) {
|
|
367
|
-
try {
|
|
368
|
-
return liveState.read();
|
|
369
|
-
} catch (e) {
|
|
370
|
-
if (e === LIVE_RESOLVER_SUSPENSE) {
|
|
371
|
-
return e;
|
|
372
|
-
} else {
|
|
373
|
-
throw e;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
368
|
module.exports = {
|
|
379
|
-
LiveResolverCache: LiveResolverCache
|
|
380
|
-
suspenseSentinel: suspenseSentinel
|
|
369
|
+
LiveResolverCache: LiveResolverCache
|
|
381
370
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and 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
|
+
* @emails oncall+relay
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var LIVE_RESOLVER_SUSPENSE_SENTINEL = {};
|
|
14
|
+
|
|
15
|
+
function suspenseSentinel() {
|
|
16
|
+
// $FlowFixMe[incompatible-return]
|
|
17
|
+
return LIVE_RESOLVER_SUSPENSE_SENTINEL;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isSuspenseSentinel(value) {
|
|
21
|
+
return value === LIVE_RESOLVER_SUSPENSE_SENTINEL;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
isSuspenseSentinel: isSuspenseSentinel,
|
|
26
|
+
suspenseSentinel: suspenseSentinel
|
|
27
|
+
};
|