react-relay 16.2.0 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactRelayContainerUtils.js.flow +2 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -1
- package/ReactRelayFragmentContainer.js.flow +10 -8
- package/ReactRelayLocalQueryRenderer.js.flow +4 -1
- package/ReactRelayPaginationContainer.js.flow +4 -2
- package/ReactRelayQueryRenderer.js.flow +2 -2
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +2 -2
- package/ReactRelayTypes.js.flow +45 -18
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +10 -8
- package/getRootVariablesForFragments.js.flow +1 -0
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +2 -2
- package/lib/buildReactRelayContainer.js +3 -3
- package/lib/relay-hooks/legacy/FragmentResource.js +14 -16
- package/lib/relay-hooks/loadEntryPoint.js +8 -5
- package/lib/relay-hooks/loadQuery.js +2 -14
- package/lib/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js → readFragmentInternal.js} +7 -5
- package/lib/relay-hooks/useEntryPointLoader.js +5 -8
- package/lib/relay-hooks/useFragment.js +7 -20
- package/lib/relay-hooks/useFragmentInternal.js +13 -0
- package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal_CURRENT.js} +12 -18
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +520 -0
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
- package/lib/relay-hooks/useLazyLoadQueryNode.js +2 -13
- package/lib/relay-hooks/usePaginationFragment.js +17 -13
- package/lib/relay-hooks/usePreloadedQuery.js +6 -9
- package/lib/relay-hooks/useQueryLoader.js +1 -3
- package/lib/relay-hooks/useRefetchableFragment.js +3 -12
- package/lib/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js → useRefetchableFragmentInternal.js} +7 -7
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +1 -1
- 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/relay-hooks/EntryPointTypes.flow.js.flow +49 -25
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +22 -5
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +21 -0
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +19 -0
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +22 -0
- package/relay-hooks/legacy/FragmentResource.js.flow +13 -16
- package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +2 -2
- package/relay-hooks/legacy/useFragmentNode.js.flow +1 -1
- package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +2 -2
- package/relay-hooks/loadEntryPoint.js.flow +10 -4
- package/relay-hooks/loadQuery.js.flow +10 -33
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
- package/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js.flow → readFragmentInternal.js.flow} +6 -4
- package/relay-hooks/useClientQuery.js.flow +1 -1
- package/relay-hooks/useEntryPointLoader.js.flow +4 -5
- package/relay-hooks/useFetchTrackingRef.js.flow +1 -1
- package/relay-hooks/useFragment.js.flow +8 -25
- package/relay-hooks/useFragmentInternal.js.flow +45 -0
- package/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js.flow → useFragmentInternal_CURRENT.js.flow} +14 -5
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +764 -0
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +5 -2
- package/relay-hooks/useLazyLoadQuery.js.flow +3 -7
- package/relay-hooks/useLazyLoadQueryNode.js.flow +3 -19
- package/relay-hooks/useLoadMoreFunction.js.flow +1 -1
- package/relay-hooks/useMemoOperationDescriptor.js.flow +1 -1
- package/relay-hooks/useMemoVariables.js.flow +1 -1
- package/relay-hooks/useMutation.js.flow +1 -1
- package/relay-hooks/usePaginationFragment.js.flow +62 -50
- package/relay-hooks/usePreloadedQuery.js.flow +2 -6
- package/relay-hooks/useQueryLoader.js.flow +3 -7
- package/relay-hooks/useRefetchableFragment.js.flow +7 -37
- package/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow → useRefetchableFragmentInternal.js.flow} +11 -11
- package/relay-hooks/useRelayEnvironment.js.flow +1 -1
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -1
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +1 -1
- package/lib/relay-hooks/HooksImplementation.js +0 -15
- package/lib/relay-hooks/experimental/useFragment_EXPERIMENTAL.js +0 -26
- package/lib/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js +0 -127
- package/lib/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js +0 -23
- package/relay-hooks/HooksImplementation.js.flow +0 -45
- package/relay-hooks/experimental/useFragment_EXPERIMENTAL.js.flow +0 -72
- package/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js.flow +0 -161
- package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +0 -49
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
5
|
-
var useLoadMoreFunction = require('../useLoadMoreFunction');
|
|
6
|
-
var useRelayEnvironment = require('../useRelayEnvironment');
|
|
7
|
-
var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
|
8
|
-
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_EXPERIMENTAL');
|
|
9
|
-
var _require = require('react'),
|
|
10
|
-
useCallback = _require.useCallback,
|
|
11
|
-
useDebugValue = _require.useDebugValue,
|
|
12
|
-
useState = _require.useState;
|
|
13
|
-
var _require2 = require('relay-runtime'),
|
|
14
|
-
getFragment = _require2.getFragment,
|
|
15
|
-
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
|
16
|
-
getPaginationMetadata = _require2.getPaginationMetadata;
|
|
17
|
-
function usePaginationFragment(fragmentInput, parentFragmentRef) {
|
|
18
|
-
var fragmentNode = getFragment(fragmentInput);
|
|
19
|
-
useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePaginationFragment()');
|
|
20
|
-
var componentDisplayName = 'usePaginationFragment()';
|
|
21
|
-
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
|
22
|
-
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
|
23
|
-
paginationRequest = _getPaginationMetadat.paginationRequest,
|
|
24
|
-
paginationMetadata = _getPaginationMetadat.paginationMetadata;
|
|
25
|
-
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, parentFragmentRef, componentDisplayName),
|
|
26
|
-
fragmentData = _useRefetchableFragme.fragmentData,
|
|
27
|
-
fragmentRef = _useRefetchableFragme.fragmentRef,
|
|
28
|
-
refetch = _useRefetchableFragme.refetch;
|
|
29
|
-
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
|
30
|
-
var _useLoadMore = useLoadMore({
|
|
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];
|
|
45
|
-
var _useLoadMore2 = useLoadMore({
|
|
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];
|
|
60
|
-
var refetchPagination = useCallback(function (variables, options) {
|
|
61
|
-
disposeFetchNext();
|
|
62
|
-
disposeFetchPrevious();
|
|
63
|
-
return refetch(variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
|
|
64
|
-
__environment: undefined
|
|
65
|
-
}));
|
|
66
|
-
}, [disposeFetchNext, disposeFetchPrevious, refetch]);
|
|
67
|
-
if (process.env.NODE_ENV !== "production") {
|
|
68
|
-
useDebugValue({
|
|
69
|
-
fragment: fragmentNode.name,
|
|
70
|
-
data: fragmentData,
|
|
71
|
-
hasNext: hasNext,
|
|
72
|
-
isLoadingNext: isLoadingNext,
|
|
73
|
-
hasPrevious: hasPrevious,
|
|
74
|
-
isLoadingPrevious: isLoadingPrevious
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
data: fragmentData,
|
|
79
|
-
loadNext: loadNext,
|
|
80
|
-
loadPrevious: loadPrevious,
|
|
81
|
-
hasNext: hasNext,
|
|
82
|
-
hasPrevious: hasPrevious,
|
|
83
|
-
isLoadingNext: isLoadingNext,
|
|
84
|
-
isLoadingPrevious: isLoadingPrevious,
|
|
85
|
-
refetch: refetchPagination
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function useLoadMore(args) {
|
|
89
|
-
var environment = useRelayEnvironment();
|
|
90
|
-
var _useState = useState(false),
|
|
91
|
-
isLoadingMore = _useState[0],
|
|
92
|
-
reallySetIsLoadingMore = _useState[1];
|
|
93
|
-
var setIsLoadingMore = function setIsLoadingMore(value) {
|
|
94
|
-
var _environment$getSched;
|
|
95
|
-
var schedule = (_environment$getSched = environment.getScheduler()) === null || _environment$getSched === void 0 ? void 0 : _environment$getSched.schedule;
|
|
96
|
-
if (schedule) {
|
|
97
|
-
schedule(function () {
|
|
98
|
-
reallySetIsLoadingMore(value);
|
|
99
|
-
});
|
|
100
|
-
} else {
|
|
101
|
-
reallySetIsLoadingMore(value);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
var observer = {
|
|
105
|
-
start: function start() {
|
|
106
|
-
return setIsLoadingMore(true);
|
|
107
|
-
},
|
|
108
|
-
complete: function complete() {
|
|
109
|
-
return setIsLoadingMore(false);
|
|
110
|
-
},
|
|
111
|
-
error: function error() {
|
|
112
|
-
return setIsLoadingMore(false);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
var handleReset = function handleReset() {
|
|
116
|
-
return setIsLoadingMore(false);
|
|
117
|
-
};
|
|
118
|
-
var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, args), {}, {
|
|
119
|
-
observer: observer,
|
|
120
|
-
onReset: handleReset
|
|
121
|
-
})),
|
|
122
|
-
loadMore = _useLoadMoreFunction[0],
|
|
123
|
-
hasMore = _useLoadMoreFunction[1],
|
|
124
|
-
disposeFetch = _useLoadMoreFunction[2];
|
|
125
|
-
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
|
126
|
-
}
|
|
127
|
-
module.exports = usePaginationFragment;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
|
4
|
-
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_EXPERIMENTAL');
|
|
5
|
-
var _require = require('react'),
|
|
6
|
-
useDebugValue = _require.useDebugValue;
|
|
7
|
-
var _require2 = require('relay-runtime'),
|
|
8
|
-
getFragment = _require2.getFragment;
|
|
9
|
-
function useRefetchableFragment(fragmentInput, fragmentRef) {
|
|
10
|
-
var fragmentNode = getFragment(fragmentInput);
|
|
11
|
-
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
|
|
12
|
-
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
|
|
13
|
-
fragmentData = _useRefetchableFragme.fragmentData,
|
|
14
|
-
refetch = _useRefetchableFragme.refetch;
|
|
15
|
-
if (process.env.NODE_ENV !== "production") {
|
|
16
|
-
useDebugValue({
|
|
17
|
-
fragment: fragmentNode.name,
|
|
18
|
-
data: fragmentData
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
return [fragmentData, refetch];
|
|
22
|
-
}
|
|
23
|
-
module.exports = useRefetchableFragment;
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
import typeof useFragmentInternal from './experimental/useFragmentInternal_EXPERIMENTAL';
|
|
15
|
-
import typeof useFragment from './useFragment';
|
|
16
|
-
import type {UsePaginationFragmentType} from './usePaginationFragment';
|
|
17
|
-
import type {UseRefetchableFragmentType} from './useRefetchableFragment';
|
|
18
|
-
|
|
19
|
-
const warning = require('warning');
|
|
20
|
-
|
|
21
|
-
type HooksImplementation = {
|
|
22
|
-
useFragment: useFragment,
|
|
23
|
-
usePaginationFragment: UsePaginationFragmentType,
|
|
24
|
-
useRefetchableFragment: UseRefetchableFragmentType,
|
|
25
|
-
useFragment__internal?: useFragmentInternal,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
let implementation: HooksImplementation | null = null;
|
|
29
|
-
|
|
30
|
-
function inject(impl: HooksImplementation): void {
|
|
31
|
-
warning(
|
|
32
|
-
implementation === null,
|
|
33
|
-
'Relay HooksImplementation was injected twice.',
|
|
34
|
-
);
|
|
35
|
-
implementation = impl;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function get(): HooksImplementation | null {
|
|
39
|
-
return implementation;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
module.exports = {
|
|
43
|
-
inject,
|
|
44
|
-
get,
|
|
45
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
import type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
|
|
15
|
-
|
|
16
|
-
const {useTrackLoadQueryInRender} = require('../loadQuery');
|
|
17
|
-
const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
|
18
|
-
const useFragmentInternal = require('./useFragmentInternal_EXPERIMENTAL');
|
|
19
|
-
const {useDebugValue} = require('react');
|
|
20
|
-
const {getFragment} = require('relay-runtime');
|
|
21
|
-
|
|
22
|
-
type HasSpread<TFragmentType> = {
|
|
23
|
-
+$fragmentSpreads: TFragmentType,
|
|
24
|
-
...
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// if the key is non-nullable, return non-nullable value
|
|
28
|
-
declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
29
|
-
fragment: Fragment<TFragmentType, TData>,
|
|
30
|
-
key: HasSpread<TFragmentType>,
|
|
31
|
-
): TData;
|
|
32
|
-
|
|
33
|
-
// if the key is nullable, return nullable value
|
|
34
|
-
declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
35
|
-
fragment: Fragment<TFragmentType, TData>,
|
|
36
|
-
key: ?HasSpread<TFragmentType>,
|
|
37
|
-
): ?TData;
|
|
38
|
-
|
|
39
|
-
// if the key is a non-nullable array of keys, return non-nullable array
|
|
40
|
-
declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
41
|
-
fragment: Fragment<TFragmentType, TData>,
|
|
42
|
-
key: $ReadOnlyArray<HasSpread<TFragmentType>>,
|
|
43
|
-
): TData;
|
|
44
|
-
|
|
45
|
-
// if the key is a nullable array of keys, return nullable array
|
|
46
|
-
declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
47
|
-
fragment: Fragment<TFragmentType, TData>,
|
|
48
|
-
key: ?$ReadOnlyArray<HasSpread<TFragmentType>>,
|
|
49
|
-
): ?TData;
|
|
50
|
-
|
|
51
|
-
function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
|
52
|
-
// We need to use this hook in order to be able to track if
|
|
53
|
-
// loadQuery was called during render
|
|
54
|
-
useTrackLoadQueryInRender();
|
|
55
|
-
|
|
56
|
-
const fragmentNode = getFragment(fragment);
|
|
57
|
-
if (__DEV__) {
|
|
58
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
59
|
-
useStaticFragmentNodeWarning(
|
|
60
|
-
fragmentNode,
|
|
61
|
-
'first argument of useFragment()',
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
const data = useFragmentInternal(fragmentNode, key, 'useFragment()');
|
|
65
|
-
if (__DEV__) {
|
|
66
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
67
|
-
useDebugValue({fragment: fragmentNode.name, data});
|
|
68
|
-
}
|
|
69
|
-
return data;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports = useFragment;
|
|
@@ -1,161 +0,0 @@
|
|
|
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
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from '../useLoadMoreFunction';
|
|
15
|
-
import type {ReturnType} from '../usePaginationFragment';
|
|
16
|
-
import type {Options} from './useRefetchableFragmentInternal_EXPERIMENTAL';
|
|
17
|
-
import type {
|
|
18
|
-
FragmentType,
|
|
19
|
-
GraphQLResponse,
|
|
20
|
-
Observer,
|
|
21
|
-
RefetchableFragment,
|
|
22
|
-
Variables,
|
|
23
|
-
} from 'relay-runtime';
|
|
24
|
-
|
|
25
|
-
const useLoadMoreFunction = require('../useLoadMoreFunction');
|
|
26
|
-
const useRelayEnvironment = require('../useRelayEnvironment');
|
|
27
|
-
const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
|
28
|
-
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_EXPERIMENTAL');
|
|
29
|
-
const {useCallback, useDebugValue, useState} = require('react');
|
|
30
|
-
const {
|
|
31
|
-
getFragment,
|
|
32
|
-
getFragmentIdentifier,
|
|
33
|
-
getPaginationMetadata,
|
|
34
|
-
} = require('relay-runtime');
|
|
35
|
-
|
|
36
|
-
function usePaginationFragment<
|
|
37
|
-
TFragmentType: FragmentType,
|
|
38
|
-
TVariables: Variables,
|
|
39
|
-
TData,
|
|
40
|
-
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
|
41
|
-
>(
|
|
42
|
-
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
43
|
-
parentFragmentRef: TKey,
|
|
44
|
-
): ReturnType<TVariables, TData, TKey> {
|
|
45
|
-
const fragmentNode = getFragment(fragmentInput);
|
|
46
|
-
useStaticFragmentNodeWarning(
|
|
47
|
-
fragmentNode,
|
|
48
|
-
'first argument of usePaginationFragment()',
|
|
49
|
-
);
|
|
50
|
-
const componentDisplayName = 'usePaginationFragment()';
|
|
51
|
-
|
|
52
|
-
const {connectionPathInFragmentData, paginationRequest, paginationMetadata} =
|
|
53
|
-
getPaginationMetadata(fragmentNode, componentDisplayName);
|
|
54
|
-
|
|
55
|
-
const {fragmentData, fragmentRef, refetch} = useRefetchableFragmentInternal<
|
|
56
|
-
{variables: TVariables, response: TData},
|
|
57
|
-
{data?: TData},
|
|
58
|
-
>(fragmentNode, parentFragmentRef, componentDisplayName);
|
|
59
|
-
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
|
60
|
-
|
|
61
|
-
// Backward pagination
|
|
62
|
-
const [loadPrevious, hasPrevious, isLoadingPrevious, disposeFetchPrevious] =
|
|
63
|
-
useLoadMore<TVariables>({
|
|
64
|
-
componentDisplayName,
|
|
65
|
-
connectionPathInFragmentData,
|
|
66
|
-
direction: 'backward',
|
|
67
|
-
fragmentData,
|
|
68
|
-
fragmentIdentifier,
|
|
69
|
-
fragmentNode,
|
|
70
|
-
fragmentRef,
|
|
71
|
-
paginationMetadata,
|
|
72
|
-
paginationRequest,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Forward pagination
|
|
76
|
-
const [loadNext, hasNext, isLoadingNext, disposeFetchNext] =
|
|
77
|
-
useLoadMore<TVariables>({
|
|
78
|
-
componentDisplayName,
|
|
79
|
-
connectionPathInFragmentData,
|
|
80
|
-
direction: 'forward',
|
|
81
|
-
fragmentData,
|
|
82
|
-
fragmentIdentifier,
|
|
83
|
-
fragmentNode,
|
|
84
|
-
fragmentRef,
|
|
85
|
-
paginationMetadata,
|
|
86
|
-
paginationRequest,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const refetchPagination = useCallback(
|
|
90
|
-
(variables: TVariables, options: void | Options) => {
|
|
91
|
-
disposeFetchNext();
|
|
92
|
-
disposeFetchPrevious();
|
|
93
|
-
return refetch(variables, {...options, __environment: undefined});
|
|
94
|
-
},
|
|
95
|
-
[disposeFetchNext, disposeFetchPrevious, refetch],
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
if (__DEV__) {
|
|
99
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
100
|
-
useDebugValue({
|
|
101
|
-
fragment: fragmentNode.name,
|
|
102
|
-
data: fragmentData,
|
|
103
|
-
hasNext,
|
|
104
|
-
isLoadingNext,
|
|
105
|
-
hasPrevious,
|
|
106
|
-
isLoadingPrevious,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
// $FlowFixMe[incompatible-return]
|
|
111
|
-
data: fragmentData,
|
|
112
|
-
loadNext,
|
|
113
|
-
loadPrevious,
|
|
114
|
-
hasNext,
|
|
115
|
-
hasPrevious,
|
|
116
|
-
isLoadingNext,
|
|
117
|
-
isLoadingPrevious,
|
|
118
|
-
refetch: refetchPagination,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function useLoadMore<TVariables: Variables>(
|
|
123
|
-
args: $Diff<
|
|
124
|
-
UseLoadMoreFunctionArgs,
|
|
125
|
-
{
|
|
126
|
-
observer: Observer<GraphQLResponse>,
|
|
127
|
-
onReset: () => void,
|
|
128
|
-
...
|
|
129
|
-
},
|
|
130
|
-
>,
|
|
131
|
-
): [LoadMoreFn<TVariables>, boolean, boolean, () => void] {
|
|
132
|
-
const environment = useRelayEnvironment();
|
|
133
|
-
const [isLoadingMore, reallySetIsLoadingMore] = useState(false);
|
|
134
|
-
// Schedule this update since it must be observed by components at the same
|
|
135
|
-
// batch as when hasNext changes. hasNext is read from the store and store
|
|
136
|
-
// updates are scheduled, so this must be scheduled too.
|
|
137
|
-
const setIsLoadingMore = (value: boolean) => {
|
|
138
|
-
const schedule = environment.getScheduler()?.schedule;
|
|
139
|
-
if (schedule) {
|
|
140
|
-
schedule(() => {
|
|
141
|
-
reallySetIsLoadingMore(value);
|
|
142
|
-
});
|
|
143
|
-
} else {
|
|
144
|
-
reallySetIsLoadingMore(value);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
const observer = {
|
|
148
|
-
start: () => setIsLoadingMore(true),
|
|
149
|
-
complete: () => setIsLoadingMore(false),
|
|
150
|
-
error: () => setIsLoadingMore(false),
|
|
151
|
-
};
|
|
152
|
-
const handleReset = () => setIsLoadingMore(false);
|
|
153
|
-
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
|
|
154
|
-
...args,
|
|
155
|
-
observer,
|
|
156
|
-
onReset: handleReset,
|
|
157
|
-
});
|
|
158
|
-
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
module.exports = usePaginationFragment;
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
import type {ReturnType} from '../useRefetchableFragment';
|
|
15
|
-
import type {FragmentType, RefetchableFragment, Variables} from 'relay-runtime';
|
|
16
|
-
|
|
17
|
-
const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
|
18
|
-
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_EXPERIMENTAL');
|
|
19
|
-
const {useDebugValue} = require('react');
|
|
20
|
-
const {getFragment} = require('relay-runtime');
|
|
21
|
-
|
|
22
|
-
function useRefetchableFragment<
|
|
23
|
-
TFragmentType: FragmentType,
|
|
24
|
-
TVariables: Variables,
|
|
25
|
-
TData,
|
|
26
|
-
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
|
27
|
-
>(
|
|
28
|
-
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
29
|
-
fragmentRef: TKey,
|
|
30
|
-
): ReturnType<TVariables, TData, TKey> {
|
|
31
|
-
const fragmentNode = getFragment(fragmentInput);
|
|
32
|
-
useStaticFragmentNodeWarning(
|
|
33
|
-
fragmentNode,
|
|
34
|
-
'first argument of useRefetchableFragment()',
|
|
35
|
-
);
|
|
36
|
-
const {fragmentData, refetch} = useRefetchableFragmentInternal<
|
|
37
|
-
{variables: TVariables, response: TData},
|
|
38
|
-
{data?: TData},
|
|
39
|
-
>(fragmentNode, fragmentRef, 'useRefetchableFragment()');
|
|
40
|
-
if (__DEV__) {
|
|
41
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
42
|
-
useDebugValue({fragment: fragmentNode.name, data: fragmentData});
|
|
43
|
-
}
|
|
44
|
-
// $FlowFixMe[incompatible-return]
|
|
45
|
-
// $FlowFixMe[prop-missing]
|
|
46
|
-
return [fragmentData, refetch];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
module.exports = useRefetchableFragment;
|