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
@@ -0,0 +1,55 @@
|
|
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
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
|
13
|
+
var _require = require('../loadQuery'),
|
14
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
15
|
+
|
16
|
+
var useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
|
17
|
+
|
18
|
+
var useRelayEnvironment = require('../useRelayEnvironment');
|
19
|
+
|
20
|
+
var getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
|
21
|
+
|
22
|
+
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
23
|
+
|
24
|
+
var _require2 = require('react'),
|
25
|
+
useEffect = _require2.useEffect;
|
26
|
+
|
27
|
+
function useLazyLoadQuery_REACT_CACHE(gqlQuery, variables, options) {
|
28
|
+
var _options$networkCache;
|
29
|
+
|
30
|
+
useTrackLoadQueryInRender();
|
31
|
+
var environment = useRelayEnvironment();
|
32
|
+
var queryOperationDescriptor = useMemoOperationDescriptor(gqlQuery, variables, (_options$networkCache = options === null || options === void 0 ? void 0 : options.networkCacheConfig) !== null && _options$networkCache !== void 0 ? _options$networkCache : {
|
33
|
+
force: true
|
34
|
+
}); // Get the query going if needed -- this may suspend.
|
35
|
+
|
36
|
+
var _getQueryResultOrFetc = getQueryResultOrFetchQuery(environment, queryOperationDescriptor, {
|
37
|
+
fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
|
38
|
+
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy,
|
39
|
+
fetchKey: options === null || options === void 0 ? void 0 : options.fetchKey
|
40
|
+
}),
|
41
|
+
queryResult = _getQueryResultOrFetc[0],
|
42
|
+
effect = _getQueryResultOrFetc[1];
|
43
|
+
|
44
|
+
useEffect(effect); // Read the query's root fragment -- this may suspend.
|
45
|
+
|
46
|
+
var fragmentNode = queryResult.fragmentNode,
|
47
|
+
fragmentRef = queryResult.fragmentRef; // $FlowExpectedError[incompatible-return] Is this a fixable incompatible-return?
|
48
|
+
|
49
|
+
return useFragmentInternal(fragmentNode, fragmentRef, 'useLazyLoadQuery()', {
|
50
|
+
fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
|
51
|
+
networkCacheConfig: options === null || options === void 0 ? void 0 : options.networkCacheConfig
|
52
|
+
});
|
53
|
+
}
|
54
|
+
|
55
|
+
module.exports = useLazyLoadQuery_REACT_CACHE;
|
@@ -0,0 +1,150 @@
|
|
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 _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
+
|
15
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
+
|
17
|
+
var useLoadMoreFunction = require('../useLoadMoreFunction');
|
18
|
+
|
19
|
+
var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
20
|
+
|
21
|
+
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
22
|
+
|
23
|
+
var _require = require('react'),
|
24
|
+
useCallback = _require.useCallback,
|
25
|
+
useDebugValue = _require.useDebugValue,
|
26
|
+
useState = _require.useState;
|
27
|
+
|
28
|
+
var _require2 = require('relay-runtime'),
|
29
|
+
getFragment = _require2.getFragment,
|
30
|
+
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
31
|
+
getPaginationMetadata = _require2.getPaginationMetadata;
|
32
|
+
|
33
|
+
function usePaginationFragment(fragmentInput, parentFragmentRef) {
|
34
|
+
var fragmentNode = getFragment(fragmentInput);
|
35
|
+
useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePaginationFragment()');
|
36
|
+
var componentDisplayName = 'usePaginationFragment()';
|
37
|
+
|
38
|
+
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
39
|
+
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
40
|
+
paginationRequest = _getPaginationMetadat.paginationRequest,
|
41
|
+
paginationMetadata = _getPaginationMetadat.paginationMetadata,
|
42
|
+
identifierField = _getPaginationMetadat.identifierField;
|
43
|
+
|
44
|
+
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, parentFragmentRef, componentDisplayName),
|
45
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
46
|
+
fragmentRef = _useRefetchableFragme.fragmentRef,
|
47
|
+
refetch = _useRefetchableFragme.refetch;
|
48
|
+
|
49
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef); // Backward pagination
|
50
|
+
|
51
|
+
var _useLoadMore = useLoadMore({
|
52
|
+
componentDisplayName: componentDisplayName,
|
53
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
54
|
+
direction: 'backward',
|
55
|
+
fragmentData: fragmentData,
|
56
|
+
fragmentIdentifier: fragmentIdentifier,
|
57
|
+
fragmentNode: fragmentNode,
|
58
|
+
fragmentRef: fragmentRef,
|
59
|
+
identifierField: identifierField,
|
60
|
+
paginationMetadata: paginationMetadata,
|
61
|
+
paginationRequest: paginationRequest
|
62
|
+
}),
|
63
|
+
loadPrevious = _useLoadMore[0],
|
64
|
+
hasPrevious = _useLoadMore[1],
|
65
|
+
isLoadingPrevious = _useLoadMore[2],
|
66
|
+
disposeFetchPrevious = _useLoadMore[3]; // Forward pagination
|
67
|
+
|
68
|
+
|
69
|
+
var _useLoadMore2 = useLoadMore({
|
70
|
+
componentDisplayName: componentDisplayName,
|
71
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
72
|
+
direction: 'forward',
|
73
|
+
fragmentData: fragmentData,
|
74
|
+
fragmentIdentifier: fragmentIdentifier,
|
75
|
+
fragmentNode: fragmentNode,
|
76
|
+
fragmentRef: fragmentRef,
|
77
|
+
identifierField: identifierField,
|
78
|
+
paginationMetadata: paginationMetadata,
|
79
|
+
paginationRequest: paginationRequest
|
80
|
+
}),
|
81
|
+
loadNext = _useLoadMore2[0],
|
82
|
+
hasNext = _useLoadMore2[1],
|
83
|
+
isLoadingNext = _useLoadMore2[2],
|
84
|
+
disposeFetchNext = _useLoadMore2[3];
|
85
|
+
|
86
|
+
var refetchPagination = useCallback(function (variables, options) {
|
87
|
+
disposeFetchNext();
|
88
|
+
disposeFetchPrevious();
|
89
|
+
return refetch(variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
|
90
|
+
__environment: undefined
|
91
|
+
}));
|
92
|
+
}, [disposeFetchNext, disposeFetchPrevious, refetch]);
|
93
|
+
|
94
|
+
if (process.env.NODE_ENV !== "production") {
|
95
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
96
|
+
useDebugValue({
|
97
|
+
fragment: fragmentNode.name,
|
98
|
+
data: fragmentData,
|
99
|
+
hasNext: hasNext,
|
100
|
+
isLoadingNext: isLoadingNext,
|
101
|
+
hasPrevious: hasPrevious,
|
102
|
+
isLoadingPrevious: isLoadingPrevious
|
103
|
+
});
|
104
|
+
}
|
105
|
+
|
106
|
+
return {
|
107
|
+
data: fragmentData,
|
108
|
+
loadNext: loadNext,
|
109
|
+
loadPrevious: loadPrevious,
|
110
|
+
hasNext: hasNext,
|
111
|
+
hasPrevious: hasPrevious,
|
112
|
+
isLoadingNext: isLoadingNext,
|
113
|
+
isLoadingPrevious: isLoadingPrevious,
|
114
|
+
refetch: refetchPagination
|
115
|
+
};
|
116
|
+
}
|
117
|
+
|
118
|
+
function useLoadMore(args) {
|
119
|
+
var _useState = useState(false),
|
120
|
+
isLoadingMore = _useState[0],
|
121
|
+
setIsLoadingMore = _useState[1];
|
122
|
+
|
123
|
+
var observer = {
|
124
|
+
start: function start() {
|
125
|
+
return setIsLoadingMore(true);
|
126
|
+
},
|
127
|
+
complete: function complete() {
|
128
|
+
return setIsLoadingMore(false);
|
129
|
+
},
|
130
|
+
error: function error() {
|
131
|
+
return setIsLoadingMore(false);
|
132
|
+
}
|
133
|
+
};
|
134
|
+
|
135
|
+
var handleReset = function handleReset() {
|
136
|
+
return setIsLoadingMore(false);
|
137
|
+
};
|
138
|
+
|
139
|
+
var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, args), {}, {
|
140
|
+
observer: observer,
|
141
|
+
onReset: handleReset
|
142
|
+
})),
|
143
|
+
loadMore = _useLoadMoreFunction[0],
|
144
|
+
hasMore = _useLoadMoreFunction[1],
|
145
|
+
disposeFetch = _useLoadMoreFunction[2];
|
146
|
+
|
147
|
+
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
148
|
+
}
|
149
|
+
|
150
|
+
module.exports = usePaginationFragment;
|
@@ -0,0 +1,124 @@
|
|
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
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
|
13
|
+
var _require = require('../loadQuery'),
|
14
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
15
|
+
|
16
|
+
var useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
|
17
|
+
|
18
|
+
var useRelayEnvironment = require('../useRelayEnvironment');
|
19
|
+
|
20
|
+
var getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
|
21
|
+
|
22
|
+
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
23
|
+
|
24
|
+
var invariant = require('invariant');
|
25
|
+
|
26
|
+
var _require2 = require('react'),
|
27
|
+
useDebugValue = _require2.useDebugValue,
|
28
|
+
useEffect = _require2.useEffect;
|
29
|
+
|
30
|
+
var _require3 = require('relay-runtime'),
|
31
|
+
_require3$__internal = _require3.__internal,
|
32
|
+
fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
|
33
|
+
fetchQuery = _require3$__internal.fetchQuery;
|
34
|
+
|
35
|
+
var warning = require("fbjs/lib/warning");
|
36
|
+
|
37
|
+
function usePreloadedQuery_REACT_CACHE(gqlQuery, preloadedQuery, options) {
|
38
|
+
var environment = useRelayEnvironment();
|
39
|
+
useTrackLoadQueryInRender();
|
40
|
+
var fetchKey = preloadedQuery.fetchKey,
|
41
|
+
fetchPolicy = preloadedQuery.fetchPolicy,
|
42
|
+
source = preloadedQuery.source,
|
43
|
+
variables = preloadedQuery.variables,
|
44
|
+
networkCacheConfig = preloadedQuery.networkCacheConfig;
|
45
|
+
var operation = useMemoOperationDescriptor(gqlQuery, variables, networkCacheConfig);
|
46
|
+
var fetchObservable;
|
47
|
+
|
48
|
+
if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
|
49
|
+
!(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;
|
50
|
+
fetchObservable = fetchQueryDeduped(environment, operation.request.identifier, function () {
|
51
|
+
if (environment === preloadedQuery.environment && source != null) {
|
52
|
+
return environment.executeWithSource({
|
53
|
+
operation: operation,
|
54
|
+
source: source
|
55
|
+
});
|
56
|
+
} else {
|
57
|
+
return environment.execute({
|
58
|
+
operation: operation
|
59
|
+
});
|
60
|
+
}
|
61
|
+
});
|
62
|
+
} else {
|
63
|
+
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;
|
64
|
+
var fallbackFetchObservable = fetchQuery(environment, operation);
|
65
|
+
|
66
|
+
if (source != null && environment === preloadedQuery.environment) {
|
67
|
+
// If the source observable exists and the environments match, reuse
|
68
|
+
// the source observable.
|
69
|
+
// If the source observable happens to be empty, we need to fall back
|
70
|
+
// and re-execute and de-dupe the query (at render time).
|
71
|
+
fetchObservable = source.ifEmpty(fallbackFetchObservable);
|
72
|
+
} else if (environment !== preloadedQuery.environment) {
|
73
|
+
// If a call to loadQuery is made with a particular environment, and that
|
74
|
+
// preloaded query is passed to usePreloadedQuery in a different environment
|
75
|
+
// context, we cannot re-use the existing preloaded query.
|
76
|
+
// Instead, we need to fall back and re-execute and de-dupe the query with
|
77
|
+
// the new environment (at render time).
|
78
|
+
// TODO T68036756 track occurences of this warning and turn it into a hard error
|
79
|
+
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;
|
80
|
+
fetchObservable = fallbackFetchObservable;
|
81
|
+
} else {
|
82
|
+
// if (source == null)
|
83
|
+
// If the source observable does not exist, we need to
|
84
|
+
// fall back and re-execute and de-dupe the query (at render time).
|
85
|
+
fetchObservable = fallbackFetchObservable;
|
86
|
+
}
|
87
|
+
} // Get the query going if needed -- this may suspend.
|
88
|
+
|
89
|
+
|
90
|
+
var _getQueryResultOrFetc = getQueryResultOrFetchQuery(environment, operation, {
|
91
|
+
fetchPolicy: fetchPolicy,
|
92
|
+
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy,
|
93
|
+
fetchKey: fetchKey,
|
94
|
+
fetchObservable: fetchObservable
|
95
|
+
}),
|
96
|
+
queryResult = _getQueryResultOrFetc[0],
|
97
|
+
effect = _getQueryResultOrFetc[1];
|
98
|
+
|
99
|
+
useEffect(effect); // Read the query's root fragment -- this may suspend.
|
100
|
+
|
101
|
+
var fragmentNode = queryResult.fragmentNode,
|
102
|
+
fragmentRef = queryResult.fragmentRef; // $FlowExpectedError[incompatible-return] Is this a fixable incompatible-return?
|
103
|
+
|
104
|
+
var data = useFragmentInternal(fragmentNode, fragmentRef, 'usePreloadedQuery()', {
|
105
|
+
fetchPolicy: fetchPolicy,
|
106
|
+
networkCacheConfig: networkCacheConfig
|
107
|
+
});
|
108
|
+
|
109
|
+
if (process.env.NODE_ENV !== "production") {
|
110
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
111
|
+
useDebugValue({
|
112
|
+
query: preloadedQuery.name,
|
113
|
+
variables: preloadedQuery.variables,
|
114
|
+
data: data,
|
115
|
+
fetchKey: fetchKey,
|
116
|
+
fetchPolicy: fetchPolicy,
|
117
|
+
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
|
118
|
+
});
|
119
|
+
}
|
120
|
+
|
121
|
+
return data;
|
122
|
+
}
|
123
|
+
|
124
|
+
module.exports = usePreloadedQuery_REACT_CACHE;
|