react-relay 16.2.0 → 18.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +2 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -1
- package/ReactRelayFragmentContainer.js.flow +10 -8
- package/ReactRelayLocalQueryRenderer.js.flow +4 -1
- package/ReactRelayPaginationContainer.js.flow +4 -2
- package/ReactRelayQueryRenderer.js.flow +2 -2
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +2 -2
- package/ReactRelayTypes.js.flow +45 -18
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +10 -8
- package/getRootVariablesForFragments.js.flow +1 -0
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +2 -2
- package/lib/buildReactRelayContainer.js +3 -3
- package/lib/relay-hooks/legacy/FragmentResource.js +14 -16
- package/lib/relay-hooks/loadEntryPoint.js +8 -5
- package/lib/relay-hooks/loadQuery.js +2 -14
- package/lib/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js → readFragmentInternal.js} +7 -5
- package/lib/relay-hooks/useEntryPointLoader.js +5 -8
- package/lib/relay-hooks/useFragment.js +7 -20
- package/lib/relay-hooks/useFragmentInternal.js +13 -0
- package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal_CURRENT.js} +12 -18
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +520 -0
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
- package/lib/relay-hooks/useLazyLoadQueryNode.js +2 -13
- package/lib/relay-hooks/usePaginationFragment.js +17 -13
- package/lib/relay-hooks/usePreloadedQuery.js +6 -9
- package/lib/relay-hooks/useQueryLoader.js +1 -3
- package/lib/relay-hooks/useRefetchableFragment.js +3 -12
- package/lib/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js → useRefetchableFragmentInternal.js} +7 -7
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +1 -1
- package/package.json +3 -3
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointTypes.flow.js.flow +49 -25
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +22 -5
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +21 -0
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +19 -0
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +22 -0
- package/relay-hooks/legacy/FragmentResource.js.flow +13 -16
- package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +2 -2
- package/relay-hooks/legacy/useFragmentNode.js.flow +1 -1
- package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +2 -2
- package/relay-hooks/loadEntryPoint.js.flow +10 -4
- package/relay-hooks/loadQuery.js.flow +10 -33
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
- package/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js.flow → readFragmentInternal.js.flow} +6 -4
- package/relay-hooks/useClientQuery.js.flow +1 -1
- package/relay-hooks/useEntryPointLoader.js.flow +4 -5
- package/relay-hooks/useFetchTrackingRef.js.flow +1 -1
- package/relay-hooks/useFragment.js.flow +8 -25
- package/relay-hooks/useFragmentInternal.js.flow +45 -0
- package/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js.flow → useFragmentInternal_CURRENT.js.flow} +14 -5
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +764 -0
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +5 -2
- package/relay-hooks/useLazyLoadQuery.js.flow +3 -7
- package/relay-hooks/useLazyLoadQueryNode.js.flow +3 -19
- package/relay-hooks/useLoadMoreFunction.js.flow +1 -1
- package/relay-hooks/useMemoOperationDescriptor.js.flow +1 -1
- package/relay-hooks/useMemoVariables.js.flow +1 -1
- package/relay-hooks/useMutation.js.flow +1 -1
- package/relay-hooks/usePaginationFragment.js.flow +62 -50
- package/relay-hooks/usePreloadedQuery.js.flow +2 -6
- package/relay-hooks/useQueryLoader.js.flow +3 -7
- package/relay-hooks/useRefetchableFragment.js.flow +7 -37
- package/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow → useRefetchableFragmentInternal.js.flow} +11 -11
- package/relay-hooks/useRelayEnvironment.js.flow +1 -1
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -1
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +1 -1
- package/lib/relay-hooks/HooksImplementation.js +0 -15
- package/lib/relay-hooks/experimental/useFragment_EXPERIMENTAL.js +0 -26
- package/lib/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js +0 -127
- package/lib/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js +0 -23
- package/relay-hooks/HooksImplementation.js.flow +0 -45
- package/relay-hooks/experimental/useFragment_EXPERIMENTAL.js.flow +0 -72
- package/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js.flow +0 -161
- package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +0 -49
@@ -17,9 +17,12 @@ const useIsOperationNodeActive = require('./useIsOperationNodeActive');
|
|
17
17
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
18
18
|
const {getFragment} = require('relay-runtime');
|
19
19
|
|
20
|
-
|
20
|
+
hook useIsParentQueryActive<
|
21
21
|
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
22
|
-
>(
|
22
|
+
>(
|
23
|
+
fragmentInput: GraphQLTaggedNode,
|
24
|
+
fragmentRef: TKey,
|
25
|
+
): boolean {
|
23
26
|
const fragmentNode = getFragment(fragmentInput);
|
24
27
|
useStaticFragmentNodeWarning(
|
25
28
|
fragmentNode,
|
@@ -19,7 +19,6 @@ import type {
|
|
19
19
|
Variables,
|
20
20
|
} from 'relay-runtime';
|
21
21
|
|
22
|
-
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
23
22
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
24
23
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
25
24
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
@@ -30,7 +29,7 @@ const {
|
|
30
29
|
// This separate type export is only needed as long as we are injecting
|
31
30
|
// a separate hooks implementation in ./HooksImplementation -- it can
|
32
31
|
// be removed after we stop doing that.
|
33
|
-
export type UseLazyLoadQueryHookType = <TVariables: Variables, TData>(
|
32
|
+
export type UseLazyLoadQueryHookType = hook <TVariables: Variables, TData>(
|
34
33
|
gqlQuery: Query<TVariables, TData>,
|
35
34
|
variables: TVariables,
|
36
35
|
options?: {
|
@@ -41,7 +40,7 @@ export type UseLazyLoadQueryHookType = <TVariables: Variables, TData>(
|
|
41
40
|
},
|
42
41
|
) => TData;
|
43
42
|
|
44
|
-
|
43
|
+
hook useLazyLoadQuery<TVariables: Variables, TData>(
|
45
44
|
gqlQuery: Query<TVariables, TData>,
|
46
45
|
variables: TVariables,
|
47
46
|
options?: {
|
@@ -51,10 +50,6 @@ function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
51
50
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
52
51
|
},
|
53
52
|
): TData {
|
54
|
-
// We need to use this hook in order to be able to track if
|
55
|
-
// loadQuery was called during render
|
56
|
-
useTrackLoadQueryInRender();
|
57
|
-
|
58
53
|
const environment = useRelayEnvironment();
|
59
54
|
|
60
55
|
const query = useMemoOperationDescriptor(
|
@@ -75,4 +70,5 @@ function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
75
70
|
return data;
|
76
71
|
}
|
77
72
|
|
73
|
+
// $FlowFixMe[react-rule-hook-incompatible]
|
78
74
|
module.exports = (useLazyLoadQuery: UseLazyLoadQueryHookType);
|
@@ -19,22 +19,20 @@ import type {
|
|
19
19
|
OperationType,
|
20
20
|
RenderPolicy,
|
21
21
|
} from 'relay-runtime';
|
22
|
-
import type {ReaderFragment} from 'relay-runtime/util/ReaderNode';
|
23
22
|
|
24
|
-
const HooksImplementation = require('./HooksImplementation');
|
25
|
-
const useFragmentNode = require('./legacy/useFragmentNode');
|
26
23
|
const ProfilerContext = require('./ProfilerContext');
|
27
24
|
const {
|
28
25
|
getQueryCacheIdentifier,
|
29
26
|
getQueryResourceForEnvironment,
|
30
27
|
} = require('./QueryResource');
|
31
28
|
const useFetchTrackingRef = require('./useFetchTrackingRef');
|
29
|
+
const useFragmentInternal = require('./useFragmentInternal');
|
32
30
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
33
31
|
const React = require('react');
|
34
32
|
|
35
33
|
const {useContext, useEffect, useState, useRef} = React;
|
36
34
|
|
37
|
-
|
35
|
+
hook useLazyLoadQueryNode<TQuery: OperationType>({
|
38
36
|
query,
|
39
37
|
componentDisplayName,
|
40
38
|
fetchObservable,
|
@@ -127,7 +125,7 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
|
|
127
125
|
});
|
128
126
|
|
129
127
|
const {fragmentNode, fragmentRef} = preparedQueryResult;
|
130
|
-
const data =
|
128
|
+
const data = useFragmentInternal(
|
131
129
|
fragmentNode,
|
132
130
|
fragmentRef,
|
133
131
|
componentDisplayName,
|
@@ -135,18 +133,4 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
|
|
135
133
|
return data;
|
136
134
|
}
|
137
135
|
|
138
|
-
function useFragmentNodeImpl(
|
139
|
-
fragment: ReaderFragment,
|
140
|
-
key: mixed,
|
141
|
-
componentDisplayName: string,
|
142
|
-
): mixed {
|
143
|
-
const impl = HooksImplementation.get();
|
144
|
-
if (impl && impl.useFragment__internal) {
|
145
|
-
return impl.useFragment__internal(fragment, key, componentDisplayName);
|
146
|
-
} else {
|
147
|
-
const {data} = useFragmentNode<mixed>(fragment, key, componentDisplayName);
|
148
|
-
return data;
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
136
|
module.exports = useLazyLoadQueryNode;
|
@@ -61,7 +61,7 @@ export type UseLoadMoreFunctionArgs = {
|
|
61
61
|
onReset: () => void,
|
62
62
|
};
|
63
63
|
|
64
|
-
|
64
|
+
hook useLoadMoreFunction<TVariables: Variables>(
|
65
65
|
args: UseLoadMoreFunctionArgs,
|
66
66
|
): [LoadMoreFn<TVariables>, boolean, () => void] {
|
67
67
|
const {
|
@@ -24,7 +24,7 @@ const {createOperationDescriptor, getRequest} = require('relay-runtime');
|
|
24
24
|
|
25
25
|
const {useMemo} = React;
|
26
26
|
|
27
|
-
|
27
|
+
hook useMemoOperationDescriptor(
|
28
28
|
gqlQuery: GraphQLTaggedNode,
|
29
29
|
variables: Variables,
|
30
30
|
cacheConfig?: ?CacheConfig,
|
@@ -21,7 +21,7 @@ const {useState} = require('react');
|
|
21
21
|
* This is useful when a `variables` object is used as a value in a depencency
|
22
22
|
* array as it might often be constructed during render.
|
23
23
|
*/
|
24
|
-
|
24
|
+
hook useMemoVariables<TVariables: Variables | null>(
|
25
25
|
variables: TVariables,
|
26
26
|
): TVariables {
|
27
27
|
const [mirroredVariables, setMirroredVariables] = useState(variables);
|
@@ -64,7 +64,7 @@ type UseMutationConfigInternal<TVariables, TData, TRawResponse> = {
|
|
64
64
|
variables: TVariables,
|
65
65
|
};
|
66
66
|
|
67
|
-
|
67
|
+
hook useMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
68
68
|
mutation: Mutation<TVariables, TData, TRawResponse>,
|
69
69
|
commitMutationFn?: (
|
70
70
|
environment: IEnvironment,
|
@@ -11,10 +11,10 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
import type {Options} from './legacy/useRefetchableFragmentNode';
|
15
14
|
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
16
|
-
import type {
|
15
|
+
import type {Options} from './useRefetchableFragmentInternal';
|
17
16
|
import type {
|
17
|
+
Disposable,
|
18
18
|
FragmentType,
|
19
19
|
GraphQLResponse,
|
20
20
|
Observer,
|
@@ -22,9 +22,9 @@ import type {
|
|
22
22
|
Variables,
|
23
23
|
} from 'relay-runtime';
|
24
24
|
|
25
|
-
const HooksImplementation = require('./HooksImplementation');
|
26
|
-
const useRefetchableFragmentNode = require('./legacy/useRefetchableFragmentNode');
|
27
25
|
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
26
|
+
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal');
|
27
|
+
const useRelayEnvironment = require('./useRelayEnvironment');
|
28
28
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
29
29
|
const {useCallback, useDebugValue, useState} = require('react');
|
30
30
|
const {
|
@@ -33,6 +33,40 @@ const {
|
|
33
33
|
getPaginationMetadata,
|
34
34
|
} = require('relay-runtime');
|
35
35
|
|
36
|
+
type RefetchVariables<TVariables, TKey: ?{+$fragmentSpreads: mixed, ...}> =
|
37
|
+
// NOTE: This type ensures that the type of the returned variables is either:
|
38
|
+
// - nullable if the provided ref type is nullable
|
39
|
+
// - non-nullable if the provided ref type is non-nullable
|
40
|
+
[+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
|
41
|
+
? Partial<TVariables>
|
42
|
+
: TVariables;
|
43
|
+
|
44
|
+
type RefetchFnBase<TVars, TOptions> = (
|
45
|
+
vars: TVars,
|
46
|
+
options?: TOptions,
|
47
|
+
) => Disposable;
|
48
|
+
|
49
|
+
export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
|
50
|
+
RefetchVariables<TVariables, TKey>,
|
51
|
+
TOptions,
|
52
|
+
>;
|
53
|
+
|
54
|
+
export type ReturnType<TVariables, TData, TKey> = {
|
55
|
+
// NOTE: This type ensures that the type of the returned data is either:
|
56
|
+
// - nullable if the provided ref type is nullable
|
57
|
+
// - non-nullable if the provided ref type is non-nullable
|
58
|
+
data: [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
|
59
|
+
? TData
|
60
|
+
: ?TData,
|
61
|
+
loadNext: LoadMoreFn<TVariables>,
|
62
|
+
loadPrevious: LoadMoreFn<TVariables>,
|
63
|
+
hasNext: boolean,
|
64
|
+
hasPrevious: boolean,
|
65
|
+
isLoadingNext: boolean,
|
66
|
+
isLoadingPrevious: boolean,
|
67
|
+
refetch: RefetchFn<TVariables, TKey>,
|
68
|
+
};
|
69
|
+
|
36
70
|
// This separate type export is only needed as long as we are injecting
|
37
71
|
// a separate hooks implementation in ./HooksImplementation -- it can
|
38
72
|
// be removed after we stop doing that.
|
@@ -46,7 +80,7 @@ export type UsePaginationFragmentType = <
|
|
46
80
|
parentFragmentRef: TKey,
|
47
81
|
) => ReturnType<TVariables, TData, TKey>;
|
48
82
|
|
49
|
-
|
83
|
+
hook usePaginationFragment<
|
50
84
|
TFragmentType: FragmentType,
|
51
85
|
TVariables: Variables,
|
52
86
|
TData,
|
@@ -65,9 +99,9 @@ function usePaginationFragment_LEGACY<
|
|
65
99
|
const {connectionPathInFragmentData, paginationRequest, paginationMetadata} =
|
66
100
|
getPaginationMetadata(fragmentNode, componentDisplayName);
|
67
101
|
|
68
|
-
const {fragmentData, fragmentRef, refetch} =
|
69
|
-
|
70
|
-
|
102
|
+
const {fragmentData, fragmentRef, refetch} = useRefetchableFragmentInternal<
|
103
|
+
{variables: TVariables, response: TData},
|
104
|
+
{data?: TData},
|
71
105
|
>(fragmentNode, parentFragmentRef, componentDisplayName);
|
72
106
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
73
107
|
|
@@ -99,7 +133,7 @@ function usePaginationFragment_LEGACY<
|
|
99
133
|
paginationRequest,
|
100
134
|
});
|
101
135
|
|
102
|
-
const refetchPagination
|
136
|
+
const refetchPagination = useCallback(
|
103
137
|
(variables: TVariables, options: void | Options) => {
|
104
138
|
disposeFetchNext();
|
105
139
|
disposeFetchPrevious();
|
@@ -110,6 +144,7 @@ function usePaginationFragment_LEGACY<
|
|
110
144
|
|
111
145
|
if (__DEV__) {
|
112
146
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
147
|
+
// $FlowFixMe[react-rule-hook]
|
113
148
|
useDebugValue({
|
114
149
|
fragment: fragmentNode.name,
|
115
150
|
data: fragmentData,
|
@@ -120,7 +155,8 @@ function usePaginationFragment_LEGACY<
|
|
120
155
|
});
|
121
156
|
}
|
122
157
|
return {
|
123
|
-
|
158
|
+
// $FlowFixMe[incompatible-return]
|
159
|
+
data: fragmentData,
|
124
160
|
loadNext,
|
125
161
|
loadPrevious,
|
126
162
|
hasNext,
|
@@ -131,7 +167,7 @@ function usePaginationFragment_LEGACY<
|
|
131
167
|
};
|
132
168
|
}
|
133
169
|
|
134
|
-
|
170
|
+
hook useLoadMore<TVariables: Variables>(
|
135
171
|
args: $Diff<
|
136
172
|
UseLoadMoreFunctionArgs,
|
137
173
|
{
|
@@ -141,7 +177,21 @@ function useLoadMore<TVariables: Variables>(
|
|
141
177
|
},
|
142
178
|
>,
|
143
179
|
): [LoadMoreFn<TVariables>, boolean, boolean, () => void] {
|
144
|
-
const
|
180
|
+
const environment = useRelayEnvironment();
|
181
|
+
const [isLoadingMore, reallySetIsLoadingMore] = useState(false);
|
182
|
+
// Schedule this update since it must be observed by components at the same
|
183
|
+
// batch as when hasNext changes. hasNext is read from the store and store
|
184
|
+
// updates are scheduled, so this must be scheduled too.
|
185
|
+
const setIsLoadingMore = (value: boolean) => {
|
186
|
+
const schedule = environment.getScheduler()?.schedule;
|
187
|
+
if (schedule) {
|
188
|
+
schedule(() => {
|
189
|
+
reallySetIsLoadingMore(value);
|
190
|
+
});
|
191
|
+
} else {
|
192
|
+
reallySetIsLoadingMore(value);
|
193
|
+
}
|
194
|
+
};
|
145
195
|
const observer = {
|
146
196
|
start: () => setIsLoadingMore(true),
|
147
197
|
complete: () => setIsLoadingMore(false),
|
@@ -156,42 +206,4 @@ function useLoadMore<TVariables: Variables>(
|
|
156
206
|
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
157
207
|
}
|
158
208
|
|
159
|
-
export type ReturnType<TVariables, TData, TKey> = {
|
160
|
-
// NOTE: This type ensures that the type of the returned data is either:
|
161
|
-
// - nullable if the provided ref type is nullable
|
162
|
-
// - non-nullable if the provided ref type is non-nullable
|
163
|
-
data: [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
|
164
|
-
? TData
|
165
|
-
: ?TData,
|
166
|
-
loadNext: LoadMoreFn<TVariables>,
|
167
|
-
loadPrevious: LoadMoreFn<TVariables>,
|
168
|
-
hasNext: boolean,
|
169
|
-
hasPrevious: boolean,
|
170
|
-
isLoadingNext: boolean,
|
171
|
-
isLoadingPrevious: boolean,
|
172
|
-
refetch: RefetchFn<TVariables, TKey>,
|
173
|
-
};
|
174
|
-
|
175
|
-
function usePaginationFragment<
|
176
|
-
TFragmentType: FragmentType,
|
177
|
-
TVariables: Variables,
|
178
|
-
TData,
|
179
|
-
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
180
|
-
>(
|
181
|
-
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
182
|
-
parentFragmentRef: TKey,
|
183
|
-
): ReturnType<TVariables, TData, TKey> {
|
184
|
-
const impl = HooksImplementation.get();
|
185
|
-
if (impl) {
|
186
|
-
// $FlowExpectedError[incompatible-return] Flow cannot prove that two conditional type satisfy each other
|
187
|
-
return impl.usePaginationFragment<TFragmentType, TVariables, TData, TKey>(
|
188
|
-
fragmentInput,
|
189
|
-
parentFragmentRef,
|
190
|
-
);
|
191
|
-
} else {
|
192
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
193
|
-
return usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef);
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
209
|
module.exports = usePaginationFragment;
|
@@ -18,7 +18,6 @@ import type {
|
|
18
18
|
} from './EntryPointTypes.flow';
|
19
19
|
import type {Query, RenderPolicy, Variables} from 'relay-runtime';
|
20
20
|
|
21
|
-
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
22
21
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
23
22
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
24
23
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
@@ -52,7 +51,7 @@ type PreloadedQuery<
|
|
52
51
|
TEnvironmentProviderOptions,
|
53
52
|
>;
|
54
53
|
|
55
|
-
|
54
|
+
hook usePreloadedQuery<
|
56
55
|
TVariables: Variables,
|
57
56
|
TData,
|
58
57
|
TRawResponse: ?{...} = void,
|
@@ -67,10 +66,6 @@ function usePreloadedQuery<
|
|
67
66
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
68
67
|
},
|
69
68
|
): TData {
|
70
|
-
// We need to use this hook in order to be able to track if
|
71
|
-
// loadQuery was called during render
|
72
|
-
useTrackLoadQueryInRender();
|
73
|
-
|
74
69
|
const environment = useRelayEnvironment();
|
75
70
|
const {fetchKey, fetchPolicy, source, variables, networkCacheConfig} =
|
76
71
|
preloadedQuery;
|
@@ -164,6 +159,7 @@ function usePreloadedQuery<
|
|
164
159
|
|
165
160
|
if (__DEV__) {
|
166
161
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
162
|
+
// $FlowFixMe[react-rule-hook]
|
167
163
|
useDebugValue({
|
168
164
|
query: preloadedQuery.name,
|
169
165
|
variables: preloadedQuery.variables,
|
@@ -23,7 +23,7 @@ import type {
|
|
23
23
|
Variables,
|
24
24
|
} from 'relay-runtime';
|
25
25
|
|
26
|
-
const {loadQuery
|
26
|
+
const {loadQuery} = require('./loadQuery');
|
27
27
|
const useIsMountedRef = require('./useIsMountedRef');
|
28
28
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
29
29
|
const {useCallback, useEffect, useRef, useState} = require('react');
|
@@ -108,11 +108,7 @@ declare function useQueryLoader<TQuery: OperationType>(
|
|
108
108
|
initialQueryReference?: ?PreloadedQuery<TQuery>,
|
109
109
|
): UseQueryLoaderHookReturnType<TQuery['variables'], TQuery['response']>;
|
110
110
|
|
111
|
-
|
112
|
-
TVariables: Variables,
|
113
|
-
TData,
|
114
|
-
TRawResponse: ?{...} = void,
|
115
|
-
>(
|
111
|
+
hook useQueryLoader<TVariables: Variables, TData, TRawResponse: ?{...} = void>(
|
116
112
|
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
117
113
|
initialQueryReference?: ?PreloadedQuery<{
|
118
114
|
response: TData,
|
@@ -150,7 +146,6 @@ function useQueryLoader<
|
|
150
146
|
initialQueryReference ?? initialNullQueryReferenceState;
|
151
147
|
|
152
148
|
const environment = useRelayEnvironment();
|
153
|
-
useTrackLoadQueryInRender();
|
154
149
|
|
155
150
|
const isMountedRef = useIsMountedRef();
|
156
151
|
const undisposedQueryReferencesRef = useRef<
|
@@ -172,6 +167,7 @@ function useQueryLoader<
|
|
172
167
|
// necessary here
|
173
168
|
// TODO(T78446637): Handle disposal of managed query references in
|
174
169
|
// components that were never mounted after rendering
|
170
|
+
// $FlowFixMe[react-rule-unsafe-ref]
|
175
171
|
undisposedQueryReferencesRef.current.add(initialQueryReferenceInternal);
|
176
172
|
setPreviousInitialQueryReference(initialQueryReferenceInternal);
|
177
173
|
setQueryReference(initialQueryReferenceInternal);
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
import type {Options} from './
|
14
|
+
import type {Options} from './useRefetchableFragmentInternal';
|
15
15
|
import type {
|
16
16
|
Disposable,
|
17
17
|
FragmentType,
|
@@ -19,8 +19,7 @@ import type {
|
|
19
19
|
Variables,
|
20
20
|
} from 'relay-runtime';
|
21
21
|
|
22
|
-
const
|
23
|
-
const useRefetchableFragmentNode = require('./legacy/useRefetchableFragmentNode');
|
22
|
+
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal');
|
24
23
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
25
24
|
const {useDebugValue} = require('react');
|
26
25
|
const {getFragment} = require('relay-runtime');
|
@@ -65,7 +64,7 @@ export type UseRefetchableFragmentType = <
|
|
65
64
|
key: TKey,
|
66
65
|
) => ReturnType<TVariables, TData, TKey>;
|
67
66
|
|
68
|
-
|
67
|
+
hook useRefetchableFragment<
|
69
68
|
TFragmentType: FragmentType,
|
70
69
|
TVariables: Variables,
|
71
70
|
TData,
|
@@ -79,47 +78,18 @@ function useRefetchableFragment_LEGACY<
|
|
79
78
|
fragmentNode,
|
80
79
|
'first argument of useRefetchableFragment()',
|
81
80
|
);
|
82
|
-
const {fragmentData, refetch} =
|
83
|
-
{
|
84
|
-
|
85
|
-
variables: TVariables,
|
86
|
-
},
|
87
|
-
{
|
88
|
-
+$data: mixed,
|
89
|
-
...
|
90
|
-
},
|
81
|
+
const {fragmentData, refetch} = useRefetchableFragmentInternal<
|
82
|
+
{variables: TVariables, response: TData},
|
83
|
+
{data?: TData},
|
91
84
|
>(fragmentNode, fragmentRef, 'useRefetchableFragment()');
|
92
85
|
if (__DEV__) {
|
93
86
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
87
|
+
// $FlowFixMe[react-rule-hook]
|
94
88
|
useDebugValue({fragment: fragmentNode.name, data: fragmentData});
|
95
89
|
}
|
96
|
-
|
97
90
|
// $FlowFixMe[incompatible-return]
|
98
91
|
// $FlowFixMe[prop-missing]
|
99
|
-
// $FlowFixMe[incompatible-variance]
|
100
92
|
return [fragmentData, refetch];
|
101
93
|
}
|
102
94
|
|
103
|
-
function useRefetchableFragment<
|
104
|
-
TFragmentType: FragmentType,
|
105
|
-
TVariables: Variables,
|
106
|
-
TData,
|
107
|
-
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
108
|
-
>(
|
109
|
-
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
110
|
-
parentFragmentRef: TKey,
|
111
|
-
): ReturnType<TVariables, TData, TKey> {
|
112
|
-
const impl = HooksImplementation.get();
|
113
|
-
if (impl) {
|
114
|
-
// $FlowExpectedError[incompatible-return] Flow cannot prove that two conditional type satisfy each other
|
115
|
-
return impl.useRefetchableFragment<TFragmentType, TVariables, TData, TKey>(
|
116
|
-
fragmentInput,
|
117
|
-
parentFragmentRef,
|
118
|
-
);
|
119
|
-
} else {
|
120
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
121
|
-
return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
|
125
95
|
module.exports = useRefetchableFragment;
|
@@ -11,8 +11,7 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
import type {
|
15
|
-
import type {LoaderFn} from '../useQueryLoader';
|
14
|
+
import type {LoaderFn} from './useQueryLoader';
|
16
15
|
import type {
|
17
16
|
ConcreteRequest,
|
18
17
|
Disposable,
|
@@ -21,18 +20,19 @@ import type {
|
|
21
20
|
OperationDescriptor,
|
22
21
|
OperationType,
|
23
22
|
ReaderFragment,
|
23
|
+
RefetchableIdentifierInfo,
|
24
24
|
RenderPolicy,
|
25
25
|
Variables,
|
26
26
|
VariablesOf,
|
27
27
|
} from 'relay-runtime';
|
28
28
|
|
29
|
-
const ProfilerContext = require('
|
30
|
-
const {getQueryResourceForEnvironment} = require('
|
31
|
-
const
|
32
|
-
const
|
33
|
-
const
|
34
|
-
const
|
35
|
-
const
|
29
|
+
const ProfilerContext = require('./ProfilerContext');
|
30
|
+
const {getQueryResourceForEnvironment} = require('./QueryResource');
|
31
|
+
const readFragmentInternal = require('./readFragmentInternal');
|
32
|
+
const useFragmentInternal = require('./useFragmentInternal');
|
33
|
+
const useIsMountedRef = require('./useIsMountedRef');
|
34
|
+
const useQueryLoader = require('./useQueryLoader');
|
35
|
+
const useRelayEnvironment = require('./useRelayEnvironment');
|
36
36
|
const invariant = require('invariant');
|
37
37
|
const {useCallback, useContext, useReducer} = require('react');
|
38
38
|
const {
|
@@ -160,7 +160,7 @@ function reducer(state: RefetchState, action: Action): RefetchState {
|
|
160
160
|
}
|
161
161
|
}
|
162
162
|
|
163
|
-
|
163
|
+
hook useRefetchableFragmentNode<
|
164
164
|
TQuery: OperationType,
|
165
165
|
TKey: ?{+$data?: mixed, ...},
|
166
166
|
>(
|
@@ -355,7 +355,7 @@ function useRefetchableFragmentNode<
|
|
355
355
|
};
|
356
356
|
}
|
357
357
|
|
358
|
-
|
358
|
+
hook useRefetchFunction<TQuery: OperationType>(
|
359
359
|
componentDisplayName: string,
|
360
360
|
dispatch: (
|
361
361
|
| {
|
@@ -17,7 +17,7 @@ const ReactRelayContext = require('./../ReactRelayContext');
|
|
17
17
|
const invariant = require('invariant');
|
18
18
|
const {useContext} = require('react');
|
19
19
|
|
20
|
-
|
20
|
+
hook useRelayEnvironment(): IEnvironment {
|
21
21
|
const context = useContext(ReactRelayContext);
|
22
22
|
invariant(
|
23
23
|
context != null,
|
@@ -16,7 +16,7 @@ import type {ReaderFragment} from 'relay-runtime';
|
|
16
16
|
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
17
17
|
const warning = require('warning');
|
18
18
|
|
19
|
-
|
19
|
+
hook useStaticFragmentNodeWarning(
|
20
20
|
fragmentNode: ReaderFragment,
|
21
21
|
warningContext: string,
|
22
22
|
): void {
|
@@ -25,8 +25,10 @@ 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
|
+
// $FlowFixMe[react-rule-hook]
|
28
29
|
const initialPropRef = useUnsafeRef_DEPRECATED(fragmentNode.name);
|
29
30
|
warning(
|
31
|
+
// $FlowFixMe[react-rule-unsafe-ref]
|
30
32
|
initialPropRef.current === fragmentNode.name,
|
31
33
|
'Relay: The %s has to remain the same over the lifetime of a component. ' +
|
32
34
|
'Changing it is not supported and will result in unexpected behavior.',
|
@@ -25,7 +25,7 @@ const {useEffect, useRef} = require('react');
|
|
25
25
|
* re-established and the previous one will be disposed.
|
26
26
|
* The subscription will automatically be disposed on unmount
|
27
27
|
*/
|
28
|
-
|
28
|
+
hook useSubscribeToInvalidationState(
|
29
29
|
dataIDs: $ReadOnlyArray<DataID>,
|
30
30
|
callback: () => void,
|
31
31
|
): Disposable {
|
@@ -26,7 +26,7 @@ type RequestSubscriptionFn<TVariables, TData, TRawResponse> = (
|
|
26
26
|
config: GraphQLSubscriptionConfig<TVariables, TData, TRawResponse>,
|
27
27
|
) => Disposable;
|
28
28
|
|
29
|
-
|
29
|
+
hook useSubscription<TVariables, TData, TRawResponse>(
|
30
30
|
config: GraphQLSubscriptionConfig<TVariables, TData, TRawResponse>,
|
31
31
|
requestSubscriptionFn?: RequestSubscriptionFn<
|
32
32
|
TVariables,
|
@@ -18,7 +18,7 @@ const {useMemo} = require('react');
|
|
18
18
|
* pattern to read or write from a ref during render as it does not trigger
|
19
19
|
* a rerender and might result in bugs.
|
20
20
|
*/
|
21
|
-
|
21
|
+
hook useUnsafeRef_DEPRECATED<T>(init: T): {current: T} {
|
22
22
|
return useMemo<{current: T}>(() => ({current: init}), []);
|
23
23
|
}
|
24
24
|
|
@@ -1,15 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var warning = require("fbjs/lib/warning");
|
4
|
-
var implementation = null;
|
5
|
-
function inject(impl) {
|
6
|
-
process.env.NODE_ENV !== "production" ? warning(implementation === null, 'Relay HooksImplementation was injected twice.') : void 0;
|
7
|
-
implementation = impl;
|
8
|
-
}
|
9
|
-
function get() {
|
10
|
-
return implementation;
|
11
|
-
}
|
12
|
-
module.exports = {
|
13
|
-
inject: inject,
|
14
|
-
get: get
|
15
|
-
};
|
@@ -1,26 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var _require = require('../loadQuery'),
|
4
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
5
|
-
var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
6
|
-
var useFragmentInternal = require('./useFragmentInternal_EXPERIMENTAL');
|
7
|
-
var _require2 = require('react'),
|
8
|
-
useDebugValue = _require2.useDebugValue;
|
9
|
-
var _require3 = require('relay-runtime'),
|
10
|
-
getFragment = _require3.getFragment;
|
11
|
-
function useFragment(fragment, key) {
|
12
|
-
useTrackLoadQueryInRender();
|
13
|
-
var fragmentNode = getFragment(fragment);
|
14
|
-
if (process.env.NODE_ENV !== "production") {
|
15
|
-
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
16
|
-
}
|
17
|
-
var data = useFragmentInternal(fragmentNode, key, 'useFragment()');
|
18
|
-
if (process.env.NODE_ENV !== "production") {
|
19
|
-
useDebugValue({
|
20
|
-
fragment: fragmentNode.name,
|
21
|
-
data: data
|
22
|
-
});
|
23
|
-
}
|
24
|
-
return data;
|
25
|
-
}
|
26
|
-
module.exports = useFragment;
|