react-relay 14.0.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- 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 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- 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 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
- 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 +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- 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 +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
@@ -4,39 +4,31 @@
|
|
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
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
|
11
|
+
|
12
12
|
'use strict';
|
13
13
|
|
14
14
|
var _require = require('../loadQuery'),
|
15
|
-
|
16
|
-
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
17
16
|
var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
18
|
-
|
19
17
|
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
20
|
-
|
21
18
|
var _require2 = require('react'),
|
22
|
-
|
23
|
-
|
19
|
+
useDebugValue = _require2.useDebugValue;
|
24
20
|
var _require3 = require('relay-runtime'),
|
25
|
-
|
26
|
-
|
21
|
+
getFragment = _require3.getFragment;
|
27
22
|
function useFragment(fragment, key) {
|
28
23
|
// We need to use this hook in order to be able to track if
|
29
24
|
// loadQuery was called during render
|
30
25
|
useTrackLoadQueryInRender();
|
31
26
|
var fragmentNode = getFragment(fragment);
|
32
|
-
|
33
27
|
if (process.env.NODE_ENV !== "production") {
|
34
28
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
35
29
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
36
30
|
}
|
37
|
-
|
38
31
|
var data = useFragmentInternal(fragmentNode, key, 'useFragment()');
|
39
|
-
|
40
32
|
if (process.env.NODE_ENV !== "production") {
|
41
33
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
42
34
|
useDebugValue({
|
@@ -44,8 +36,6 @@ function useFragment(fragment, key) {
|
|
44
36
|
data: data
|
45
37
|
});
|
46
38
|
}
|
47
|
-
|
48
39
|
return data;
|
49
40
|
}
|
50
|
-
|
51
41
|
module.exports = useFragment;
|
@@ -5,52 +5,45 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
*
|
8
|
-
* @emails oncall+relay
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
|
11
|
+
|
12
12
|
'use strict';
|
13
13
|
|
14
14
|
var _require = require('../loadQuery'),
|
15
|
-
|
16
|
-
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
17
16
|
var useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
|
18
|
-
|
19
17
|
var useRelayEnvironment = require('../useRelayEnvironment');
|
20
|
-
|
21
18
|
var getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
|
22
|
-
|
23
19
|
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
24
|
-
|
25
20
|
var _require2 = require('react'),
|
26
|
-
|
27
|
-
|
21
|
+
useEffect = _require2.useEffect;
|
28
22
|
function useLazyLoadQuery_REACT_CACHE(gqlQuery, variables, options) {
|
29
23
|
var _options$networkCache;
|
30
|
-
|
31
24
|
useTrackLoadQueryInRender();
|
32
25
|
var environment = useRelayEnvironment();
|
33
26
|
var queryOperationDescriptor = useMemoOperationDescriptor(gqlQuery, variables, (_options$networkCache = options === null || options === void 0 ? void 0 : options.networkCacheConfig) !== null && _options$networkCache !== void 0 ? _options$networkCache : {
|
34
27
|
force: true
|
35
|
-
});
|
28
|
+
});
|
36
29
|
|
30
|
+
// Get the query going if needed -- this may suspend.
|
37
31
|
var _getQueryResultOrFetc = getQueryResultOrFetchQuery(environment, queryOperationDescriptor, {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
32
|
+
fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
|
33
|
+
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy,
|
34
|
+
fetchKey: options === null || options === void 0 ? void 0 : options.fetchKey
|
35
|
+
}),
|
36
|
+
queryResult = _getQueryResultOrFetc[0],
|
37
|
+
effect = _getQueryResultOrFetc[1];
|
38
|
+
useEffect(effect);
|
39
|
+
|
40
|
+
// Read the query's root fragment -- this may suspend.
|
47
41
|
var fragmentNode = queryResult.fragmentNode,
|
48
|
-
|
49
|
-
|
42
|
+
fragmentRef = queryResult.fragmentRef;
|
43
|
+
// $FlowExpectedError[incompatible-return] Is this a fixable incompatible-return?
|
50
44
|
return useFragmentInternal(fragmentNode, fragmentRef, 'useLazyLoadQuery()', {
|
51
45
|
fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
|
52
46
|
networkCacheConfig: options === null || options === void 0 ? void 0 : options.networkCacheConfig
|
53
47
|
});
|
54
48
|
}
|
55
|
-
|
56
49
|
module.exports = useLazyLoadQuery_REACT_CACHE;
|
@@ -0,0 +1,149 @@
|
|
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
|
+
* @oncall relay
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
+
var useLoadMoreFunction = require('../useLoadMoreFunction');
|
17
|
+
var useRelayEnvironment = require('../useRelayEnvironment');
|
18
|
+
var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
19
|
+
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
20
|
+
var _require = require('react'),
|
21
|
+
useCallback = _require.useCallback,
|
22
|
+
useDebugValue = _require.useDebugValue,
|
23
|
+
useState = _require.useState;
|
24
|
+
var _require2 = require('relay-runtime'),
|
25
|
+
getFragment = _require2.getFragment,
|
26
|
+
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
27
|
+
getPaginationMetadata = _require2.getPaginationMetadata;
|
28
|
+
function usePaginationFragment(fragmentInput, parentFragmentRef) {
|
29
|
+
var fragmentNode = getFragment(fragmentInput);
|
30
|
+
useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePaginationFragment()');
|
31
|
+
var componentDisplayName = 'usePaginationFragment()';
|
32
|
+
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
33
|
+
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
34
|
+
paginationRequest = _getPaginationMetadat.paginationRequest,
|
35
|
+
paginationMetadata = _getPaginationMetadat.paginationMetadata,
|
36
|
+
identifierField = _getPaginationMetadat.identifierField;
|
37
|
+
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, parentFragmentRef, componentDisplayName),
|
38
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
39
|
+
fragmentRef = _useRefetchableFragme.fragmentRef,
|
40
|
+
refetch = _useRefetchableFragme.refetch;
|
41
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
42
|
+
|
43
|
+
// Backward pagination
|
44
|
+
var _useLoadMore = useLoadMore({
|
45
|
+
componentDisplayName: componentDisplayName,
|
46
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
47
|
+
direction: 'backward',
|
48
|
+
fragmentData: fragmentData,
|
49
|
+
fragmentIdentifier: fragmentIdentifier,
|
50
|
+
fragmentNode: fragmentNode,
|
51
|
+
fragmentRef: fragmentRef,
|
52
|
+
identifierField: identifierField,
|
53
|
+
paginationMetadata: paginationMetadata,
|
54
|
+
paginationRequest: paginationRequest
|
55
|
+
}),
|
56
|
+
loadPrevious = _useLoadMore[0],
|
57
|
+
hasPrevious = _useLoadMore[1],
|
58
|
+
isLoadingPrevious = _useLoadMore[2],
|
59
|
+
disposeFetchPrevious = _useLoadMore[3];
|
60
|
+
|
61
|
+
// Forward pagination
|
62
|
+
var _useLoadMore2 = useLoadMore({
|
63
|
+
componentDisplayName: componentDisplayName,
|
64
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
65
|
+
direction: 'forward',
|
66
|
+
fragmentData: fragmentData,
|
67
|
+
fragmentIdentifier: fragmentIdentifier,
|
68
|
+
fragmentNode: fragmentNode,
|
69
|
+
fragmentRef: fragmentRef,
|
70
|
+
identifierField: identifierField,
|
71
|
+
paginationMetadata: paginationMetadata,
|
72
|
+
paginationRequest: paginationRequest
|
73
|
+
}),
|
74
|
+
loadNext = _useLoadMore2[0],
|
75
|
+
hasNext = _useLoadMore2[1],
|
76
|
+
isLoadingNext = _useLoadMore2[2],
|
77
|
+
disposeFetchNext = _useLoadMore2[3];
|
78
|
+
var refetchPagination = useCallback(function (variables, options) {
|
79
|
+
disposeFetchNext();
|
80
|
+
disposeFetchPrevious();
|
81
|
+
return refetch(variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
|
82
|
+
__environment: undefined
|
83
|
+
}));
|
84
|
+
}, [disposeFetchNext, disposeFetchPrevious, refetch]);
|
85
|
+
if (process.env.NODE_ENV !== "production") {
|
86
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
87
|
+
useDebugValue({
|
88
|
+
fragment: fragmentNode.name,
|
89
|
+
data: fragmentData,
|
90
|
+
hasNext: hasNext,
|
91
|
+
isLoadingNext: isLoadingNext,
|
92
|
+
hasPrevious: hasPrevious,
|
93
|
+
isLoadingPrevious: isLoadingPrevious
|
94
|
+
});
|
95
|
+
}
|
96
|
+
return {
|
97
|
+
data: fragmentData,
|
98
|
+
loadNext: loadNext,
|
99
|
+
loadPrevious: loadPrevious,
|
100
|
+
hasNext: hasNext,
|
101
|
+
hasPrevious: hasPrevious,
|
102
|
+
isLoadingNext: isLoadingNext,
|
103
|
+
isLoadingPrevious: isLoadingPrevious,
|
104
|
+
refetch: refetchPagination
|
105
|
+
};
|
106
|
+
}
|
107
|
+
function useLoadMore(args) {
|
108
|
+
var environment = useRelayEnvironment();
|
109
|
+
var _useState = useState(false),
|
110
|
+
isLoadingMore = _useState[0],
|
111
|
+
reallySetIsLoadingMore = _useState[1];
|
112
|
+
// Schedule this update since it must be observed by components at the same
|
113
|
+
// batch as when hasNext changes. hasNext is read from the store and store
|
114
|
+
// updates are scheduled, so this must be scheduled too.
|
115
|
+
var setIsLoadingMore = function setIsLoadingMore(value) {
|
116
|
+
var _environment$getSched;
|
117
|
+
var schedule = (_environment$getSched = environment.getScheduler()) === null || _environment$getSched === void 0 ? void 0 : _environment$getSched.schedule;
|
118
|
+
if (schedule) {
|
119
|
+
schedule(function () {
|
120
|
+
reallySetIsLoadingMore(value);
|
121
|
+
});
|
122
|
+
} else {
|
123
|
+
reallySetIsLoadingMore(value);
|
124
|
+
}
|
125
|
+
};
|
126
|
+
var observer = {
|
127
|
+
start: function start() {
|
128
|
+
return setIsLoadingMore(true);
|
129
|
+
},
|
130
|
+
complete: function complete() {
|
131
|
+
return setIsLoadingMore(false);
|
132
|
+
},
|
133
|
+
error: function error() {
|
134
|
+
return setIsLoadingMore(false);
|
135
|
+
}
|
136
|
+
};
|
137
|
+
var handleReset = function handleReset() {
|
138
|
+
return setIsLoadingMore(false);
|
139
|
+
};
|
140
|
+
var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, args), {}, {
|
141
|
+
observer: observer,
|
142
|
+
onReset: handleReset
|
143
|
+
})),
|
144
|
+
loadMore = _useLoadMoreFunction[0],
|
145
|
+
hasMore = _useLoadMoreFunction[1],
|
146
|
+
disposeFetch = _useLoadMoreFunction[2];
|
147
|
+
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
148
|
+
}
|
149
|
+
module.exports = usePaginationFragment;
|
@@ -5,47 +5,37 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
*
|
8
|
-
* @emails oncall+relay
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
|
11
|
+
|
12
12
|
'use strict';
|
13
13
|
|
14
14
|
var _require = require('../loadQuery'),
|
15
|
-
|
16
|
-
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
17
16
|
var useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
|
18
|
-
|
19
17
|
var useRelayEnvironment = require('../useRelayEnvironment');
|
20
|
-
|
21
18
|
var getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
|
22
|
-
|
23
19
|
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
24
|
-
|
25
20
|
var invariant = require('invariant');
|
26
|
-
|
27
21
|
var _require2 = require('react'),
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
useDebugValue = _require2.useDebugValue,
|
23
|
+
useEffect = _require2.useEffect;
|
31
24
|
var _require3 = require('relay-runtime'),
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
_require3$__internal = _require3.__internal,
|
26
|
+
fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
|
27
|
+
fetchQuery = _require3$__internal.fetchQuery;
|
36
28
|
var warning = require("fbjs/lib/warning");
|
37
|
-
|
38
29
|
function usePreloadedQuery_REACT_CACHE(gqlQuery, preloadedQuery, options) {
|
39
30
|
var environment = useRelayEnvironment();
|
40
31
|
useTrackLoadQueryInRender();
|
41
32
|
var fetchKey = preloadedQuery.fetchKey,
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
33
|
+
fetchPolicy = preloadedQuery.fetchPolicy,
|
34
|
+
source = preloadedQuery.source,
|
35
|
+
variables = preloadedQuery.variables,
|
36
|
+
networkCacheConfig = preloadedQuery.networkCacheConfig;
|
46
37
|
var operation = useMemoOperationDescriptor(gqlQuery, variables, networkCacheConfig);
|
47
38
|
var fetchObservable;
|
48
|
-
|
49
39
|
if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
|
50
40
|
!(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;
|
51
41
|
fetchObservable = fetchQueryDeduped(environment, operation.request.identifier, function () {
|
@@ -63,7 +53,6 @@ function usePreloadedQuery_REACT_CACHE(gqlQuery, preloadedQuery, options) {
|
|
63
53
|
} else {
|
64
54
|
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;
|
65
55
|
var fallbackFetchObservable = fetchQuery(environment, operation);
|
66
|
-
|
67
56
|
if (source != null && environment === preloadedQuery.environment) {
|
68
57
|
// If the source observable exists and the environments match, reuse
|
69
58
|
// the source observable.
|
@@ -85,28 +74,26 @@ function usePreloadedQuery_REACT_CACHE(gqlQuery, preloadedQuery, options) {
|
|
85
74
|
// fall back and re-execute and de-dupe the query (at render time).
|
86
75
|
fetchObservable = fallbackFetchObservable;
|
87
76
|
}
|
88
|
-
}
|
89
|
-
|
77
|
+
}
|
90
78
|
|
79
|
+
// Get the query going if needed -- this may suspend.
|
91
80
|
var _getQueryResultOrFetc = getQueryResultOrFetchQuery(environment, operation, {
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
useEffect(effect); // Read the query's root fragment -- this may suspend.
|
81
|
+
fetchPolicy: fetchPolicy,
|
82
|
+
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy,
|
83
|
+
fetchKey: fetchKey,
|
84
|
+
fetchObservable: fetchObservable
|
85
|
+
}),
|
86
|
+
queryResult = _getQueryResultOrFetc[0],
|
87
|
+
effect = _getQueryResultOrFetc[1];
|
88
|
+
useEffect(effect);
|
101
89
|
|
90
|
+
// Read the query's root fragment -- this may suspend.
|
102
91
|
var fragmentNode = queryResult.fragmentNode,
|
103
|
-
|
104
|
-
|
92
|
+
fragmentRef = queryResult.fragmentRef;
|
105
93
|
var data = useFragmentInternal(fragmentNode, fragmentRef, 'usePreloadedQuery()', {
|
106
94
|
fetchPolicy: fetchPolicy,
|
107
95
|
networkCacheConfig: networkCacheConfig
|
108
96
|
});
|
109
|
-
|
110
97
|
if (process.env.NODE_ENV !== "production") {
|
111
98
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
112
99
|
useDebugValue({
|
@@ -118,8 +105,6 @@ function usePreloadedQuery_REACT_CACHE(gqlQuery, preloadedQuery, options) {
|
|
118
105
|
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
|
119
106
|
});
|
120
107
|
}
|
121
|
-
|
122
108
|
return data;
|
123
109
|
}
|
124
|
-
|
125
110
|
module.exports = usePreloadedQuery_REACT_CACHE;
|