react-relay 13.1.1 → 14.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +0 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +0 -2
- package/ReactRelayFragmentContainer.js.flow +7 -6
- package/ReactRelayFragmentMockRenderer.js.flow +0 -2
- package/ReactRelayLocalQueryRenderer.js.flow +1 -3
- package/ReactRelayPaginationContainer.js.flow +13 -10
- package/ReactRelayQueryFetcher.js.flow +10 -11
- package/ReactRelayQueryRenderer.js.flow +15 -16
- package/ReactRelayQueryRendererContext.js.flow +1 -3
- package/ReactRelayRefetchContainer.js.flow +10 -7
- package/ReactRelayTestMocker.js.flow +0 -2
- package/ReactRelayTypes.js.flow +6 -8
- package/RelayContext.js.flow +0 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -4
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +3 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +3 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +2 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +2 -2
- package/assertFragmentMap.js.flow +0 -2
- package/buildReactRelayContainer.js.flow +2 -4
- package/getRootVariablesForFragments.js.flow +0 -2
- package/hooks.js +1 -1
- package/hooks.js.flow +0 -2
- package/index.js +1 -1
- package/index.js.flow +2 -2
- package/isRelayEnvironment.js.flow +0 -2
- package/jest-react/internalAct.js.flow +25 -9
- package/legacy.js +1 -1
- package/legacy.js.flow +0 -2
- package/lib/ReactRelayContainerUtils.js +0 -1
- package/lib/ReactRelayContext.js +0 -1
- package/lib/ReactRelayFragmentContainer.js +10 -9
- package/lib/ReactRelayFragmentMockRenderer.js +0 -1
- package/lib/ReactRelayLocalQueryRenderer.js +0 -1
- package/lib/ReactRelayPaginationContainer.js +14 -11
- package/lib/ReactRelayQueryFetcher.js +2 -2
- package/lib/ReactRelayQueryRenderer.js +2 -4
- package/lib/ReactRelayQueryRendererContext.js +0 -1
- package/lib/ReactRelayRefetchContainer.js +11 -14
- package/lib/ReactRelayTestMocker.js +1 -2
- package/lib/ReactRelayTypes.js +0 -1
- package/lib/RelayContext.js +0 -1
- package/lib/assertFragmentMap.js +0 -1
- package/lib/buildReactRelayContainer.js +1 -2
- package/lib/getRootVariablesForFragments.js +1 -2
- package/lib/hooks.js +0 -1
- package/lib/index.js +3 -1
- package/lib/isRelayEnvironment.js +0 -1
- package/lib/jest-react/internalAct.js +24 -4
- package/lib/legacy.js +0 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +0 -1
- package/lib/readContext.js +2 -2
- package/lib/relay-hooks/EntryPointContainer.react.js +0 -1
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -1
- package/lib/relay-hooks/FragmentResource.js +68 -29
- package/lib/relay-hooks/HooksImplementation.js +29 -0
- package/lib/relay-hooks/InternalLogger.js +0 -1
- package/lib/relay-hooks/LRUCache.js +0 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -1
- package/lib/relay-hooks/MatchContainer.js +2 -2
- package/lib/relay-hooks/ProfilerContext.js +0 -1
- package/lib/relay-hooks/QueryResource.js +5 -168
- package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -1
- package/lib/relay-hooks/SuspenseResource.js +1 -2
- package/lib/relay-hooks/loadQuery.js +1 -1
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -13
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -1
- package/lib/relay-hooks/react-cache/RelayReactCache.js +36 -0
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +344 -0
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +239 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +598 -0
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +50 -0
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +55 -0
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +150 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +124 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +367 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +45 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +4 -3
- package/lib/relay-hooks/useClientQuery.js +33 -0
- package/lib/relay-hooks/useEntryPointLoader.js +1 -2
- package/lib/relay-hooks/useFetchTrackingRef.js +0 -1
- package/lib/relay-hooks/useFragment.js +15 -2
- package/lib/relay-hooks/useFragmentNode.js +0 -1
- package/lib/relay-hooks/useIsMountedRef.js +0 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +4 -2
- package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -1
- package/lib/relay-hooks/useLoadMoreFunction.js +1 -2
- package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -1
- package/lib/relay-hooks/useMemoVariables.js +0 -1
- package/lib/relay-hooks/useMutation.js +5 -7
- package/lib/relay-hooks/usePaginationFragment.js +15 -3
- package/lib/relay-hooks/usePreloadedQuery.js +4 -2
- package/lib/relay-hooks/useQueryLoader.js +1 -2
- package/lib/relay-hooks/useRefetchableFragment.js +14 -2
- package/lib/relay-hooks/useRefetchableFragmentNode.js +1 -2
- package/lib/relay-hooks/useRelayEnvironment.js +0 -1
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -1
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -1
- package/lib/relay-hooks/useSubscription.js +0 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +0 -2
- package/package.json +3 -3
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/readContext.js.flow +1 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +2 -4
- package/relay-hooks/EntryPointTypes.flow.js.flow +30 -32
- package/relay-hooks/FragmentResource.js.flow +80 -37
- package/relay-hooks/HooksImplementation.js.flow +43 -0
- package/relay-hooks/InternalLogger.js.flow +0 -2
- package/relay-hooks/LRUCache.js.flow +0 -2
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -6
- package/relay-hooks/MatchContainer.js.flow +11 -6
- package/relay-hooks/ProfilerContext.js.flow +0 -2
- package/relay-hooks/QueryResource.js.flow +12 -209
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -4
- package/relay-hooks/SuspenseResource.js.flow +0 -2
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +2 -2
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +4 -6
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +0 -2
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +4 -6
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +0 -2
- package/relay-hooks/__flowtests__/utils.js.flow +8 -10
- package/relay-hooks/loadQuery.js.flow +2 -1
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +11 -20
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +0 -2
- package/relay-hooks/react-cache/RelayReactCache.js.flow +40 -0
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +430 -0
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +599 -0
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +72 -0
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +70 -0
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +171 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +151 -0
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +595 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +4 -6
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +6 -8
- package/relay-hooks/useFetchTrackingRef.js.flow +2 -4
- package/relay-hooks/useFragment.js.flow +17 -12
- package/relay-hooks/useFragmentNode.js.flow +2 -4
- package/relay-hooks/useIsMountedRef.js.flow +1 -3
- package/relay-hooks/useLazyLoadQuery.js.flow +17 -5
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -4
- package/relay-hooks/useLoadMoreFunction.js.flow +6 -8
- package/relay-hooks/useMemoOperationDescriptor.js.flow +0 -2
- package/relay-hooks/useMemoVariables.js.flow +0 -2
- package/relay-hooks/useMutation.js.flow +5 -7
- package/relay-hooks/usePaginationFragment.js.flow +44 -19
- package/relay-hooks/usePreloadedQuery.js.flow +14 -5
- package/relay-hooks/useQueryLoader.js.flow +4 -6
- package/relay-hooks/useRefetchableFragment.js.flow +32 -3
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -25
- package/relay-hooks/useRelayEnvironment.js.flow +0 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +0 -2
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +0 -2
- package/relay-hooks/useSubscription.js.flow +14 -10
@@ -7,10 +7,9 @@
|
|
7
7
|
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
10
|
'use strict';
|
12
11
|
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
13
|
|
15
14
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
16
15
|
|
@@ -24,6 +23,8 @@ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inh
|
|
24
23
|
|
25
24
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
26
25
|
|
26
|
+
var _excluded = ["componentRef", "__relayContext", "__rootIsQueryRenderer"];
|
27
|
+
|
27
28
|
var buildReactRelayContainer = require('./buildReactRelayContainer');
|
28
29
|
|
29
30
|
var getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
@@ -59,10 +60,10 @@ var warning = require("fbjs/lib/warning");
|
|
59
60
|
* updates.
|
60
61
|
*/
|
61
62
|
function createContainerWithFragments(Component, fragments, taggedNode) {
|
62
|
-
var _class
|
63
|
+
var _class;
|
63
64
|
|
64
65
|
var containerName = getContainerName(Component);
|
65
|
-
return
|
66
|
+
return _class = /*#__PURE__*/function (_React$Component) {
|
66
67
|
(0, _inheritsLoose2["default"])(_class, _React$Component);
|
67
68
|
|
68
69
|
function _class(props) {
|
@@ -113,11 +114,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
113
114
|
var query = getRequest(taggedNode);
|
114
115
|
var operation = createOperationDescriptor(query, fetchVariables, cacheConfig); // TODO: T26288752 find a better way
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
_this.state.localVariables = fetchVariables;
|
119
|
-
/* eslint-enable lint/react-state-props-mutation */
|
120
|
-
// Cancel any previously running refetch.
|
117
|
+
_this.state.localVariables = fetchVariables; // Cancel any previously running refetch.
|
121
118
|
|
122
119
|
_this._refetchSubscription && _this._refetchSubscription.unsubscribe(); // Declare refetchSubscription before assigning it in .start(), since
|
123
120
|
// synchronous completion may call callbacks .subscribe() returns.
|
@@ -304,14 +301,14 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
304
301
|
var keys = Object.keys(nextProps);
|
305
302
|
|
306
303
|
for (var ii = 0; ii < keys.length; ii++) {
|
307
|
-
var
|
304
|
+
var key = keys[ii];
|
308
305
|
|
309
|
-
if (
|
306
|
+
if (key === '__relayContext') {
|
310
307
|
if (this.state.prevPropsContext.environment !== nextState.prevPropsContext.environment) {
|
311
308
|
return true;
|
312
309
|
}
|
313
310
|
} else {
|
314
|
-
if (!fragments.hasOwnProperty(
|
311
|
+
if (!fragments.hasOwnProperty(key) && !isScalarAndEqual(nextProps[key], this.props[key])) {
|
315
312
|
return true;
|
316
313
|
}
|
317
314
|
}
|
@@ -373,7 +370,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
373
370
|
componentRef = _this$props.componentRef,
|
374
371
|
__relayContext = _this$props.__relayContext,
|
375
372
|
__rootIsQueryRenderer = _this$props.__rootIsQueryRenderer,
|
376
|
-
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props,
|
373
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
|
377
374
|
var _this$state3 = this.state,
|
378
375
|
relayProp = _this$state3.relayProp,
|
379
376
|
contextForChildren = _this$state3.contextForChildren;
|
@@ -386,7 +383,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
|
|
386
383
|
};
|
387
384
|
|
388
385
|
return _class;
|
389
|
-
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName),
|
386
|
+
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _class;
|
390
387
|
}
|
391
388
|
|
392
389
|
function getRelayProp(environment, refetch) {
|
@@ -7,10 +7,9 @@
|
|
7
7
|
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
10
|
'use strict';
|
12
11
|
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
13
|
|
15
14
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
15
|
|
package/lib/ReactRelayTypes.js
CHANGED
package/lib/RelayContext.js
CHANGED
package/lib/assertFragmentMap.js
CHANGED
@@ -7,10 +7,9 @@
|
|
7
7
|
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
10
|
'use strict';
|
12
11
|
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
13
|
|
15
14
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
16
15
|
|
@@ -7,10 +7,9 @@
|
|
7
7
|
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
10
|
'use strict';
|
12
11
|
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
13
|
|
15
14
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
15
|
|
package/lib/hooks.js
CHANGED
package/lib/index.js
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
10
|
'use strict';
|
12
11
|
|
13
12
|
var ReactRelayContext = require('./ReactRelayContext');
|
@@ -31,6 +30,8 @@ var _require = require('./relay-hooks/loadQuery'),
|
|
31
30
|
|
32
31
|
var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
|
33
32
|
|
33
|
+
var useClientQuery = require('./relay-hooks/useClientQuery');
|
34
|
+
|
34
35
|
var useEntryPointLoader = require('./relay-hooks/useEntryPointLoader');
|
35
36
|
|
36
37
|
var useFragment = require('./relay-hooks/useFragment');
|
@@ -83,6 +84,7 @@ module.exports = {
|
|
83
84
|
fetchQuery: RelayRuntime.fetchQuery,
|
84
85
|
loadQuery: loadQuery,
|
85
86
|
loadEntryPoint: loadEntryPoint,
|
87
|
+
useClientQuery: useClientQuery,
|
86
88
|
useFragment: useFragment,
|
87
89
|
useLazyLoadQuery: useLazyLoadQuery,
|
88
90
|
useEntryPointLoader: useEntryPointLoader,
|
@@ -36,10 +36,21 @@ function act(scope) {
|
|
36
36
|
throw Error("This version of `act` requires Jest's timer mocks " + '(i.e. jest.useFakeTimers).');
|
37
37
|
}
|
38
38
|
|
39
|
+
var previousIsActEnvironment = global.IS_REACT_ACT_ENVIRONMENT;
|
39
40
|
var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
40
41
|
actingUpdatesScopeDepth++;
|
41
42
|
|
43
|
+
if (process.env.NODE_ENV !== "production" && actingUpdatesScopeDepth === 1) {
|
44
|
+
// Because this is not the "real" `act`, we set this to `false` so React
|
45
|
+
// knows not to fire `act` warnings.
|
46
|
+
global.IS_REACT_ACT_ENVIRONMENT = false;
|
47
|
+
}
|
48
|
+
|
42
49
|
var unwind = function unwind() {
|
50
|
+
if (process.env.NODE_ENV !== "production" && actingUpdatesScopeDepth === 1) {
|
51
|
+
global.IS_REACT_ACT_ENVIRONMENT = previousIsActEnvironment;
|
52
|
+
}
|
53
|
+
|
43
54
|
actingUpdatesScopeDepth--;
|
44
55
|
|
45
56
|
if (process.env.NODE_ENV !== "production") {
|
@@ -55,15 +66,16 @@ function act(scope) {
|
|
55
66
|
|
56
67
|
|
57
68
|
try {
|
58
|
-
var
|
69
|
+
var result = scope();
|
59
70
|
|
60
|
-
if (typeof
|
71
|
+
if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
|
72
|
+
var thenableResult = result;
|
61
73
|
return {
|
62
74
|
then: function then(resolve, reject) {
|
63
|
-
|
75
|
+
thenableResult.then(function (returnValue) {
|
64
76
|
flushActWork(function () {
|
65
77
|
unwind();
|
66
|
-
resolve();
|
78
|
+
resolve(returnValue);
|
67
79
|
}, function (error) {
|
68
80
|
unwind();
|
69
81
|
reject(error);
|
@@ -75,6 +87,8 @@ function act(scope) {
|
|
75
87
|
}
|
76
88
|
};
|
77
89
|
} else {
|
90
|
+
var returnValue = result;
|
91
|
+
|
78
92
|
try {
|
79
93
|
// TODO: Let's not support non-async scopes at all in our tests. Need to
|
80
94
|
// migrate existing tests.
|
@@ -83,6 +97,12 @@ function act(scope) {
|
|
83
97
|
do {
|
84
98
|
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
|
85
99
|
} while (didFlushWork);
|
100
|
+
|
101
|
+
return {
|
102
|
+
then: function then(resolve, reject) {
|
103
|
+
resolve(returnValue);
|
104
|
+
}
|
105
|
+
};
|
86
106
|
} finally {
|
87
107
|
unwind();
|
88
108
|
}
|
package/lib/legacy.js
CHANGED
package/lib/readContext.js
CHANGED
@@ -7,10 +7,10 @@
|
|
7
7
|
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
10
|
'use strict';
|
12
11
|
|
13
|
-
var React = require('react');
|
12
|
+
var React = require('react'); // $FlowFixMe[incompatible-use]
|
13
|
+
|
14
14
|
|
15
15
|
var _React$__SECRET_INTER =
|
16
16
|
/* $FlowFixMe[prop-missing] Flow doesn't know about React's internals for
|
@@ -8,10 +8,9 @@
|
|
8
8
|
* @emails oncall+relay
|
9
9
|
* @format
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
11
|
'use strict';
|
13
12
|
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
14
|
|
16
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
16
|
|
@@ -38,9 +37,9 @@ var _require2 = require('relay-runtime'),
|
|
38
37
|
getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
|
39
38
|
getSelector = _require2.getSelector,
|
40
39
|
getVariablesFromFragment = _require2.getVariablesFromFragment,
|
40
|
+
handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors,
|
41
41
|
isPromise = _require2.isPromise,
|
42
|
-
recycleNodesInto = _require2.recycleNodesInto
|
43
|
-
reportMissingRequiredFields = _require2.reportMissingRequiredFields;
|
42
|
+
recycleNodesInto = _require2.recycleNodesInto;
|
44
43
|
|
45
44
|
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
46
45
|
// TODO: Fix to not rely on LRU. If the number of active fragments exceeds this
|
@@ -74,6 +73,16 @@ function hasMissingClientEdges(snapshot) {
|
|
74
73
|
return ((_snapshot$missingClie = (_snapshot$missingClie2 = snapshot.missingClientEdges) === null || _snapshot$missingClie2 === void 0 ? void 0 : _snapshot$missingClie2.length) !== null && _snapshot$missingClie !== void 0 ? _snapshot$missingClie : 0) > 0;
|
75
74
|
}
|
76
75
|
|
76
|
+
function missingLiveResolverFields(snapshot) {
|
77
|
+
if (Array.isArray(snapshot)) {
|
78
|
+
return snapshot.map(function (s) {
|
79
|
+
return s.missingLiveResolverFields;
|
80
|
+
}).filter(Boolean).flat();
|
81
|
+
}
|
82
|
+
|
83
|
+
return snapshot.missingLiveResolverFields;
|
84
|
+
}
|
85
|
+
|
77
86
|
function singularOrPluralForEach(snapshot, f) {
|
78
87
|
if (Array.isArray(snapshot)) {
|
79
88
|
snapshot.forEach(f);
|
@@ -126,7 +135,8 @@ var ClientEdgeQueryResultsCache = /*#__PURE__*/function () {
|
|
126
135
|
return (_this$_cache$get$ = (_this$_cache$get = this._cache.get(fragmentIdentifier)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get[0]) !== null && _this$_cache$get$ !== void 0 ? _this$_cache$get$ : undefined;
|
127
136
|
};
|
128
137
|
|
129
|
-
_proto.recordQueryResults = function recordQueryResults(fragmentIdentifier, value
|
138
|
+
_proto.recordQueryResults = function recordQueryResults(fragmentIdentifier, value // may be mutated after being passed here
|
139
|
+
) {
|
130
140
|
var _this = this;
|
131
141
|
|
132
142
|
var existing = this._cache.get(fragmentIdentifier);
|
@@ -210,7 +220,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
210
220
|
_proto2.readWithIdentifier = function readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName, fragmentKey) {
|
211
221
|
var _this3 = this;
|
212
222
|
|
213
|
-
var _fragmentNode$metadat,
|
223
|
+
var _fragmentNode$metadat, _fragmentNode$metadat2, _missingLiveResolverF2, _missingLiveResolverF3;
|
214
224
|
|
215
225
|
var environment = this._environment; // If fragmentRef is null or undefined, pass it directly through.
|
216
226
|
// This is a convenience when consuming fragments via a HOC API, when the
|
@@ -248,6 +258,8 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
248
258
|
var cachedValue = this._cache.get(fragmentIdentifier);
|
249
259
|
|
250
260
|
if (cachedValue != null) {
|
261
|
+
var _missingLiveResolverF;
|
262
|
+
|
251
263
|
if (cachedValue.kind === 'pending' && isPromise(cachedValue.promise)) {
|
252
264
|
environment.__log({
|
253
265
|
name: 'suspense.fragment',
|
@@ -262,8 +274,8 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
262
274
|
throw cachedValue.promise;
|
263
275
|
}
|
264
276
|
|
265
|
-
if (cachedValue.kind === 'done' && cachedValue.result.snapshot) {
|
266
|
-
this.
|
277
|
+
if (cachedValue.kind === 'done' && cachedValue.result.snapshot && !((_missingLiveResolverF = missingLiveResolverFields(cachedValue.result.snapshot)) !== null && _missingLiveResolverF !== void 0 && _missingLiveResolverF.length)) {
|
278
|
+
this._handlePotentialSnapshotErrorsInSnapshot(cachedValue.result.snapshot);
|
267
279
|
|
268
280
|
return cachedValue.result;
|
269
281
|
}
|
@@ -279,7 +291,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
279
291
|
var fragmentResult = getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
|
280
292
|
|
281
293
|
if (!fragmentResult.isMissingData) {
|
282
|
-
this.
|
294
|
+
this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
|
283
295
|
|
284
296
|
this._cache.set(fragmentIdentifier, {
|
285
297
|
kind: 'done',
|
@@ -300,7 +312,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
300
312
|
|
301
313
|
var clientEdgeRequests = null;
|
302
314
|
|
303
|
-
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && hasMissingClientEdges(snapshot)) {
|
315
|
+
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && ((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true && hasMissingClientEdges(snapshot)) {
|
304
316
|
clientEdgeRequests = [];
|
305
317
|
var queryResource = getQueryResourceForEnvironment(this._environment);
|
306
318
|
var queryResults = [];
|
@@ -328,14 +340,12 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
328
340
|
this._clientEdgeQueryResultsCache.recordQueryResults(fragmentIdentifier, queryResults);
|
329
341
|
}
|
330
342
|
|
331
|
-
var clientEdgePromises =
|
343
|
+
var clientEdgePromises = [];
|
332
344
|
|
333
345
|
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && clientEdgeRequests) {
|
334
346
|
clientEdgePromises = clientEdgeRequests.map(function (request) {
|
335
347
|
return getPromiseForActiveRequest(_this3._environment, request);
|
336
|
-
}).filter(
|
337
|
-
return p != null;
|
338
|
-
});
|
348
|
+
}).filter(Boolean);
|
339
349
|
} // Finally look for operations in flight for our parent query:
|
340
350
|
|
341
351
|
|
@@ -345,8 +355,15 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
345
355
|
|
346
356
|
var parentQueryPromiseResultPromise = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.promise; // for refinement
|
347
357
|
|
348
|
-
|
349
|
-
var
|
358
|
+
var missingResolverFieldPromises = (_missingLiveResolverF2 = (_missingLiveResolverF3 = missingLiveResolverFields(snapshot)) === null || _missingLiveResolverF3 === void 0 ? void 0 : _missingLiveResolverF3.map(function (_ref2) {
|
359
|
+
var liveStateID = _ref2.liveStateID;
|
360
|
+
var store = environment.getStore(); // $FlowFixMe[prop-missing] This is expected to be a LiveResolverStore
|
361
|
+
|
362
|
+
return store.getLiveResolverPromise(liveStateID);
|
363
|
+
})) !== null && _missingLiveResolverF2 !== void 0 ? _missingLiveResolverF2 : [];
|
364
|
+
|
365
|
+
if (clientEdgePromises.length || missingResolverFieldPromises.length || isPromise(parentQueryPromiseResultPromise)) {
|
366
|
+
var _parentQueryPromiseRe, _clientEdgeRequests2;
|
350
367
|
|
351
368
|
environment.__log({
|
352
369
|
name: 'suspense.fragment',
|
@@ -355,13 +372,37 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
355
372
|
isRelayHooks: true,
|
356
373
|
isPromiseCached: false,
|
357
374
|
isMissingData: fragmentResult.isMissingData,
|
375
|
+
// TODO! Attach information here about missing live resolver fields
|
358
376
|
pendingOperations: [].concat((0, _toConsumableArray2["default"])((_parentQueryPromiseRe = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.pendingOperations) !== null && _parentQueryPromiseRe !== void 0 ? _parentQueryPromiseRe : []), (0, _toConsumableArray2["default"])((_clientEdgeRequests2 = clientEdgeRequests) !== null && _clientEdgeRequests2 !== void 0 ? _clientEdgeRequests2 : []))
|
359
377
|
});
|
360
378
|
|
361
|
-
|
379
|
+
var promises = [];
|
380
|
+
|
381
|
+
if (clientEdgePromises.length > 0) {
|
382
|
+
promises = promises.concat(clientEdgePromises);
|
383
|
+
}
|
384
|
+
|
385
|
+
if (missingResolverFieldPromises.length > 0) {
|
386
|
+
promises = promises.concat(missingResolverFieldPromises);
|
387
|
+
}
|
388
|
+
|
389
|
+
if (promises.length > 0) {
|
390
|
+
if (parentQueryPromiseResultPromise) {
|
391
|
+
promises.push(parentQueryPromiseResultPromise);
|
392
|
+
}
|
393
|
+
|
394
|
+
throw Promise.all(promises);
|
395
|
+
} // Note: we are re-throwing the `parentQueryPromiseResultPromise` here,
|
396
|
+
// because some of our suspense-related code is relying on the instance equality
|
397
|
+
// of thrown promises. See FragmentResource-test.js
|
398
|
+
|
399
|
+
|
400
|
+
if (parentQueryPromiseResultPromise) {
|
401
|
+
throw parentQueryPromiseResultPromise;
|
402
|
+
}
|
362
403
|
}
|
363
404
|
|
364
|
-
this.
|
405
|
+
this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
|
365
406
|
|
366
407
|
return getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
|
367
408
|
};
|
@@ -383,27 +424,23 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
383
424
|
};
|
384
425
|
};
|
385
426
|
|
386
|
-
_proto2.
|
427
|
+
_proto2._handlePotentialSnapshotErrorsInSnapshot = function _handlePotentialSnapshotErrorsInSnapshot(snapshot) {
|
387
428
|
var _this4 = this;
|
388
429
|
|
389
430
|
if (Array.isArray(snapshot)) {
|
390
431
|
snapshot.forEach(function (s) {
|
391
|
-
|
392
|
-
reportMissingRequiredFields(_this4._environment, s.missingRequiredFields);
|
393
|
-
}
|
432
|
+
handlePotentialSnapshotErrors(_this4._environment, s.missingRequiredFields, s.relayResolverErrors);
|
394
433
|
});
|
395
434
|
} else {
|
396
|
-
|
397
|
-
reportMissingRequiredFields(this._environment, snapshot.missingRequiredFields);
|
398
|
-
}
|
435
|
+
handlePotentialSnapshotErrors(this._environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors);
|
399
436
|
}
|
400
437
|
};
|
401
438
|
|
402
439
|
_proto2.readSpec = function readSpec(fragmentNodes, fragmentRefs, componentDisplayName) {
|
403
440
|
var result = {};
|
404
441
|
|
405
|
-
for (var
|
406
|
-
result[
|
442
|
+
for (var key in fragmentNodes) {
|
443
|
+
result[key] = this.read(fragmentNodes[key], fragmentRefs[key], componentDisplayName, key);
|
407
444
|
}
|
408
445
|
|
409
446
|
return result;
|
@@ -467,7 +504,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
467
504
|
|
468
505
|
var clientEdgeQueryResults = (_this$_clientEdgeQuer = (_this$_clientEdgeQuer2 = this._clientEdgeQueryResultsCache) === null || _this$_clientEdgeQuer2 === void 0 ? void 0 : _this$_clientEdgeQuer2.get(cacheKey)) !== null && _this$_clientEdgeQuer !== void 0 ? _this$_clientEdgeQuer : undefined;
|
469
506
|
|
470
|
-
if (clientEdgeQueryResults
|
507
|
+
if (clientEdgeQueryResults !== null && clientEdgeQueryResults !== void 0 && clientEdgeQueryResults.length) {
|
471
508
|
var queryResource = getQueryResourceForEnvironment(this._environment);
|
472
509
|
clientEdgeQueryResults.forEach(function (queryResult) {
|
473
510
|
disposables.push(queryResource.retain(queryResult));
|
@@ -557,9 +594,11 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
557
594
|
data: updatedData,
|
558
595
|
isMissingData: currentSnapshot.isMissingData,
|
559
596
|
missingClientEdges: currentSnapshot.missingClientEdges,
|
597
|
+
missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
|
560
598
|
seenRecords: currentSnapshot.seenRecords,
|
561
599
|
selector: currentSnapshot.selector,
|
562
|
-
missingRequiredFields: currentSnapshot.missingRequiredFields
|
600
|
+
missingRequiredFields: currentSnapshot.missingRequiredFields,
|
601
|
+
relayResolverErrors: currentSnapshot.relayResolverErrors
|
563
602
|
};
|
564
603
|
|
565
604
|
if (updatedData !== renderData) {
|
@@ -0,0 +1,29 @@
|
|
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
|
+
* @emails oncall+relay
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
|
13
|
+
var warning = require("fbjs/lib/warning");
|
14
|
+
|
15
|
+
var implementation = null;
|
16
|
+
|
17
|
+
function inject(impl) {
|
18
|
+
process.env.NODE_ENV !== "production" ? warning(implementation !== null, 'Relay HooksImplementation was injected twice.') : void 0;
|
19
|
+
implementation = impl;
|
20
|
+
}
|
21
|
+
|
22
|
+
function get() {
|
23
|
+
return implementation;
|
24
|
+
}
|
25
|
+
|
26
|
+
module.exports = {
|
27
|
+
inject: inject,
|
28
|
+
get: get
|
29
|
+
};
|
@@ -8,10 +8,9 @@
|
|
8
8
|
*
|
9
9
|
* @format
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
11
|
'use strict';
|
13
12
|
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
14
|
|
16
15
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
17
16
|
|
@@ -137,6 +136,7 @@ function MatchContainer(_ref2) {
|
|
137
136
|
|
138
137
|
if (LoadedContainer != null && fragmentProps != null) {
|
139
138
|
// $FlowFixMe[incompatible-type]
|
139
|
+
// $FlowFixMe[cannot-spread-indexer]
|
140
140
|
return /*#__PURE__*/React.createElement(LoadedContainer, (0, _extends2["default"])({}, props, fragmentProps));
|
141
141
|
} else {
|
142
142
|
return fallback !== null && fallback !== void 0 ? fallback : null;
|
@@ -8,7 +8,6 @@
|
|
8
8
|
*
|
9
9
|
* @format
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
11
|
// This contextual profiler can be used to wrap a react sub-tree. It will bind
|
13
12
|
// the RelayProfiler during the render phase of these components. Allows
|
14
13
|
// collecting metrics for a specific part of your application.
|