react-relay 14.1.0 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +20 -10
- package/ReactRelayQueryRenderer.js.flow +15 -11
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +2 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +10 -6
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +0 -11
- package/lib/ReactRelayContext.js +1 -12
- package/lib/ReactRelayFragmentContainer.js +23 -122
- package/lib/ReactRelayFragmentMockRenderer.js +0 -12
- package/lib/ReactRelayLocalQueryRenderer.js +12 -41
- package/lib/ReactRelayPaginationContainer.js +45 -341
- package/lib/ReactRelayQueryFetcher.js +36 -111
- package/lib/ReactRelayQueryRenderer.js +29 -137
- package/lib/ReactRelayQueryRendererContext.js +0 -10
- package/lib/ReactRelayRefetchContainer.js +33 -166
- package/lib/ReactRelayTestMocker.js +18 -128
- package/lib/ReactRelayTypes.js +0 -9
- package/lib/RelayContext.js +0 -23
- package/lib/assertFragmentMap.js +0 -16
- package/lib/buildReactRelayContainer.js +7 -41
- package/lib/getRootVariablesForFragments.js +2 -19
- package/lib/hooks.js +3 -30
- package/lib/index.js +3 -39
- package/lib/isRelayEnvironment.js +1 -16
- package/lib/jest-react/enqueueTask.js +1 -25
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +2 -51
- package/lib/legacy.js +0 -20
- package/lib/multi-actor/ActorChange.js +0 -14
- package/lib/multi-actor/index.js +0 -10
- package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
- package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
- package/lib/relay-hooks/FragmentResource.js +130 -280
- package/lib/relay-hooks/HooksImplementation.js +0 -14
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -39
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
- package/lib/relay-hooks/MatchContainer.js +9 -111
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -14
- package/lib/relay-hooks/QueryResource.js +14 -149
- package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
- package/lib/relay-hooks/SuspenseResource.js +2 -59
- package/lib/relay-hooks/loadEntryPoint.js +10 -45
- package/lib/relay-hooks/loadQuery.js +29 -169
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
- package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
- package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
- package/lib/relay-hooks/useClientQuery.js +0 -21
- package/lib/relay-hooks/useEntryPointLoader.js +12 -100
- package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
- package/lib/relay-hooks/useFragment.js +5 -32
- package/lib/relay-hooks/useFragmentNode.js +14 -55
- package/lib/relay-hooks/useIsMountedRef.js +2 -14
- package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
- package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
- package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
- package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
- package/lib/relay-hooks/useMemoVariables.js +8 -43
- package/lib/relay-hooks/useMutation.js +6 -34
- package/lib/relay-hooks/usePaginationFragment.js +49 -89
- package/lib/relay-hooks/usePreloadedQuery.js +10 -54
- package/lib/relay-hooks/useQueryLoader.js +18 -116
- package/lib/relay-hooks/useRefetchableFragment.js +4 -30
- package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
- package/lib/relay-hooks/useRelayEnvironment.js +2 -16
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
- package/lib/relay-hooks/useSubscription.js +3 -22
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
- package/package.json +2 -2
- 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/relay-hooks/EntryPointContainer.react.js.flow +6 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
- package/relay-hooks/FragmentResource.js.flow +148 -34
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +15 -8
- package/relay-hooks/loadQuery.js.flow +32 -8
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
- package/relay-hooks/useClientQuery.js.flow +3 -3
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +7 -6
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +30 -13
- package/relay-hooks/usePaginationFragment.js.flow +55 -54
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +78 -21
- package/relay-hooks/useRefetchableFragment.js.flow +65 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
@@ -1,35 +1,16 @@
|
|
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
1
|
'use strict';
|
12
2
|
|
13
3
|
var useMemoVariables = require('./useMemoVariables');
|
14
|
-
|
15
4
|
var React = require('react');
|
16
|
-
|
17
5
|
var _require = require('relay-runtime'),
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
createOperationDescriptor = _require.createOperationDescriptor,
|
7
|
+
getRequest = _require.getRequest;
|
21
8
|
var useMemo = React.useMemo;
|
22
|
-
|
23
9
|
function useMemoOperationDescriptor(gqlQuery, variables, cacheConfig) {
|
24
|
-
var
|
25
|
-
|
26
|
-
|
27
|
-
var _useMemoVariables2 = useMemoVariables(cacheConfig || {}),
|
28
|
-
memoCacheConfig = _useMemoVariables2[0];
|
29
|
-
|
10
|
+
var memoVariables = useMemoVariables(variables);
|
11
|
+
var memoCacheConfig = useMemoVariables(cacheConfig || {});
|
30
12
|
return useMemo(function () {
|
31
13
|
return createOperationDescriptor(getRequest(gqlQuery), memoVariables, memoCacheConfig);
|
32
14
|
}, [gqlQuery, memoVariables, memoCacheConfig]);
|
33
15
|
}
|
34
|
-
|
35
16
|
module.exports = useMemoOperationDescriptor;
|
@@ -1,52 +1,17 @@
|
|
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
1
|
'use strict';
|
12
2
|
|
13
3
|
var areEqual = require("fbjs/lib/areEqual");
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
var useMemo = React.useMemo,
|
18
|
-
useRef = React.useRef,
|
19
|
-
useState = React.useState;
|
20
|
-
|
4
|
+
var _require = require('react'),
|
5
|
+
useState = _require.useState;
|
21
6
|
function useMemoVariables(variables) {
|
22
|
-
var _variablesChangedGene2;
|
23
|
-
|
24
|
-
// The value of this ref is a counter that should be incremented when
|
25
|
-
// variables change. This allows us to use the counter as a
|
26
|
-
// memoization value to indicate if the computation for useMemo
|
27
|
-
// should be re-executed.
|
28
|
-
var variablesChangedGenerationRef = useRef(0); // We mirror the variables to check if they have changed between renders
|
29
|
-
|
30
7
|
var _useState = useState(variables),
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
if (variablesChanged) {
|
37
|
-
var _variablesChangedGene;
|
38
|
-
|
39
|
-
variablesChangedGenerationRef.current = ((_variablesChangedGene = variablesChangedGenerationRef.current) !== null && _variablesChangedGene !== void 0 ? _variablesChangedGene : 0) + 1;
|
8
|
+
mirroredVariables = _useState[0],
|
9
|
+
setMirroredVariables = _useState[1];
|
10
|
+
if (areEqual(variables, mirroredVariables)) {
|
11
|
+
return mirroredVariables;
|
12
|
+
} else {
|
40
13
|
setMirroredVariables(variables);
|
41
|
-
} // NOTE: We disable react-hooks-deps warning because we explicitly
|
42
|
-
// don't want to memoize on object identity
|
43
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
44
|
-
|
45
|
-
|
46
|
-
var memoVariables = useMemo(function () {
|
47
14
|
return variables;
|
48
|
-
}
|
49
|
-
return [memoVariables, (_variablesChangedGene2 = variablesChangedGenerationRef.current) !== null && _variablesChangedGene2 !== void 0 ? _variablesChangedGene2 : 0];
|
15
|
+
}
|
50
16
|
}
|
51
|
-
|
52
17
|
module.exports = useMemoVariables;
|
@@ -1,33 +1,16 @@
|
|
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
1
|
'use strict';
|
12
2
|
|
13
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
|
17
5
|
var useIsMountedRef = require('./useIsMountedRef');
|
18
|
-
|
19
6
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
20
|
-
|
21
7
|
var React = require('react');
|
22
|
-
|
23
8
|
var _require = require('relay-runtime'),
|
24
|
-
|
25
|
-
|
9
|
+
defaultCommitMutation = _require.commitMutation;
|
26
10
|
var useState = React.useState,
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
11
|
+
useEffect = React.useEffect,
|
12
|
+
useRef = React.useRef,
|
13
|
+
useCallback = React.useCallback;
|
31
14
|
function useMutation(mutation) {
|
32
15
|
var commitMutationFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCommitMutation;
|
33
16
|
var environment = useRelayEnvironment();
|
@@ -35,15 +18,12 @@ function useMutation(mutation) {
|
|
35
18
|
var environmentRef = useRef(environment);
|
36
19
|
var mutationRef = useRef(mutation);
|
37
20
|
var inFlightMutationsRef = useRef(new Set());
|
38
|
-
|
39
21
|
var _useState = useState(false),
|
40
|
-
|
41
|
-
|
42
|
-
|
22
|
+
isMutationInFlight = _useState[0],
|
23
|
+
setMutationInFlight = _useState[1];
|
43
24
|
var cleanup = useCallback(function (disposable) {
|
44
25
|
if (environmentRef.current === environment && mutationRef.current === mutation) {
|
45
26
|
inFlightMutationsRef.current["delete"](disposable);
|
46
|
-
|
47
27
|
if (isMountedRef.current) {
|
48
28
|
setMutationInFlight(inFlightMutationsRef.current.size > 0);
|
49
29
|
}
|
@@ -52,11 +32,9 @@ function useMutation(mutation) {
|
|
52
32
|
useEffect(function () {
|
53
33
|
if (environmentRef.current !== environment || mutationRef.current !== mutation) {
|
54
34
|
inFlightMutationsRef.current = new Set();
|
55
|
-
|
56
35
|
if (isMountedRef.current) {
|
57
36
|
setMutationInFlight(false);
|
58
37
|
}
|
59
|
-
|
60
38
|
environmentRef.current = environment;
|
61
39
|
mutationRef.current = mutation;
|
62
40
|
}
|
@@ -65,30 +43,25 @@ function useMutation(mutation) {
|
|
65
43
|
if (isMountedRef.current) {
|
66
44
|
setMutationInFlight(true);
|
67
45
|
}
|
68
|
-
|
69
46
|
var disposable = commitMutationFn(environment, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, config), {}, {
|
70
47
|
mutation: mutation,
|
71
48
|
onCompleted: function onCompleted(response, errors) {
|
72
49
|
var _config$onCompleted;
|
73
|
-
|
74
50
|
cleanup(disposable);
|
75
51
|
(_config$onCompleted = config.onCompleted) === null || _config$onCompleted === void 0 ? void 0 : _config$onCompleted.call(config, response, errors);
|
76
52
|
},
|
77
53
|
onError: function onError(error) {
|
78
54
|
var _config$onError;
|
79
|
-
|
80
55
|
cleanup(disposable);
|
81
56
|
(_config$onError = config.onError) === null || _config$onError === void 0 ? void 0 : _config$onError.call(config, error);
|
82
57
|
},
|
83
58
|
onUnsubscribe: function onUnsubscribe() {
|
84
59
|
var _config$onUnsubscribe;
|
85
|
-
|
86
60
|
cleanup(disposable);
|
87
61
|
(_config$onUnsubscribe = config.onUnsubscribe) === null || _config$onUnsubscribe === void 0 ? void 0 : _config$onUnsubscribe.call(config);
|
88
62
|
},
|
89
63
|
onNext: function onNext() {
|
90
64
|
var _config$onNext;
|
91
|
-
|
92
65
|
(_config$onNext = config.onNext) === null || _config$onNext === void 0 ? void 0 : _config$onNext.call(config);
|
93
66
|
}
|
94
67
|
}));
|
@@ -97,5 +70,4 @@ function useMutation(mutation) {
|
|
97
70
|
}, [cleanup, commitMutationFn, environment, isMountedRef, mutation]);
|
98
71
|
return [commit, isMutationInFlight];
|
99
72
|
}
|
100
|
-
|
101
73
|
module.exports = useMutation;
|
@@ -1,90 +1,62 @@
|
|
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
1
|
'use strict';
|
12
2
|
|
13
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
|
17
5
|
var HooksImplementation = require('./HooksImplementation');
|
18
|
-
|
19
6
|
var useLoadMoreFunction = require('./useLoadMoreFunction');
|
20
|
-
|
21
7
|
var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
22
|
-
|
23
8
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
24
|
-
|
25
9
|
var _require = require('react'),
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
10
|
+
useCallback = _require.useCallback,
|
11
|
+
useDebugValue = _require.useDebugValue,
|
12
|
+
useState = _require.useState;
|
30
13
|
var _require2 = require('relay-runtime'),
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
14
|
+
getFragment = _require2.getFragment,
|
15
|
+
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
16
|
+
getPaginationMetadata = _require2.getPaginationMetadata;
|
35
17
|
function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
36
18
|
var fragmentNode = getFragment(fragmentInput);
|
37
19
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePaginationFragment()');
|
38
20
|
var componentDisplayName = 'usePaginationFragment()';
|
39
|
-
|
40
21
|
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
identifierField = _getPaginationMetadat.identifierField;
|
45
|
-
|
22
|
+
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
23
|
+
paginationRequest = _getPaginationMetadat.paginationRequest,
|
24
|
+
paginationMetadata = _getPaginationMetadat.paginationMetadata;
|
46
25
|
var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName),
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef); // Backward pagination
|
52
|
-
|
26
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
27
|
+
fragmentRef = _useRefetchableFragme.fragmentRef,
|
28
|
+
refetch = _useRefetchableFragme.refetch;
|
29
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
53
30
|
var _useLoadMore = useLoadMore({
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
disposeFetchPrevious = _useLoadMore[3]; // Forward pagination
|
69
|
-
|
70
|
-
|
31
|
+
componentDisplayName: componentDisplayName,
|
32
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
33
|
+
direction: 'backward',
|
34
|
+
fragmentData: fragmentData,
|
35
|
+
fragmentIdentifier: fragmentIdentifier,
|
36
|
+
fragmentNode: fragmentNode,
|
37
|
+
fragmentRef: fragmentRef,
|
38
|
+
paginationMetadata: paginationMetadata,
|
39
|
+
paginationRequest: paginationRequest
|
40
|
+
}),
|
41
|
+
loadPrevious = _useLoadMore[0],
|
42
|
+
hasPrevious = _useLoadMore[1],
|
43
|
+
isLoadingPrevious = _useLoadMore[2],
|
44
|
+
disposeFetchPrevious = _useLoadMore[3];
|
71
45
|
var _useLoadMore2 = useLoadMore({
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
disposeFetchNext = _useLoadMore2[3];
|
87
|
-
|
46
|
+
componentDisplayName: componentDisplayName,
|
47
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
48
|
+
direction: 'forward',
|
49
|
+
fragmentData: fragmentData,
|
50
|
+
fragmentIdentifier: fragmentIdentifier,
|
51
|
+
fragmentNode: fragmentNode,
|
52
|
+
fragmentRef: fragmentRef,
|
53
|
+
paginationMetadata: paginationMetadata,
|
54
|
+
paginationRequest: paginationRequest
|
55
|
+
}),
|
56
|
+
loadNext = _useLoadMore2[0],
|
57
|
+
hasNext = _useLoadMore2[1],
|
58
|
+
isLoadingNext = _useLoadMore2[2],
|
59
|
+
disposeFetchNext = _useLoadMore2[3];
|
88
60
|
var refetchPagination = useCallback(function (variables, options) {
|
89
61
|
disposeFetchNext();
|
90
62
|
disposeFetchPrevious();
|
@@ -92,9 +64,7 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
92
64
|
__environment: undefined
|
93
65
|
}));
|
94
66
|
}, [disposeFetchNext, disposeFetchPrevious, refetch]);
|
95
|
-
|
96
67
|
if (process.env.NODE_ENV !== "production") {
|
97
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
98
68
|
useDebugValue({
|
99
69
|
fragment: fragmentNode.name,
|
100
70
|
data: fragmentData,
|
@@ -104,7 +74,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
104
74
|
isLoadingPrevious: isLoadingPrevious
|
105
75
|
});
|
106
76
|
}
|
107
|
-
|
108
77
|
return {
|
109
78
|
data: fragmentData,
|
110
79
|
loadNext: loadNext,
|
@@ -116,12 +85,10 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
116
85
|
refetch: refetchPagination
|
117
86
|
};
|
118
87
|
}
|
119
|
-
|
120
88
|
function useLoadMore(args) {
|
121
89
|
var _useState = useState(false),
|
122
|
-
|
123
|
-
|
124
|
-
|
90
|
+
isLoadingMore = _useState[0],
|
91
|
+
setIsLoadingMore = _useState[1];
|
125
92
|
var observer = {
|
126
93
|
start: function start() {
|
127
94
|
return setIsLoadingMore(true);
|
@@ -133,31 +100,24 @@ function useLoadMore(args) {
|
|
133
100
|
return setIsLoadingMore(false);
|
134
101
|
}
|
135
102
|
};
|
136
|
-
|
137
103
|
var handleReset = function handleReset() {
|
138
104
|
return setIsLoadingMore(false);
|
139
105
|
};
|
140
|
-
|
141
106
|
var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, args), {}, {
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
107
|
+
observer: observer,
|
108
|
+
onReset: handleReset
|
109
|
+
})),
|
110
|
+
loadMore = _useLoadMoreFunction[0],
|
111
|
+
hasMore = _useLoadMoreFunction[1],
|
112
|
+
disposeFetch = _useLoadMoreFunction[2];
|
149
113
|
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
150
114
|
}
|
151
|
-
|
152
115
|
function usePaginationFragment(fragmentInput, parentFragmentRef) {
|
153
116
|
var impl = HooksImplementation.get();
|
154
|
-
|
155
117
|
if (impl) {
|
156
118
|
return impl.usePaginationFragment(fragmentInput, parentFragmentRef);
|
157
119
|
} else {
|
158
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
159
120
|
return usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef);
|
160
121
|
}
|
161
122
|
}
|
162
|
-
|
163
123
|
module.exports = usePaginationFragment;
|
@@ -1,52 +1,28 @@
|
|
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
1
|
'use strict';
|
12
2
|
|
13
3
|
var _require = require('./loadQuery'),
|
14
|
-
|
15
|
-
|
4
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
16
5
|
var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
17
|
-
|
18
6
|
var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
19
|
-
|
20
7
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
21
|
-
|
22
8
|
var invariant = require('invariant');
|
23
|
-
|
24
9
|
var _require2 = require('react'),
|
25
|
-
|
26
|
-
|
10
|
+
useDebugValue = _require2.useDebugValue;
|
27
11
|
var _require3 = require('relay-runtime'),
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
var warning = require("fbjs/lib/warning"); // This separate type export is only needed as long as we are injecting
|
33
|
-
// a separate hooks implementation in ./HooksImplementation -- it can
|
34
|
-
// be removed after we stop doing that.
|
35
|
-
|
36
|
-
|
12
|
+
_require3$__internal = _require3.__internal,
|
13
|
+
fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
|
14
|
+
fetchQuery = _require3$__internal.fetchQuery;
|
15
|
+
var warning = require("fbjs/lib/warning");
|
37
16
|
function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
38
|
-
// We need to use this hook in order to be able to track if
|
39
|
-
// loadQuery was called during render
|
40
17
|
useTrackLoadQueryInRender();
|
41
18
|
var environment = useRelayEnvironment();
|
42
19
|
var fetchKey = preloadedQuery.fetchKey,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
20
|
+
fetchPolicy = preloadedQuery.fetchPolicy,
|
21
|
+
source = preloadedQuery.source,
|
22
|
+
variables = preloadedQuery.variables,
|
23
|
+
networkCacheConfig = preloadedQuery.networkCacheConfig;
|
47
24
|
var operation = useMemoOperationDescriptor(gqlQuery, variables, networkCacheConfig);
|
48
25
|
var useLazyLoadQueryNodeParams;
|
49
|
-
|
50
26
|
if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
|
51
27
|
!(operation.request.node.params.name === preloadedQuery.name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'usePreloadedQuery(): Expected data to be prefetched for query `%s`, ' + 'got prefetch results for query `%s`.', operation.request.node.params.name, preloadedQuery.name) : invariant(false) : void 0;
|
52
28
|
useLazyLoadQueryNodeParams = {
|
@@ -72,29 +48,14 @@ function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
|
72
48
|
process.env.NODE_ENV !== "production" ? warning(preloadedQuery.isDisposed === false, 'usePreloadedQuery(): Expected preloadedQuery to not be disposed yet. ' + 'This is because disposing the query marks it for future garbage ' + 'collection, and as such query results may no longer be present in the Relay ' + 'store. In the future, this will become a hard error.') : void 0;
|
73
49
|
var fallbackFetchObservable = fetchQuery(environment, operation);
|
74
50
|
var fetchObservable;
|
75
|
-
|
76
51
|
if (source != null && environment === preloadedQuery.environment) {
|
77
|
-
// If the source observable exists and the environments match, reuse
|
78
|
-
// the source observable.
|
79
|
-
// If the source observable happens to be empty, we need to fall back
|
80
|
-
// and re-execute and de-dupe the query (at render time).
|
81
52
|
fetchObservable = source.ifEmpty(fallbackFetchObservable);
|
82
53
|
} else if (environment !== preloadedQuery.environment) {
|
83
|
-
// If a call to loadQuery is made with a particular environment, and that
|
84
|
-
// preloaded query is passed to usePreloadedQuery in a different environment
|
85
|
-
// context, we cannot re-use the existing preloaded query.
|
86
|
-
// Instead, we need to fall back and re-execute and de-dupe the query with
|
87
|
-
// the new environment (at render time).
|
88
|
-
// TODO T68036756 track occurences of this warning and turn it into a hard error
|
89
54
|
process.env.NODE_ENV !== "production" ? warning(false, 'usePreloadedQuery(): usePreloadedQuery was passed a preloaded query ' + 'that was created with a different environment than the one that is currently ' + 'in context. In the future, this will become a hard error.') : void 0;
|
90
55
|
fetchObservable = fallbackFetchObservable;
|
91
56
|
} else {
|
92
|
-
// if (source == null)
|
93
|
-
// If the source observable does not exist, we need to
|
94
|
-
// fall back and re-execute and de-dupe the query (at render time).
|
95
57
|
fetchObservable = fallbackFetchObservable;
|
96
58
|
}
|
97
|
-
|
98
59
|
useLazyLoadQueryNodeParams = {
|
99
60
|
componentDisplayName: 'usePreloadedQuery()',
|
100
61
|
fetchObservable: fetchObservable,
|
@@ -104,11 +65,8 @@ function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
|
104
65
|
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
|
105
66
|
};
|
106
67
|
}
|
107
|
-
|
108
68
|
var data = useLazyLoadQueryNode(useLazyLoadQueryNodeParams);
|
109
|
-
|
110
69
|
if (process.env.NODE_ENV !== "production") {
|
111
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
112
70
|
useDebugValue({
|
113
71
|
query: preloadedQuery.name,
|
114
72
|
variables: preloadedQuery.variables,
|
@@ -118,8 +76,6 @@ function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
|
118
76
|
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
|
119
77
|
});
|
120
78
|
}
|
121
|
-
|
122
79
|
return data;
|
123
80
|
}
|
124
|
-
|
125
81
|
module.exports = usePreloadedQuery;
|