react-relay 14.0.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
@@ -4,13 +4,11 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
@@ -19,9 +17,10 @@ import type {
|
|
19
17
|
PreloadedQuery,
|
20
18
|
} from './EntryPointTypes.flow';
|
21
19
|
import type {
|
22
|
-
GraphQLTaggedNode,
|
23
20
|
IEnvironment,
|
24
21
|
OperationType,
|
22
|
+
Query,
|
23
|
+
Variables,
|
25
24
|
} from 'relay-runtime';
|
26
25
|
|
27
26
|
const {loadQuery, useTrackLoadQueryInRender} = require('./loadQuery');
|
@@ -35,39 +34,104 @@ export type LoaderFn<TQuery: OperationType> = (
|
|
35
34
|
options?: UseQueryLoaderLoadQueryOptions,
|
36
35
|
) => void;
|
37
36
|
|
38
|
-
export type UseQueryLoaderLoadQueryOptions = $ReadOnly<{
|
37
|
+
export type UseQueryLoaderLoadQueryOptions = $ReadOnly<{
|
39
38
|
...LoadQueryOptions,
|
40
39
|
+__environment?: ?IEnvironment,
|
41
|
-
|
42
|
-
|
43
|
-
type UseQueryLoaderHookReturnType<TQuery: OperationType> = [
|
44
|
-
?PreloadedQuery<TQuery>,
|
45
|
-
LoaderFn<TQuery>,
|
46
|
-
() => void,
|
47
|
-
];
|
40
|
+
}>;
|
48
41
|
|
49
42
|
// NullQueryReference needs to implement referential equality,
|
50
43
|
// so that multiple NullQueryReferences can be in the same set
|
51
44
|
// (corresponding to multiple calls to disposeQuery).
|
52
|
-
type NullQueryReference = {
|
45
|
+
type NullQueryReference = {
|
53
46
|
kind: 'NullQueryReference',
|
54
|
-
|
47
|
+
};
|
55
48
|
const initialNullQueryReferenceState = {kind: 'NullQueryReference'};
|
56
49
|
|
57
|
-
function requestIsLiveQuery<
|
58
|
-
|
50
|
+
function requestIsLiveQuery<
|
51
|
+
TVariables: Variables,
|
52
|
+
TData,
|
53
|
+
TRawResponse: ?{...} = void,
|
54
|
+
TQuery: OperationType = {
|
55
|
+
response: TData,
|
56
|
+
variables: TVariables,
|
57
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
58
|
+
},
|
59
|
+
>(
|
60
|
+
preloadableRequest:
|
61
|
+
| Query<TVariables, TData, TRawResponse>
|
62
|
+
| PreloadableConcreteRequest<TQuery>,
|
59
63
|
): boolean {
|
60
64
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
61
|
-
return
|
65
|
+
return preloadableRequest.params.metadata.live !== undefined;
|
62
66
|
}
|
63
67
|
const request = getRequest(preloadableRequest);
|
64
68
|
return request.params.metadata.live !== undefined;
|
65
69
|
}
|
66
70
|
|
67
|
-
|
68
|
-
|
71
|
+
type UseQueryLoaderHookReturnType<
|
72
|
+
TVariables: Variables,
|
73
|
+
TData,
|
74
|
+
TRawResponse: ?{...} = void,
|
75
|
+
> = [
|
76
|
+
?PreloadedQuery<{
|
77
|
+
response: TData,
|
78
|
+
variables: TVariables,
|
79
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
80
|
+
}>,
|
81
|
+
(variables: TVariables, options?: UseQueryLoaderLoadQueryOptions) => void,
|
82
|
+
() => void,
|
83
|
+
];
|
84
|
+
|
85
|
+
type ExtractVariablesType = <T>({+variables: T, ...}) => T;
|
86
|
+
type ExtractResponseType = <T>({+response: T, ...}) => T;
|
87
|
+
|
88
|
+
declare function useQueryLoader<
|
89
|
+
TVariables: Variables,
|
90
|
+
TData,
|
91
|
+
TRawResponse: ?{...} = void,
|
92
|
+
>(
|
93
|
+
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
94
|
+
): UseQueryLoaderHookReturnType<TVariables, TData>;
|
95
|
+
|
96
|
+
declare function useQueryLoader<
|
97
|
+
TVariables: Variables,
|
98
|
+
TData,
|
99
|
+
TRawResponse: ?{...} = void,
|
100
|
+
>(
|
101
|
+
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
102
|
+
initialQueryReference: ?PreloadedQuery<{
|
103
|
+
response: TData,
|
104
|
+
variables: TVariables,
|
105
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
106
|
+
}>,
|
107
|
+
): UseQueryLoaderHookReturnType<TVariables, TData>;
|
108
|
+
|
109
|
+
declare function useQueryLoader<TQuery: OperationType>(
|
110
|
+
preloadableRequest: PreloadableConcreteRequest<TQuery>,
|
69
111
|
initialQueryReference?: ?PreloadedQuery<TQuery>,
|
70
|
-
): UseQueryLoaderHookReturnType<
|
112
|
+
): UseQueryLoaderHookReturnType<
|
113
|
+
$Call<ExtractVariablesType, TQuery>,
|
114
|
+
$Call<ExtractResponseType, TQuery>,
|
115
|
+
>;
|
116
|
+
|
117
|
+
function useQueryLoader<
|
118
|
+
TVariables: Variables,
|
119
|
+
TData,
|
120
|
+
TRawResponse: ?{...} = void,
|
121
|
+
>(
|
122
|
+
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
123
|
+
initialQueryReference?: ?PreloadedQuery<{
|
124
|
+
response: TData,
|
125
|
+
variables: TVariables,
|
126
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
127
|
+
}>,
|
128
|
+
): UseQueryLoaderHookReturnType<TVariables, TData> {
|
129
|
+
type QueryType = {
|
130
|
+
response: TData,
|
131
|
+
variables: TVariables,
|
132
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
133
|
+
};
|
134
|
+
|
71
135
|
/**
|
72
136
|
* We want to always call `queryReference.dispose()` for every call to
|
73
137
|
* `setQueryReference(loadQuery(...))` so that no leaks of data in Relay stores
|
@@ -96,15 +160,15 @@ function useQueryLoader<TQuery: OperationType>(
|
|
96
160
|
|
97
161
|
const isMountedRef = useIsMountedRef();
|
98
162
|
const undisposedQueryReferencesRef = useRef<
|
99
|
-
Set<PreloadedQuery<
|
163
|
+
Set<PreloadedQuery<QueryType> | NullQueryReference>,
|
100
164
|
>(new Set([initialQueryReferenceInternal]));
|
101
165
|
|
102
166
|
const [queryReference, setQueryReference] = useState<
|
103
|
-
PreloadedQuery<
|
167
|
+
PreloadedQuery<QueryType> | NullQueryReference,
|
104
168
|
>(() => initialQueryReferenceInternal);
|
105
169
|
|
106
170
|
const [previousInitialQueryReference, setPreviousInitialQueryReference] =
|
107
|
-
useState<PreloadedQuery<
|
171
|
+
useState<PreloadedQuery<QueryType> | NullQueryReference>(
|
108
172
|
() => initialQueryReferenceInternal,
|
109
173
|
);
|
110
174
|
|
@@ -127,10 +191,7 @@ function useQueryLoader<TQuery: OperationType>(
|
|
127
191
|
}, [isMountedRef]);
|
128
192
|
|
129
193
|
const queryLoaderCallback = useCallback(
|
130
|
-
(
|
131
|
-
variables: TQuery['variables'],
|
132
|
-
options?: ?UseQueryLoaderLoadQueryOptions,
|
133
|
-
) => {
|
194
|
+
(variables: TVariables, options?: ?UseQueryLoaderLoadQueryOptions) => {
|
134
195
|
const mergedOptions: ?UseQueryLoaderLoadQueryOptions =
|
135
196
|
options != null && options.hasOwnProperty('__environment')
|
136
197
|
? {
|
@@ -140,7 +201,7 @@ function useQueryLoader<TQuery: OperationType>(
|
|
140
201
|
}
|
141
202
|
: options;
|
142
203
|
if (isMountedRef.current) {
|
143
|
-
const updatedQueryReference = loadQuery(
|
204
|
+
const updatedQueryReference = loadQuery<QueryType>(
|
144
205
|
options?.__environment ?? environment,
|
145
206
|
preloadableRequest,
|
146
207
|
variables,
|
@@ -4,64 +4,124 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
|
-
import type {
|
14
|
+
import type {Options} from './useRefetchableFragmentNode';
|
17
15
|
import type {
|
16
|
+
Disposable,
|
18
17
|
FragmentType,
|
19
|
-
|
20
|
-
|
18
|
+
RefetchableFragment,
|
19
|
+
Variables,
|
21
20
|
} from 'relay-runtime';
|
22
21
|
|
22
|
+
const HooksImplementation = require('./HooksImplementation');
|
23
23
|
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
24
24
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
25
25
|
const {useDebugValue} = require('react');
|
26
26
|
const {getFragment} = require('relay-runtime');
|
27
27
|
|
28
|
-
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, ... }) => $Shape<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
|
+
type ReturnType<TVariables, TData, TKey> = [
|
29
50
|
// NOTE: This $Call ensures that the type of the returned data is either:
|
30
51
|
// - nullable if the provided ref type is nullable
|
31
52
|
// - non-nullable if the provided ref type is non-nullable
|
32
53
|
// prettier-ignore
|
33
54
|
$Call<
|
34
|
-
& (<
|
35
|
-
& (<
|
55
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
|
56
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
|
36
57
|
TKey,
|
37
58
|
>,
|
38
|
-
|
59
|
+
RefetchFn<TVariables, TKey>,
|
39
60
|
];
|
40
61
|
|
41
|
-
|
42
|
-
|
43
|
-
|
62
|
+
export type UseRefetchableFragmentType = <
|
63
|
+
TFragmentType: FragmentType,
|
64
|
+
TVariables: Variables,
|
65
|
+
TData,
|
66
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
44
67
|
>(
|
45
|
-
|
68
|
+
fragment: RefetchableFragment<TFragmentType, TData, TVariables>,
|
69
|
+
key: TKey,
|
70
|
+
) => ReturnType<TVariables, TData, TKey>;
|
71
|
+
|
72
|
+
function useRefetchableFragment_LEGACY<
|
73
|
+
TFragmentType: FragmentType,
|
74
|
+
TVariables: Variables,
|
75
|
+
TData,
|
76
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
77
|
+
>(
|
78
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
46
79
|
fragmentRef: TKey,
|
47
|
-
): ReturnType<
|
80
|
+
): ReturnType<TVariables, TData, TKey> {
|
48
81
|
const fragmentNode = getFragment(fragmentInput);
|
49
82
|
useStaticFragmentNodeWarning(
|
50
83
|
fragmentNode,
|
51
84
|
'first argument of useRefetchableFragment()',
|
52
85
|
);
|
53
|
-
const {fragmentData, refetch} = useRefetchableFragmentNode<
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
86
|
+
const {fragmentData, refetch} = useRefetchableFragmentNode<
|
87
|
+
{
|
88
|
+
response: TData,
|
89
|
+
variables: TVariables,
|
90
|
+
},
|
91
|
+
{
|
92
|
+
+$data: mixed,
|
93
|
+
...
|
94
|
+
},
|
95
|
+
>(fragmentNode, fragmentRef, 'useRefetchableFragment()');
|
58
96
|
if (__DEV__) {
|
59
97
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
60
98
|
useDebugValue({fragment: fragmentNode.name, data: fragmentData});
|
61
99
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
100
|
+
|
101
|
+
// $FlowFixMe[incompatible-return]
|
102
|
+
// $FlowFixMe[prop-missing]
|
103
|
+
return [fragmentData, refetch];
|
104
|
+
}
|
105
|
+
|
106
|
+
function useRefetchableFragment<
|
107
|
+
TFragmentType: FragmentType,
|
108
|
+
TVariables: Variables,
|
109
|
+
TData,
|
110
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
111
|
+
>(
|
112
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
113
|
+
parentFragmentRef: TKey,
|
114
|
+
): ReturnType<TVariables, TData, TKey> {
|
115
|
+
const impl = HooksImplementation.get();
|
116
|
+
if (impl) {
|
117
|
+
return impl.useRefetchableFragment<TFragmentType, TVariables, TData, TKey>(
|
118
|
+
fragmentInput,
|
119
|
+
parentFragmentRef,
|
120
|
+
);
|
121
|
+
} else {
|
122
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
123
|
+
return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
|
124
|
+
}
|
65
125
|
}
|
66
126
|
|
67
127
|
module.exports = useRefetchableFragment;
|
@@ -4,13 +4,11 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {LoaderFn} from './useQueryLoader';
|
@@ -71,24 +69,24 @@ export type ReturnType<
|
|
71
69
|
TQuery: OperationType,
|
72
70
|
TKey: ?{+$data?: mixed, ...},
|
73
71
|
TOptions = Options,
|
74
|
-
> = {
|
72
|
+
> = {
|
75
73
|
fragmentData: mixed,
|
76
74
|
fragmentRef: mixed,
|
77
75
|
refetch: RefetchFnDynamic<TQuery, TKey, TOptions>,
|
78
76
|
disableStoreUpdates: () => void,
|
79
77
|
enableStoreUpdates: () => void,
|
80
|
-
|
78
|
+
};
|
81
79
|
|
82
|
-
export type Options = {
|
80
|
+
export type Options = {
|
83
81
|
fetchPolicy?: FetchPolicy,
|
84
82
|
onComplete?: (Error | null) => void,
|
85
83
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
86
|
-
|
84
|
+
};
|
87
85
|
|
88
|
-
type InternalOptions = {
|
86
|
+
type InternalOptions = {
|
89
87
|
...Options,
|
90
88
|
__environment?: IEnvironment,
|
91
|
-
|
89
|
+
};
|
92
90
|
|
93
91
|
type RefetchFnBase<TVars, TOptions> = (
|
94
92
|
vars: TVars,
|
@@ -105,21 +103,21 @@ type RefetchFnInexact<
|
|
105
103
|
> = RefetchFnBase<$Shape<VariablesOf<TQuery>>, TOptions>;
|
106
104
|
|
107
105
|
type Action =
|
108
|
-
| {
|
106
|
+
| {
|
109
107
|
type: 'reset',
|
110
108
|
environment: IEnvironment,
|
111
109
|
fragmentIdentifier: string,
|
112
|
-
|
113
|
-
| {
|
110
|
+
}
|
111
|
+
| {
|
114
112
|
type: 'refetch',
|
115
113
|
refetchQuery: OperationDescriptor,
|
116
114
|
fetchPolicy?: FetchPolicy,
|
117
115
|
renderPolicy?: RenderPolicy,
|
118
116
|
onComplete?: (Error | null) => void,
|
119
117
|
refetchEnvironment: ?IEnvironment,
|
120
|
-
|
118
|
+
};
|
121
119
|
|
122
|
-
type RefetchState = {
|
120
|
+
type RefetchState = {
|
123
121
|
fetchPolicy: FetchPolicy | void,
|
124
122
|
mirroredEnvironment: IEnvironment,
|
125
123
|
mirroredFragmentIdentifier: string,
|
@@ -127,7 +125,7 @@ type RefetchState = {|
|
|
127
125
|
refetchEnvironment?: ?IEnvironment,
|
128
126
|
refetchQuery: OperationDescriptor | null,
|
129
127
|
renderPolicy: RenderPolicy | void,
|
130
|
-
|
128
|
+
};
|
131
129
|
|
132
130
|
type DebugIDandTypename = {
|
133
131
|
id: string,
|
@@ -209,8 +207,11 @@ function useRefetchableFragmentNode<
|
|
209
207
|
const shouldReset =
|
210
208
|
environment !== mirroredEnvironment ||
|
211
209
|
fragmentIdentifier !== mirroredFragmentIdentifier;
|
212
|
-
const [queryRef, loadQuery, disposeQuery] =
|
213
|
-
|
210
|
+
const [queryRef, loadQuery, disposeQuery] = useQueryLoader<
|
211
|
+
TQuery['variables'],
|
212
|
+
TQuery['response'],
|
213
|
+
TQuery['rawResponse'],
|
214
|
+
>((refetchableRequest: $FlowFixMe));
|
214
215
|
|
215
216
|
let fragmentRef = parentFragmentRef;
|
216
217
|
if (shouldReset) {
|
@@ -361,19 +362,19 @@ function useRefetchableFragmentNode<
|
|
361
362
|
function useRefetchFunction<TQuery: OperationType>(
|
362
363
|
componentDisplayName: string,
|
363
364
|
dispatch: (
|
364
|
-
| {
|
365
|
+
| {
|
365
366
|
environment: IEnvironment,
|
366
367
|
fragmentIdentifier: string,
|
367
368
|
type: 'reset',
|
368
|
-
|
369
|
-
| {
|
369
|
+
}
|
370
|
+
| {
|
370
371
|
fetchPolicy?: FetchPolicy,
|
371
372
|
onComplete?: (Error | null) => void,
|
372
373
|
refetchEnvironment: ?IEnvironment,
|
373
374
|
refetchQuery: OperationDescriptor,
|
374
375
|
renderPolicy?: RenderPolicy,
|
375
376
|
type: 'refetch',
|
376
|
-
|
377
|
+
},
|
377
378
|
) => void,
|
378
379
|
disposeQuery: () => void,
|
379
380
|
fragmentData: mixed,
|
@@ -393,7 +394,10 @@ function useRefetchFunction<TQuery: OperationType>(
|
|
393
394
|
? fragmentData[identifierField]
|
394
395
|
: null;
|
395
396
|
return useCallback(
|
396
|
-
(
|
397
|
+
(
|
398
|
+
providedRefetchVariables: VariablesOf<TQuery>,
|
399
|
+
options: void | InternalOptions,
|
400
|
+
) => {
|
397
401
|
// Bail out and warn if we're trying to refetch after the component
|
398
402
|
// has unmounted
|
399
403
|
if (isMountedRef.current !== true) {
|
@@ -4,20 +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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {IEnvironment} from 'relay-runtime';
|
17
15
|
|
16
|
+
const ReactRelayContext = require('./../ReactRelayContext');
|
18
17
|
const invariant = require('invariant');
|
19
18
|
const {useContext} = require('react');
|
20
|
-
const ReactRelayContext = require('react-relay/ReactRelayContext');
|
21
19
|
|
22
20
|
function useRelayEnvironment(): IEnvironment {
|
23
21
|
const context = useContext(ReactRelayContext);
|
@@ -4,18 +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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {ReaderFragment} from 'relay-runtime';
|
17
15
|
|
18
|
-
const
|
16
|
+
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
19
17
|
const warning = require('warning');
|
20
18
|
|
21
19
|
function useStaticFragmentNodeWarning(
|
@@ -27,7 +25,7 @@ function useStaticFragmentNodeWarning(
|
|
27
25
|
// __DEV__ setting which shouldn't change. This allows us to only pay the
|
28
26
|
// cost of `useRef` in development mode to produce the warning.
|
29
27
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
30
|
-
const initialPropRef =
|
28
|
+
const initialPropRef = useUnsafeRef_DEPRECATED(fragmentNode.name);
|
31
29
|
warning(
|
32
30
|
initialPropRef.current === fragmentNode.name,
|
33
31
|
'Relay: The %s has to remain the same over the lifetime of a component. ' +
|
@@ -4,13 +4,11 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {DataID, Disposable} from 'relay-runtime';
|
@@ -32,7 +30,7 @@ function useSubscribeToInvalidationState(
|
|
32
30
|
callback: () => void,
|
33
31
|
): Disposable {
|
34
32
|
const environment = useRelayEnvironment();
|
35
|
-
const disposableRef = useRef(null);
|
33
|
+
const disposableRef = useRef<null | Disposable>(null);
|
36
34
|
|
37
35
|
const stableDataIDs = Array.from(dataIDs).sort().join('');
|
38
36
|
useEffect(() => {
|
@@ -6,10 +6,9 @@
|
|
6
6
|
*
|
7
7
|
* @flow
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
11
|
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
12
|
'use strict';
|
14
13
|
|
15
14
|
import type {
|
@@ -47,7 +46,6 @@ function useSubscription<TVariables, TData, TRawResponse>(
|
|
47
46
|
useEffect(() => {
|
48
47
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
49
48
|
const {dispose} = actualRequestSubscription(environment, config);
|
50
|
-
// $FlowFixMe[incompatible-call]
|
51
49
|
return dispose;
|
52
50
|
}, [environment, config, actualRequestSubscription]);
|
53
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,28 +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
|
-
// flowlint ambiguous-object-type:error
|
11
|
-
'use strict';
|
12
|
-
|
13
|
-
var React = require('react'); // $FlowFixMe[incompatible-use]
|
14
|
-
|
15
|
-
|
16
|
-
var _React$__SECRET_INTER =
|
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
|
-
ReactCurrentDispatcher = _React$__SECRET_INTER.ReactCurrentDispatcher,
|
21
|
-
ReactCurrentOwner = _React$__SECRET_INTER.ReactCurrentOwner;
|
22
|
-
|
23
|
-
function readContext(Context) {
|
24
|
-
var dispatcher = ReactCurrentDispatcher != null ? ReactCurrentDispatcher.current : ReactCurrentOwner.currentDispatcher;
|
25
|
-
return dispatcher.readContext(Context);
|
26
|
-
}
|
27
|
-
|
28
|
-
module.exports = readContext;
|
package/readContext.js.flow
DELETED
@@ -1,31 +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
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
const React = require('react');
|
16
|
-
|
17
|
-
// $FlowFixMe[incompatible-use]
|
18
|
-
const {ReactCurrentDispatcher, ReactCurrentOwner} =
|
19
|
-
/* $FlowFixMe[prop-missing] Flow doesn't know about React's internals for
|
20
|
-
* good reason, but for now, Relay needs the dispatcher to read context. */
|
21
|
-
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
22
|
-
|
23
|
-
function readContext<T>(Context: React.Context<T>): T {
|
24
|
-
const dispatcher =
|
25
|
-
ReactCurrentDispatcher != null
|
26
|
-
? ReactCurrentDispatcher.current
|
27
|
-
: ReactCurrentOwner.currentDispatcher;
|
28
|
-
return dispatcher.readContext(Context);
|
29
|
-
}
|
30
|
-
|
31
|
-
module.exports = readContext;
|