react-relay 14.1.0 → 16.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 +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,18 +4,19 @@
|
|
|
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 {
|
|
14
|
+
import type {Options} from './useRefetchableFragmentNode';
|
|
15
15
|
import type {
|
|
16
|
+
Disposable,
|
|
16
17
|
FragmentType,
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
RefetchableFragment,
|
|
19
|
+
Variables,
|
|
19
20
|
} from 'relay-runtime';
|
|
20
21
|
|
|
21
22
|
const HooksImplementation = require('./HooksImplementation');
|
|
@@ -24,66 +25,97 @@ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
|
|
24
25
|
const {useDebugValue} = require('react');
|
|
25
26
|
const {getFragment} = require('relay-runtime');
|
|
26
27
|
|
|
27
|
-
type
|
|
28
|
+
type RefetchVariables<TVariables, TKey> =
|
|
29
|
+
// NOTE: This $Call ensures that the type of the returned variables is either:
|
|
30
|
+
// - nullable if the provided ref type is nullable
|
|
31
|
+
// - non-nullable if the provided ref type is non-nullable
|
|
32
|
+
// prettier-ignore
|
|
33
|
+
$Call<
|
|
34
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => Partial<TVariables>)
|
|
35
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
|
|
36
|
+
TKey,
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
type RefetchFnBase<TVars, TOptions> = (
|
|
40
|
+
vars: TVars,
|
|
41
|
+
options?: TOptions,
|
|
42
|
+
) => Disposable;
|
|
43
|
+
|
|
44
|
+
export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
|
|
45
|
+
RefetchVariables<TVariables, TKey>,
|
|
46
|
+
TOptions,
|
|
47
|
+
>;
|
|
48
|
+
|
|
49
|
+
export type ReturnType<TVariables, TData, TKey> = [
|
|
28
50
|
// NOTE: This $Call ensures that the type of the returned data is either:
|
|
29
51
|
// - nullable if the provided ref type is nullable
|
|
30
52
|
// - non-nullable if the provided ref type is non-nullable
|
|
31
53
|
// prettier-ignore
|
|
32
54
|
$Call<
|
|
33
|
-
& (<
|
|
34
|
-
& (<
|
|
55
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
|
|
56
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
|
|
35
57
|
TKey,
|
|
36
58
|
>,
|
|
37
|
-
|
|
59
|
+
RefetchFn<TVariables, TKey>,
|
|
38
60
|
];
|
|
39
61
|
|
|
40
|
-
// This separate type export is only needed as long as we are injecting
|
|
41
|
-
// a separate hooks implementation in ./HooksImplementation -- it can
|
|
42
|
-
// be removed after we stop doing that.
|
|
43
62
|
export type UseRefetchableFragmentType = <
|
|
44
|
-
|
|
45
|
-
|
|
63
|
+
TFragmentType: FragmentType,
|
|
64
|
+
TVariables: Variables,
|
|
65
|
+
TData,
|
|
66
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
|
46
67
|
>(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
) => ReturnType<
|
|
68
|
+
fragment: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
69
|
+
key: TKey,
|
|
70
|
+
) => ReturnType<TVariables, TData, TKey>;
|
|
50
71
|
|
|
51
72
|
function useRefetchableFragment_LEGACY<
|
|
52
|
-
|
|
53
|
-
|
|
73
|
+
TFragmentType: FragmentType,
|
|
74
|
+
TVariables: Variables,
|
|
75
|
+
TData,
|
|
76
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
|
54
77
|
>(
|
|
55
|
-
fragmentInput:
|
|
78
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
56
79
|
fragmentRef: TKey,
|
|
57
|
-
): ReturnType<
|
|
80
|
+
): ReturnType<TVariables, TData, TKey> {
|
|
58
81
|
const fragmentNode = getFragment(fragmentInput);
|
|
59
82
|
useStaticFragmentNodeWarning(
|
|
60
83
|
fragmentNode,
|
|
61
84
|
'first argument of useRefetchableFragment()',
|
|
62
85
|
);
|
|
63
|
-
const {fragmentData, refetch} = useRefetchableFragmentNode<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
86
|
+
const {fragmentData, refetch} = useRefetchableFragmentNode<
|
|
87
|
+
{
|
|
88
|
+
response: TData,
|
|
89
|
+
variables: TVariables,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
+$data: mixed,
|
|
93
|
+
...
|
|
94
|
+
},
|
|
95
|
+
>(fragmentNode, fragmentRef, 'useRefetchableFragment()');
|
|
68
96
|
if (__DEV__) {
|
|
69
97
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
70
98
|
useDebugValue({fragment: fragmentNode.name, data: fragmentData});
|
|
71
99
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
100
|
+
|
|
101
|
+
// $FlowFixMe[incompatible-return]
|
|
102
|
+
// $FlowFixMe[prop-missing]
|
|
103
|
+
// $FlowFixMe[incompatible-variance]
|
|
104
|
+
return [fragmentData, refetch];
|
|
75
105
|
}
|
|
76
106
|
|
|
77
107
|
function useRefetchableFragment<
|
|
78
|
-
|
|
79
|
-
|
|
108
|
+
TFragmentType: FragmentType,
|
|
109
|
+
TVariables: Variables,
|
|
110
|
+
TData,
|
|
111
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
|
80
112
|
>(
|
|
81
|
-
fragmentInput:
|
|
113
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
82
114
|
parentFragmentRef: TKey,
|
|
83
|
-
): ReturnType<
|
|
115
|
+
): ReturnType<TVariables, TData, TKey> {
|
|
84
116
|
const impl = HooksImplementation.get();
|
|
85
117
|
if (impl) {
|
|
86
|
-
return impl.useRefetchableFragment<
|
|
118
|
+
return impl.useRefetchableFragment<TFragmentType, TVariables, TData, TKey>(
|
|
87
119
|
fragmentInput,
|
|
88
120
|
parentFragmentRef,
|
|
89
121
|
);
|
|
@@ -4,13 +4,14 @@
|
|
|
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 {RefetchableIdentifierInfo} from '../../relay-runtime/util/ReaderNode';
|
|
14
15
|
import type {LoaderFn} from './useQueryLoader';
|
|
15
16
|
import type {
|
|
16
17
|
ConcreteRequest,
|
|
@@ -100,7 +101,7 @@ type RefetchFnExact<TQuery: OperationType, TOptions = Options> = RefetchFnBase<
|
|
|
100
101
|
type RefetchFnInexact<
|
|
101
102
|
TQuery: OperationType,
|
|
102
103
|
TOptions = Options,
|
|
103
|
-
> = RefetchFnBase
|
|
104
|
+
> = RefetchFnBase<Partial<VariablesOf<TQuery>>, TOptions>;
|
|
104
105
|
|
|
105
106
|
type Action =
|
|
106
107
|
| {
|
|
@@ -173,8 +174,10 @@ function useRefetchableFragmentNode<
|
|
|
173
174
|
componentDisplayName: string,
|
|
174
175
|
): ReturnType<TQuery, TKey, InternalOptions> {
|
|
175
176
|
const parentEnvironment = useRelayEnvironment();
|
|
176
|
-
const {refetchableRequest, fragmentRefPathInResponse
|
|
177
|
-
|
|
177
|
+
const {refetchableRequest, fragmentRefPathInResponse} = getRefetchMetadata(
|
|
178
|
+
fragmentNode,
|
|
179
|
+
componentDisplayName,
|
|
180
|
+
);
|
|
178
181
|
const fragmentIdentifier = getFragmentIdentifier(
|
|
179
182
|
fragmentNode,
|
|
180
183
|
parentFragmentRef,
|
|
@@ -207,10 +210,19 @@ function useRefetchableFragmentNode<
|
|
|
207
210
|
const shouldReset =
|
|
208
211
|
environment !== mirroredEnvironment ||
|
|
209
212
|
fragmentIdentifier !== mirroredFragmentIdentifier;
|
|
210
|
-
const [queryRef, loadQuery, disposeQuery] =
|
|
211
|
-
|
|
213
|
+
const [queryRef, loadQuery, disposeQuery] = useQueryLoader<
|
|
214
|
+
TQuery['variables'],
|
|
215
|
+
TQuery['response'],
|
|
216
|
+
TQuery['rawResponse'],
|
|
217
|
+
>((refetchableRequest: $FlowFixMe));
|
|
212
218
|
|
|
213
219
|
let fragmentRef = parentFragmentRef;
|
|
220
|
+
|
|
221
|
+
const {identifierInfo} = getRefetchMetadata(
|
|
222
|
+
fragmentNode,
|
|
223
|
+
componentDisplayName,
|
|
224
|
+
);
|
|
225
|
+
|
|
214
226
|
if (shouldReset) {
|
|
215
227
|
dispatch({
|
|
216
228
|
type: 'reset',
|
|
@@ -236,6 +248,7 @@ function useRefetchableFragmentNode<
|
|
|
236
248
|
debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(
|
|
237
249
|
refetchQuery.request.variables,
|
|
238
250
|
fragmentRefPathInResponse,
|
|
251
|
+
identifierInfo?.identifierQueryVariableName,
|
|
239
252
|
environment,
|
|
240
253
|
);
|
|
241
254
|
}
|
|
@@ -342,7 +355,7 @@ function useRefetchableFragmentNode<
|
|
|
342
355
|
fragmentIdentifier,
|
|
343
356
|
fragmentNode,
|
|
344
357
|
fragmentRefPathInResponse,
|
|
345
|
-
|
|
358
|
+
identifierInfo,
|
|
346
359
|
loadQuery,
|
|
347
360
|
parentFragmentRef,
|
|
348
361
|
refetchableRequest,
|
|
@@ -378,20 +391,23 @@ function useRefetchFunction<TQuery: OperationType>(
|
|
|
378
391
|
fragmentIdentifier: string,
|
|
379
392
|
fragmentNode: ReaderFragment,
|
|
380
393
|
fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
|
|
381
|
-
|
|
394
|
+
identifierInfo: ?RefetchableIdentifierInfo,
|
|
382
395
|
loadQuery: LoaderFn<TQuery>,
|
|
383
396
|
parentFragmentRef: mixed,
|
|
384
397
|
refetchableRequest: ConcreteRequest,
|
|
385
398
|
): RefetchFn<TQuery, InternalOptions> {
|
|
386
399
|
const isMountedRef = useIsMountedRef();
|
|
387
400
|
const identifierValue =
|
|
388
|
-
identifierField != null &&
|
|
401
|
+
identifierInfo?.identifierField != null &&
|
|
389
402
|
fragmentData != null &&
|
|
390
403
|
typeof fragmentData === 'object'
|
|
391
|
-
? fragmentData[identifierField]
|
|
404
|
+
? fragmentData[identifierInfo.identifierField]
|
|
392
405
|
: null;
|
|
393
406
|
return useCallback(
|
|
394
|
-
(
|
|
407
|
+
(
|
|
408
|
+
providedRefetchVariables: VariablesOf<TQuery>,
|
|
409
|
+
options: void | InternalOptions,
|
|
410
|
+
) => {
|
|
395
411
|
// Bail out and warn if we're trying to refetch after the component
|
|
396
412
|
// has unmounted
|
|
397
413
|
if (isMountedRef.current !== true) {
|
|
@@ -452,8 +468,10 @@ function useRefetchFunction<TQuery: OperationType>(
|
|
|
452
468
|
// If the query needs an identifier value ('id' or similar) and one
|
|
453
469
|
// was not explicitly provided, read it from the fragment data.
|
|
454
470
|
if (
|
|
455
|
-
|
|
456
|
-
!providedRefetchVariables.hasOwnProperty(
|
|
471
|
+
identifierInfo != null &&
|
|
472
|
+
!providedRefetchVariables.hasOwnProperty(
|
|
473
|
+
identifierInfo.identifierQueryVariableName,
|
|
474
|
+
)
|
|
457
475
|
) {
|
|
458
476
|
// @refetchable fragments are guaranteed to have an `id` selection
|
|
459
477
|
// if the type is Node, implements Node, or is @fetchable. Double-check
|
|
@@ -463,11 +481,13 @@ function useRefetchFunction<TQuery: OperationType>(
|
|
|
463
481
|
false,
|
|
464
482
|
'Relay: Expected result to have a string ' +
|
|
465
483
|
'`%s` in order to refetch, got `%s`.',
|
|
466
|
-
identifierField,
|
|
484
|
+
identifierInfo.identifierField,
|
|
467
485
|
identifierValue,
|
|
468
486
|
);
|
|
469
487
|
}
|
|
470
|
-
(refetchVariables: $FlowFixMe)
|
|
488
|
+
(refetchVariables: $FlowFixMe)[
|
|
489
|
+
identifierInfo.identifierQueryVariableName
|
|
490
|
+
] = identifierValue;
|
|
471
491
|
}
|
|
472
492
|
|
|
473
493
|
const refetchQuery = createOperationDescriptor(
|
|
@@ -516,10 +536,11 @@ if (__DEV__) {
|
|
|
516
536
|
getInitialIDAndType(
|
|
517
537
|
memoRefetchVariables: ?Variables,
|
|
518
538
|
fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
|
|
539
|
+
identifierQueryVariableName: ?string,
|
|
519
540
|
environment: IEnvironment,
|
|
520
541
|
): ?DebugIDandTypename {
|
|
521
542
|
const {Record} = require('relay-runtime');
|
|
522
|
-
const id = memoRefetchVariables?.id;
|
|
543
|
+
const id = memoRefetchVariables?.[identifierQueryVariableName ?? 'id'];
|
|
523
544
|
if (
|
|
524
545
|
fragmentRefPathInResponse.length !== 1 ||
|
|
525
546
|
fragmentRefPathInResponse[0] !== 'node' ||
|
|
@@ -529,7 +550,7 @@ if (__DEV__) {
|
|
|
529
550
|
}
|
|
530
551
|
const recordSource = environment.getStore().getSource();
|
|
531
552
|
const record = recordSource.get(id);
|
|
532
|
-
const typename = record
|
|
553
|
+
const typename = record == null ? null : Record.getType(record);
|
|
533
554
|
if (typename == null) {
|
|
534
555
|
return null;
|
|
535
556
|
}
|
|
@@ -4,18 +4,18 @@
|
|
|
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 {IEnvironment} from 'relay-runtime';
|
|
15
15
|
|
|
16
|
+
const ReactRelayContext = require('./../ReactRelayContext');
|
|
16
17
|
const invariant = require('invariant');
|
|
17
18
|
const {useContext} = require('react');
|
|
18
|
-
const ReactRelayContext = require('react-relay/ReactRelayContext');
|
|
19
19
|
|
|
20
20
|
function useRelayEnvironment(): IEnvironment {
|
|
21
21
|
const context = useContext(ReactRelayContext);
|
|
@@ -4,16 +4,16 @@
|
|
|
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 {ReaderFragment} from 'relay-runtime';
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
|
17
17
|
const warning = require('warning');
|
|
18
18
|
|
|
19
19
|
function useStaticFragmentNodeWarning(
|
|
@@ -25,7 +25,7 @@ function useStaticFragmentNodeWarning(
|
|
|
25
25
|
// __DEV__ setting which shouldn't change. This allows us to only pay the
|
|
26
26
|
// cost of `useRef` in development mode to produce the warning.
|
|
27
27
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
28
|
-
const initialPropRef =
|
|
28
|
+
const initialPropRef = useUnsafeRef_DEPRECATED(fragmentNode.name);
|
|
29
29
|
warning(
|
|
30
30
|
initialPropRef.current === fragmentNode.name,
|
|
31
31
|
'Relay: The %s has to remain the same over the lifetime of a component. ' +
|
|
@@ -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';
|
|
@@ -30,7 +30,7 @@ function useSubscribeToInvalidationState(
|
|
|
30
30
|
callback: () => void,
|
|
31
31
|
): Disposable {
|
|
32
32
|
const environment = useRelayEnvironment();
|
|
33
|
-
const disposableRef = useRef(null);
|
|
33
|
+
const disposableRef = useRef<null | Disposable>(null);
|
|
34
34
|
|
|
35
35
|
const stableDataIDs = Array.from(dataIDs).sort().join('');
|
|
36
36
|
useEffect(() => {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @flow
|
|
8
8
|
* @format
|
|
9
|
+
* @oncall relay
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
'use strict';
|
|
@@ -45,7 +46,6 @@ function useSubscription<TVariables, TData, TRawResponse>(
|
|
|
45
46
|
useEffect(() => {
|
|
46
47
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
47
48
|
const {dispose} = actualRequestSubscription(environment, config);
|
|
48
|
-
// $FlowFixMe[incompatible-call]
|
|
49
49
|
return dispose;
|
|
50
50
|
}, [environment, config, actualRequestSubscription]);
|
|
51
51
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
const {useMemo} = require('react');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Like `useRef`, but does not warn when accessed during render. It's a bad
|
|
18
|
+
* pattern to read or write from a ref during render as it does not trigger
|
|
19
|
+
* a rerender and might result in bugs.
|
|
20
|
+
*/
|
|
21
|
+
function useUnsafeRef_DEPRECATED<T>(init: T): {current: T} {
|
|
22
|
+
return useMemo<{current: T}>(() => ({current: init}), []);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = useUnsafeRef_DEPRECATED;
|
package/lib/readContext.js
DELETED
|
@@ -1,27 +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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
var React = require('react'); // $FlowFixMe[incompatible-use]
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _React$__SECRET_INTER =
|
|
16
|
-
/* $FlowFixMe[prop-missing] Flow doesn't know about React's internals for
|
|
17
|
-
* good reason, but for now, Relay needs the dispatcher to read context. */
|
|
18
|
-
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
|
19
|
-
ReactCurrentDispatcher = _React$__SECRET_INTER.ReactCurrentDispatcher,
|
|
20
|
-
ReactCurrentOwner = _React$__SECRET_INTER.ReactCurrentOwner;
|
|
21
|
-
|
|
22
|
-
function readContext(Context) {
|
|
23
|
-
var dispatcher = ReactCurrentDispatcher != null ? ReactCurrentDispatcher.current : ReactCurrentOwner.currentDispatcher;
|
|
24
|
-
return dispatcher.readContext(Context);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = readContext;
|
package/readContext.js.flow
DELETED
|
@@ -1,29 +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
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
const React = require('react');
|
|
14
|
-
|
|
15
|
-
// $FlowFixMe[incompatible-use]
|
|
16
|
-
const {ReactCurrentDispatcher, ReactCurrentOwner} =
|
|
17
|
-
/* $FlowFixMe[prop-missing] Flow doesn't know about React's internals for
|
|
18
|
-
* good reason, but for now, Relay needs the dispatcher to read context. */
|
|
19
|
-
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
20
|
-
|
|
21
|
-
function readContext<T>(Context: React.Context<T>): T {
|
|
22
|
-
const dispatcher =
|
|
23
|
-
ReactCurrentDispatcher != null
|
|
24
|
-
? ReactCurrentDispatcher.current
|
|
25
|
-
: ReactCurrentOwner.currentDispatcher;
|
|
26
|
-
return dispatcher.readContext(Context);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = readContext;
|