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
@@ -4,62 +4,46 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
import type {
|
15
|
-
import type {
|
16
|
-
FragmentType,
|
17
|
-
GraphQLTaggedNode,
|
18
|
-
OperationType,
|
19
|
-
} from 'relay-runtime';
|
14
|
+
import type {ReturnType} from '../useRefetchableFragment';
|
15
|
+
import type {FragmentType, RefetchableFragment, Variables} from 'relay-runtime';
|
20
16
|
|
21
|
-
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
22
17
|
const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
18
|
+
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
23
19
|
const {useDebugValue} = require('react');
|
24
20
|
const {getFragment} = require('relay-runtime');
|
25
21
|
|
26
|
-
type ReturnType<TQuery: OperationType, TKey: ?{+$data?: mixed, ...}> = [
|
27
|
-
// NOTE: This $Call ensures that the type of the returned data is either:
|
28
|
-
// - nullable if the provided ref type is nullable
|
29
|
-
// - non-nullable if the provided ref type is non-nullable
|
30
|
-
// prettier-ignore
|
31
|
-
$Call<
|
32
|
-
& (<TFragmentData>( { +$data?: TFragmentData, ... }) => TFragmentData)
|
33
|
-
& (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
|
34
|
-
TKey,
|
35
|
-
>,
|
36
|
-
RefetchFnDynamic<TQuery, TKey>,
|
37
|
-
];
|
38
|
-
|
39
22
|
function useRefetchableFragment<
|
40
|
-
|
41
|
-
|
23
|
+
TFragmentType: FragmentType,
|
24
|
+
TVariables: Variables,
|
25
|
+
TData,
|
26
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
42
27
|
>(
|
43
|
-
fragmentInput:
|
28
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
44
29
|
fragmentRef: TKey,
|
45
|
-
): ReturnType<
|
30
|
+
): ReturnType<TVariables, TData, TKey> {
|
46
31
|
const fragmentNode = getFragment(fragmentInput);
|
47
32
|
useStaticFragmentNodeWarning(
|
48
33
|
fragmentNode,
|
49
34
|
'first argument of useRefetchableFragment()',
|
50
35
|
);
|
51
|
-
const {fragmentData, refetch} = useRefetchableFragmentInternal<
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
);
|
36
|
+
const {fragmentData, refetch} = useRefetchableFragmentInternal<
|
37
|
+
{variables: TVariables, response: TData},
|
38
|
+
{data?: TData},
|
39
|
+
>(fragmentNode, fragmentRef, 'useRefetchableFragment()');
|
56
40
|
if (__DEV__) {
|
57
41
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
58
42
|
useDebugValue({fragment: fragmentNode.name, data: fragmentData});
|
59
43
|
}
|
60
|
-
|
61
|
-
|
62
|
-
return [fragmentData,
|
44
|
+
// $FlowFixMe[incompatible-return]
|
45
|
+
// $FlowFixMe[prop-missing]
|
46
|
+
return [fragmentData, refetch];
|
63
47
|
}
|
64
48
|
|
65
49
|
module.exports = useRefetchableFragment;
|
@@ -4,21 +4,22 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
+
import type {RefetchableFragment} from '../../relay-runtime/util/RelayRuntimeTypes';
|
14
15
|
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
15
|
-
import type {
|
16
|
+
import type {Options} from './useRefetchableFragmentNode';
|
16
17
|
import type {
|
18
|
+
Disposable,
|
17
19
|
FragmentType,
|
18
20
|
GraphQLResponse,
|
19
|
-
GraphQLTaggedNode,
|
20
21
|
Observer,
|
21
|
-
|
22
|
+
Variables,
|
22
23
|
} from 'relay-runtime';
|
23
24
|
|
24
25
|
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
@@ -32,35 +33,54 @@ const {
|
|
32
33
|
getPaginationMetadata,
|
33
34
|
} = require('relay-runtime');
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
type RefetchVariables<TVariables, TKey> =
|
37
|
+
// NOTE: This $Call ensures that the type of the variables is either:
|
38
|
+
// - nullable if the provided ref type is non-nullable
|
39
|
+
// - non-nullable if the provided ref type is nullable, and the caller need to provide the full set of variables
|
40
|
+
// prettier-ignore
|
41
|
+
$Call<
|
42
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => Partial<TVariables>)
|
43
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
|
44
|
+
TKey,
|
45
|
+
>;
|
46
|
+
|
47
|
+
type RefetchFnBase<TVars, TOptions> = (
|
48
|
+
vars: TVars,
|
49
|
+
options?: TOptions,
|
50
|
+
) => Disposable;
|
51
|
+
|
52
|
+
type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
|
53
|
+
RefetchVariables<TVariables, TKey>,
|
54
|
+
TOptions,
|
55
|
+
>;
|
56
|
+
|
57
|
+
type ReturnType<TVariables, TData, TKey> = {
|
58
|
+
// NOTE: This $Call ensures that the type of the returned data is either:
|
59
|
+
// - nullable if the provided ref type is nullable
|
60
|
+
// - non-nullable if the provided ref type is non-nullable
|
61
|
+
// prettier-ignore
|
62
|
+
data: $Call<
|
63
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
|
64
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
|
65
|
+
TKey,
|
66
|
+
>,
|
67
|
+
loadNext: LoadMoreFn<TVariables>,
|
68
|
+
loadPrevious: LoadMoreFn<TVariables>,
|
39
69
|
hasNext: boolean,
|
40
70
|
hasPrevious: boolean,
|
41
|
-
refetch:
|
71
|
+
refetch: RefetchFn<TVariables, TKey>,
|
42
72
|
};
|
43
73
|
|
44
74
|
function useBlockingPaginationFragment<
|
45
|
-
|
46
|
-
|
75
|
+
TFragmentType: FragmentType,
|
76
|
+
TVariables: Variables,
|
77
|
+
TData,
|
78
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
47
79
|
>(
|
48
|
-
fragmentInput:
|
80
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
49
81
|
parentFragmentRef: TKey,
|
50
82
|
componentDisplayName: string = 'useBlockingPaginationFragment()',
|
51
|
-
): ReturnType<
|
52
|
-
TQuery,
|
53
|
-
TKey,
|
54
|
-
// NOTE: This $Call ensures that the type of the returned data is either:
|
55
|
-
// - nullable if the provided ref type is nullable
|
56
|
-
// - non-nullable if the provided ref type is non-nullable
|
57
|
-
// prettier-ignore
|
58
|
-
$Call<
|
59
|
-
& (<TFragmentData>( { +$data?: TFragmentData, ... }) => TFragmentData)
|
60
|
-
& (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
|
61
|
-
TKey,
|
62
|
-
>,
|
63
|
-
> {
|
83
|
+
): ReturnType<TVariables, TData, TKey> {
|
64
84
|
const fragmentNode = getFragment(fragmentInput);
|
65
85
|
useStaticFragmentNodeWarning(
|
66
86
|
fragmentNode,
|
@@ -69,7 +89,6 @@ function useBlockingPaginationFragment<
|
|
69
89
|
|
70
90
|
const {
|
71
91
|
connectionPathInFragmentData,
|
72
|
-
identifierField,
|
73
92
|
paginationRequest,
|
74
93
|
paginationMetadata,
|
75
94
|
stream,
|
@@ -86,33 +105,38 @@ function useBlockingPaginationFragment<
|
|
86
105
|
refetch,
|
87
106
|
disableStoreUpdates,
|
88
107
|
enableStoreUpdates,
|
89
|
-
} = useRefetchableFragmentNode<
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
108
|
+
} = useRefetchableFragmentNode<
|
109
|
+
{
|
110
|
+
response: TData,
|
111
|
+
variables: TVariables,
|
112
|
+
},
|
113
|
+
{
|
114
|
+
+$data: mixed,
|
115
|
+
...
|
116
|
+
},
|
117
|
+
>(fragmentNode, parentFragmentRef, componentDisplayName);
|
94
118
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
95
119
|
|
96
120
|
// Backward pagination
|
97
|
-
const [loadPrevious, hasPrevious, disposeFetchPrevious] = useLoadMore<
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
);
|
121
|
+
const [loadPrevious, hasPrevious, disposeFetchPrevious] = useLoadMore<
|
122
|
+
TVariables,
|
123
|
+
TData,
|
124
|
+
>({
|
125
|
+
componentDisplayName,
|
126
|
+
connectionPathInFragmentData,
|
127
|
+
direction: 'backward',
|
128
|
+
disableStoreUpdates,
|
129
|
+
enableStoreUpdates,
|
130
|
+
fragmentData,
|
131
|
+
fragmentIdentifier,
|
132
|
+
fragmentNode,
|
133
|
+
fragmentRef,
|
134
|
+
paginationMetadata,
|
135
|
+
paginationRequest,
|
136
|
+
});
|
113
137
|
|
114
138
|
// Forward pagination
|
115
|
-
const [loadNext, hasNext, disposeFetchNext] = useLoadMore<
|
139
|
+
const [loadNext, hasNext, disposeFetchNext] = useLoadMore<TVariables, TData>({
|
116
140
|
componentDisplayName,
|
117
141
|
connectionPathInFragmentData,
|
118
142
|
direction: 'forward',
|
@@ -122,22 +146,23 @@ function useBlockingPaginationFragment<
|
|
122
146
|
fragmentIdentifier,
|
123
147
|
fragmentNode,
|
124
148
|
fragmentRef,
|
125
|
-
identifierField,
|
126
149
|
paginationMetadata,
|
127
150
|
paginationRequest,
|
128
151
|
});
|
129
152
|
|
130
|
-
const refetchPagination:
|
131
|
-
(variables, options) => {
|
153
|
+
const refetchPagination: RefetchFn<TVariables, TKey> = useCallback(
|
154
|
+
(variables: TVariables, options: void | Options) => {
|
132
155
|
disposeFetchNext();
|
133
156
|
disposeFetchPrevious();
|
157
|
+
// $FlowFixMe[incompatible-variance]
|
134
158
|
return refetch(variables, {...options, __environment: undefined});
|
135
159
|
},
|
136
160
|
[disposeFetchNext, disposeFetchPrevious, refetch],
|
137
161
|
);
|
138
162
|
|
139
163
|
return {
|
140
|
-
|
164
|
+
// $FlowFixMe[incompatible-cast]
|
165
|
+
data: (fragmentData: TData),
|
141
166
|
loadNext,
|
142
167
|
loadPrevious,
|
143
168
|
hasNext,
|
@@ -146,7 +171,7 @@ function useBlockingPaginationFragment<
|
|
146
171
|
};
|
147
172
|
}
|
148
173
|
|
149
|
-
function useLoadMore<
|
174
|
+
function useLoadMore<TVariables: Variables>(args: {
|
150
175
|
disableStoreUpdates: () => void,
|
151
176
|
enableStoreUpdates: () => void,
|
152
177
|
...$Exact<
|
@@ -159,11 +184,13 @@ function useLoadMore<TQuery: OperationType>(args: {
|
|
159
184
|
},
|
160
185
|
>,
|
161
186
|
>,
|
162
|
-
}): [LoadMoreFn<
|
187
|
+
}): [LoadMoreFn<TVariables>, boolean, () => void] {
|
163
188
|
const {disableStoreUpdates, enableStoreUpdates, ...loadMoreArgs} = args;
|
164
|
-
const [requestPromise, setRequestPromise] = useState(
|
165
|
-
|
166
|
-
|
189
|
+
const [requestPromise, setRequestPromise] = useState<null | Promise<mixed>>(
|
190
|
+
null,
|
191
|
+
);
|
192
|
+
const requestPromiseRef = useRef<null | Promise<mixed>>(null);
|
193
|
+
const promiseResolveRef = useRef<null | (() => void)>(null);
|
167
194
|
|
168
195
|
const promiseResolve = () => {
|
169
196
|
if (promiseResolveRef.current != null) {
|
@@ -208,7 +235,7 @@ function useLoadMore<TQuery: OperationType>(args: {
|
|
208
235
|
// and blow away the whole list of items.
|
209
236
|
error: promiseResolve,
|
210
237
|
};
|
211
|
-
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<
|
238
|
+
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
|
212
239
|
...loadMoreArgs,
|
213
240
|
observer,
|
214
241
|
onReset: handleReset,
|
@@ -4,9 +4,9 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -20,8 +20,8 @@ const useLazyLoadQuery = require('./useLazyLoadQuery');
|
|
20
20
|
* These queries are consist of queries for client-only data,
|
21
21
|
* schematized via local schema extensions and/or Relay resolvers.
|
22
22
|
*/
|
23
|
-
function useClientQuery<TVariables: Variables, TData>(
|
24
|
-
gqlQuery: ClientQuery<TVariables, TData>,
|
23
|
+
function useClientQuery<TVariables: Variables, TData, TRawResponse>(
|
24
|
+
gqlQuery: ClientQuery<TVariables, TData, TRawResponse>,
|
25
25
|
variables: TVariables,
|
26
26
|
options?: {
|
27
27
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
@@ -4,9 +4,9 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -134,11 +134,15 @@ function useLoadEntryPoint<
|
|
134
134
|
const entryPointLoaderCallback = useCallback(
|
135
135
|
(params: TEntryPointParams) => {
|
136
136
|
if (isMountedRef.current) {
|
137
|
-
const updatedEntryPointReference = loadEntryPoint
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
137
|
+
const updatedEntryPointReference = loadEntryPoint<
|
138
|
+
TEntryPointParams,
|
139
|
+
TPreloadedQueries,
|
140
|
+
TPreloadedEntryPoints,
|
141
|
+
TRuntimeProps,
|
142
|
+
TExtraProps,
|
143
|
+
TEntryPointComponent,
|
144
|
+
TEntryPoint,
|
145
|
+
>(environmentProvider, entryPoint, params);
|
142
146
|
undisposedEntryPointReferencesRef.current.add(
|
143
147
|
updatedEntryPointReference,
|
144
148
|
);
|
@@ -4,16 +4,17 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
14
|
import type {Subscription} from 'relay-runtime';
|
15
15
|
|
16
|
-
const
|
16
|
+
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
17
|
+
const {useCallback, useEffect} = require('react');
|
17
18
|
|
18
19
|
/**
|
19
20
|
* This hook returns a mutable React ref that holds the value of whether a
|
@@ -33,8 +34,8 @@ function useFetchTrackingRef(): {
|
|
33
34
|
disposeFetch: () => void,
|
34
35
|
completeFetch: () => void,
|
35
36
|
} {
|
36
|
-
const subscriptionRef =
|
37
|
-
const isFetchingRef =
|
37
|
+
const subscriptionRef = useUnsafeRef_DEPRECATED<?Subscription>(null);
|
38
|
+
const isFetchingRef = useUnsafeRef_DEPRECATED<?boolean>(false);
|
38
39
|
|
39
40
|
const disposeFetch = useCallback(() => {
|
40
41
|
if (subscriptionRef.current != null) {
|
@@ -4,9 +4,9 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -50,7 +50,7 @@ function useFragment_LEGACY(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
|
50
50
|
|
51
51
|
const fragmentNode = getFragment(fragment);
|
52
52
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
53
|
-
const {data} = useFragmentNode<
|
53
|
+
const {data} = useFragmentNode<mixed>(fragmentNode, key, 'useFragment()');
|
54
54
|
if (__DEV__) {
|
55
55
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
56
56
|
useDebugValue({fragment: fragmentNode.name, data});
|
@@ -4,9 +4,9 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -15,8 +15,9 @@ import type {ReaderFragment} from 'relay-runtime';
|
|
15
15
|
|
16
16
|
const {getFragmentResourceForEnvironment} = require('./FragmentResource');
|
17
17
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
18
|
-
const
|
19
|
-
const {
|
18
|
+
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
19
|
+
const {useEffect, useState} = require('react');
|
20
|
+
const {RelayFeatureFlags, getFragmentIdentifier} = require('relay-runtime');
|
20
21
|
const warning = require('warning');
|
21
22
|
|
22
23
|
type ReturnType<TFragmentData: mixed> = {
|
@@ -33,7 +34,7 @@ function useFragmentNode<TFragmentData: mixed>(
|
|
33
34
|
const environment = useRelayEnvironment();
|
34
35
|
const FragmentResource = getFragmentResourceForEnvironment(environment);
|
35
36
|
|
36
|
-
const isMountedRef =
|
37
|
+
const isMountedRef = useUnsafeRef_DEPRECATED(false);
|
37
38
|
const [, forceUpdate] = useState(0);
|
38
39
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
39
40
|
|
@@ -45,7 +46,7 @@ function useFragmentNode<TFragmentData: mixed>(
|
|
45
46
|
componentDisplayName,
|
46
47
|
);
|
47
48
|
|
48
|
-
const isListeningForUpdatesRef =
|
49
|
+
const isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
|
49
50
|
function enableStoreUpdates() {
|
50
51
|
isListeningForUpdatesRef.current = true;
|
51
52
|
const didMissUpdates =
|
@@ -98,7 +99,7 @@ function useFragmentNode<TFragmentData: mixed>(
|
|
98
99
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
99
100
|
}, [environment, fragmentIdentifier]);
|
100
101
|
|
101
|
-
if (__DEV__) {
|
102
|
+
if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || __DEV__) {
|
102
103
|
if (
|
103
104
|
fragmentRef != null &&
|
104
105
|
(fragmentResult.data === undefined ||
|
@@ -4,9 +4,9 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -64,7 +64,7 @@ function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
64
64
|
? options.networkCacheConfig
|
65
65
|
: {force: true},
|
66
66
|
);
|
67
|
-
const data = useLazyLoadQueryNode({
|
67
|
+
const data = useLazyLoadQueryNode<$FlowFixMe>({
|
68
68
|
componentDisplayName: 'useLazyLoadQuery()',
|
69
69
|
fetchKey: options?.fetchKey,
|
70
70
|
fetchObservable: fetchQuery(environment, query),
|
@@ -4,9 +4,9 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -125,7 +125,7 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
|
|
125
125
|
});
|
126
126
|
|
127
127
|
const {fragmentNode, fragmentRef} = preparedQueryResult;
|
128
|
-
const {data} = useFragmentNode(
|
128
|
+
const {data} = useFragmentNode<$FlowFixMe>(
|
129
129
|
fragmentNode,
|
130
130
|
fragmentRef,
|
131
131
|
componentDisplayName,
|
@@ -4,9 +4,9 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -17,10 +17,9 @@ import type {
|
|
17
17
|
Disposable,
|
18
18
|
GraphQLResponse,
|
19
19
|
Observer,
|
20
|
-
OperationType,
|
21
20
|
ReaderFragment,
|
22
21
|
ReaderPaginationMetadata,
|
23
|
-
|
22
|
+
Variables,
|
24
23
|
} from 'relay-runtime';
|
25
24
|
|
26
25
|
const useFetchTrackingRef = require('./useFetchTrackingRef');
|
@@ -30,20 +29,21 @@ const useRelayEnvironment = require('./useRelayEnvironment');
|
|
30
29
|
const invariant = require('invariant');
|
31
30
|
const {useCallback, useEffect, useState} = require('react');
|
32
31
|
const {
|
33
|
-
ConnectionInterface,
|
34
32
|
__internal: {fetchQuery},
|
33
|
+
ConnectionInterface,
|
35
34
|
createOperationDescriptor,
|
36
35
|
getPaginationVariables,
|
36
|
+
getRefetchMetadata,
|
37
37
|
getSelector,
|
38
38
|
getValueAtPath,
|
39
39
|
} = require('relay-runtime');
|
40
40
|
const warning = require('warning');
|
41
41
|
|
42
|
-
export type LoadMoreFn<
|
42
|
+
export type LoadMoreFn<TVariables: Variables> = (
|
43
43
|
count: number,
|
44
44
|
options?: {
|
45
45
|
onComplete?: (Error | null) => void,
|
46
|
-
UNSTABLE_extraVariables?:
|
46
|
+
UNSTABLE_extraVariables?: Partial<TVariables>,
|
47
47
|
},
|
48
48
|
) => Disposable;
|
49
49
|
|
@@ -54,7 +54,6 @@ export type UseLoadMoreFunctionArgs = {
|
|
54
54
|
fragmentIdentifier: string,
|
55
55
|
fragmentData: mixed,
|
56
56
|
connectionPathInFragmentData: $ReadOnlyArray<string | number>,
|
57
|
-
identifierField: ?string,
|
58
57
|
paginationRequest: ConcreteRequest,
|
59
58
|
paginationMetadata: ReaderPaginationMetadata,
|
60
59
|
componentDisplayName: string,
|
@@ -62,9 +61,9 @@ export type UseLoadMoreFunctionArgs = {
|
|
62
61
|
onReset: () => void,
|
63
62
|
};
|
64
63
|
|
65
|
-
function useLoadMoreFunction<
|
64
|
+
function useLoadMoreFunction<TVariables: Variables>(
|
66
65
|
args: UseLoadMoreFunctionArgs,
|
67
|
-
): [LoadMoreFn<
|
66
|
+
): [LoadMoreFn<TVariables>, boolean, () => void] {
|
68
67
|
const {
|
69
68
|
direction,
|
70
69
|
fragmentNode,
|
@@ -77,17 +76,22 @@ function useLoadMoreFunction<TQuery: OperationType>(
|
|
77
76
|
componentDisplayName,
|
78
77
|
observer,
|
79
78
|
onReset,
|
80
|
-
identifierField,
|
81
79
|
} = args;
|
82
80
|
const environment = useRelayEnvironment();
|
83
81
|
const {isFetchingRef, startFetch, disposeFetch, completeFetch} =
|
84
82
|
useFetchTrackingRef();
|
83
|
+
|
84
|
+
const {identifierInfo} = getRefetchMetadata(
|
85
|
+
fragmentNode,
|
86
|
+
componentDisplayName,
|
87
|
+
);
|
85
88
|
const identifierValue =
|
86
|
-
identifierField != null &&
|
89
|
+
identifierInfo?.identifierField != null &&
|
87
90
|
fragmentData != null &&
|
88
91
|
typeof fragmentData === 'object'
|
89
|
-
? fragmentData[identifierField]
|
92
|
+
? fragmentData[identifierInfo.identifierField]
|
90
93
|
: null;
|
94
|
+
|
91
95
|
const isMountedRef = useIsMountedRef();
|
92
96
|
const [mirroredEnvironment, setMirroredEnvironment] = useState(environment);
|
93
97
|
const [mirroredFragmentIdentifier, setMirroredFragmentIdentifier] =
|
@@ -123,7 +127,13 @@ function useLoadMoreFunction<TQuery: OperationType>(
|
|
123
127
|
}, [disposeFetch]);
|
124
128
|
|
125
129
|
const loadMore = useCallback(
|
126
|
-
(
|
130
|
+
(
|
131
|
+
count: number,
|
132
|
+
options: void | {
|
133
|
+
UNSTABLE_extraVariables?: Partial<TVariables>,
|
134
|
+
onComplete?: (Error | null) => void,
|
135
|
+
},
|
136
|
+
) => {
|
127
137
|
// TODO(T41131846): Fetch/Caching policies for loadMore
|
128
138
|
|
129
139
|
const onComplete = options?.onComplete;
|
@@ -196,7 +206,7 @@ function useLoadMoreFunction<TQuery: OperationType>(
|
|
196
206
|
|
197
207
|
// If the query needs an identifier value ('id' or similar) and one
|
198
208
|
// was not explicitly provided, read it from the fragment data.
|
199
|
-
if (
|
209
|
+
if (identifierInfo != null) {
|
200
210
|
// @refetchable fragments are guaranteed to have an `id` selection
|
201
211
|
// if the type is Node, implements Node, or is @fetchable. Double-check
|
202
212
|
// that there actually is a value at runtime.
|
@@ -205,11 +215,12 @@ function useLoadMoreFunction<TQuery: OperationType>(
|
|
205
215
|
false,
|
206
216
|
'Relay: Expected result to have a string ' +
|
207
217
|
'`%s` in order to refetch, got `%s`.',
|
208
|
-
identifierField,
|
218
|
+
identifierInfo.identifierField,
|
209
219
|
identifierValue,
|
210
220
|
);
|
211
221
|
}
|
212
|
-
paginationVariables.
|
222
|
+
paginationVariables[identifierInfo.identifierQueryVariableName] =
|
223
|
+
identifierValue;
|
213
224
|
}
|
214
225
|
|
215
226
|
const paginationQuery = createOperationDescriptor(
|