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,10 +17,9 @@ import type {
|
|
19
17
|
Disposable,
|
20
18
|
GraphQLResponse,
|
21
19
|
Observer,
|
22
|
-
OperationType,
|
23
20
|
ReaderFragment,
|
24
21
|
ReaderPaginationMetadata,
|
25
|
-
|
22
|
+
Variables,
|
26
23
|
} from 'relay-runtime';
|
27
24
|
|
28
25
|
const useFetchTrackingRef = require('./useFetchTrackingRef');
|
@@ -32,8 +29,8 @@ const useRelayEnvironment = require('./useRelayEnvironment');
|
|
32
29
|
const invariant = require('invariant');
|
33
30
|
const {useCallback, useEffect, useState} = require('react');
|
34
31
|
const {
|
35
|
-
ConnectionInterface,
|
36
32
|
__internal: {fetchQuery},
|
33
|
+
ConnectionInterface,
|
37
34
|
createOperationDescriptor,
|
38
35
|
getPaginationVariables,
|
39
36
|
getSelector,
|
@@ -41,15 +38,15 @@ const {
|
|
41
38
|
} = require('relay-runtime');
|
42
39
|
const warning = require('warning');
|
43
40
|
|
44
|
-
export type LoadMoreFn<
|
41
|
+
export type LoadMoreFn<TVariables: Variables> = (
|
45
42
|
count: number,
|
46
|
-
options?: {
|
43
|
+
options?: {
|
47
44
|
onComplete?: (Error | null) => void,
|
48
|
-
UNSTABLE_extraVariables?: $Shape<
|
49
|
-
|
45
|
+
UNSTABLE_extraVariables?: $Shape<TVariables>,
|
46
|
+
},
|
50
47
|
) => Disposable;
|
51
48
|
|
52
|
-
export type UseLoadMoreFunctionArgs = {
|
49
|
+
export type UseLoadMoreFunctionArgs = {
|
53
50
|
direction: Direction,
|
54
51
|
fragmentNode: ReaderFragment,
|
55
52
|
fragmentRef: mixed,
|
@@ -62,11 +59,11 @@ export type UseLoadMoreFunctionArgs = {|
|
|
62
59
|
componentDisplayName: string,
|
63
60
|
observer: Observer<GraphQLResponse>,
|
64
61
|
onReset: () => void,
|
65
|
-
|
62
|
+
};
|
66
63
|
|
67
|
-
function useLoadMoreFunction<
|
64
|
+
function useLoadMoreFunction<TVariables: Variables>(
|
68
65
|
args: UseLoadMoreFunctionArgs,
|
69
|
-
): [LoadMoreFn<
|
66
|
+
): [LoadMoreFn<TVariables>, boolean, () => void] {
|
70
67
|
const {
|
71
68
|
direction,
|
72
69
|
fragmentNode,
|
@@ -125,7 +122,13 @@ function useLoadMoreFunction<TQuery: OperationType>(
|
|
125
122
|
}, [disposeFetch]);
|
126
123
|
|
127
124
|
const loadMore = useCallback(
|
128
|
-
(
|
125
|
+
(
|
126
|
+
count: number,
|
127
|
+
options: void | {
|
128
|
+
UNSTABLE_extraVariables?: $Shape<TVariables>,
|
129
|
+
onComplete?: (Error | null) => void,
|
130
|
+
},
|
131
|
+
) => {
|
129
132
|
// TODO(T41131846): Fetch/Caching policies for loadMore
|
130
133
|
|
131
134
|
const onComplete = options?.onComplete;
|
@@ -265,10 +268,10 @@ function getConnectionState(
|
|
265
268
|
fragmentNode: ReaderFragment,
|
266
269
|
fragmentData: mixed,
|
267
270
|
connectionPathInFragmentData: $ReadOnlyArray<string | number>,
|
268
|
-
): {
|
271
|
+
): {
|
269
272
|
cursor: ?string,
|
270
273
|
hasMore: boolean,
|
271
|
-
|
274
|
+
} {
|
272
275
|
const {
|
273
276
|
EDGES,
|
274
277
|
PAGE_INFO,
|
@@ -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 {
|
@@ -31,8 +29,8 @@ function useMemoOperationDescriptor(
|
|
31
29
|
variables: Variables,
|
32
30
|
cacheConfig?: ?CacheConfig,
|
33
31
|
): OperationDescriptor {
|
34
|
-
const
|
35
|
-
const
|
32
|
+
const memoVariables = useMemoVariables(variables);
|
33
|
+
const memoCacheConfig = useMemoVariables(cacheConfig || {});
|
36
34
|
return useMemo(
|
37
35
|
() =>
|
38
36
|
createOperationDescriptor(
|
@@ -4,51 +4,33 @@
|
|
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 {Variables} from 'relay-runtime';
|
17
15
|
|
18
16
|
const areEqual = require('areEqual');
|
19
|
-
const
|
20
|
-
|
21
|
-
const {useMemo, useRef, useState} = React;
|
17
|
+
const {useState} = require('react');
|
22
18
|
|
19
|
+
/**
|
20
|
+
* Memoizes the passed in `variables` object based on `areEqual` equality.
|
21
|
+
* This is useful when a `variables` object is used as a value in a depencency
|
22
|
+
* array as it might often be constructed during render.
|
23
|
+
*/
|
23
24
|
function useMemoVariables<TVariables: Variables | null>(
|
24
25
|
variables: TVariables,
|
25
|
-
):
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
const variablesChangedGenerationRef = useRef(0);
|
31
|
-
|
32
|
-
// We mirror the variables to check if they have changed between renders
|
33
|
-
const [mirroredVariables, setMirroredVariables] = useState<Variables | null>(
|
34
|
-
variables,
|
35
|
-
);
|
36
|
-
|
37
|
-
const variablesChanged = !areEqual(variables, mirroredVariables);
|
38
|
-
if (variablesChanged) {
|
39
|
-
variablesChangedGenerationRef.current =
|
40
|
-
(variablesChangedGenerationRef.current ?? 0) + 1;
|
26
|
+
): TVariables {
|
27
|
+
const [mirroredVariables, setMirroredVariables] = useState(variables);
|
28
|
+
if (areEqual(variables, mirroredVariables)) {
|
29
|
+
return mirroredVariables;
|
30
|
+
} else {
|
41
31
|
setMirroredVariables(variables);
|
32
|
+
return variables;
|
42
33
|
}
|
43
|
-
|
44
|
-
// NOTE: We disable react-hooks-deps warning because we explicitly
|
45
|
-
// don't want to memoize on object identity
|
46
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
47
|
-
const memoVariables = useMemo(
|
48
|
-
() => variables,
|
49
|
-
[variablesChangedGenerationRef.current],
|
50
|
-
);
|
51
|
-
return [memoVariables, variablesChangedGenerationRef.current ?? 0];
|
52
34
|
}
|
53
35
|
|
54
36
|
module.exports = useMemoVariables;
|
@@ -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 {
|
@@ -32,7 +30,7 @@ const {commitMutation: defaultCommitMutation} = require('relay-runtime');
|
|
32
30
|
|
33
31
|
const {useState, useEffect, useRef, useCallback} = React;
|
34
32
|
|
35
|
-
export type UseMutationConfig<TMutation: MutationParameters> = {
|
33
|
+
export type UseMutationConfig<TMutation: MutationParameters> = {
|
36
34
|
configs?: Array<DeclarativeMutationConfig>,
|
37
35
|
onError?: ?(error: Error) => void,
|
38
36
|
onCompleted?: ?(
|
@@ -50,7 +48,7 @@ export type UseMutationConfig<TMutation: MutationParameters> = {|
|
|
50
48
|
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
51
49
|
uploadables?: UploadableMap,
|
52
50
|
variables: TMutation['variables'],
|
53
|
-
|
51
|
+
};
|
54
52
|
|
55
53
|
function useMutation<TMutation: MutationParameters>(
|
56
54
|
mutation: GraphQLTaggedNode,
|
@@ -63,11 +61,11 @@ function useMutation<TMutation: MutationParameters>(
|
|
63
61
|
const isMountedRef = useIsMountedRef();
|
64
62
|
const environmentRef = useRef(environment);
|
65
63
|
const mutationRef = useRef(mutation);
|
66
|
-
const inFlightMutationsRef = useRef(new Set());
|
64
|
+
const inFlightMutationsRef = useRef(new Set<Disposable>());
|
67
65
|
const [isMutationInFlight, setMutationInFlight] = useState(false);
|
68
66
|
|
69
67
|
const cleanup = useCallback(
|
70
|
-
disposable => {
|
68
|
+
(disposable: Disposable) => {
|
71
69
|
if (
|
72
70
|
environmentRef.current === environment &&
|
73
71
|
mutationRef.current === mutation
|
@@ -100,7 +98,7 @@ function useMutation<TMutation: MutationParameters>(
|
|
100
98
|
if (isMountedRef.current) {
|
101
99
|
setMutationInFlight(true);
|
102
100
|
}
|
103
|
-
const disposable = commitMutationFn(environment, {
|
101
|
+
const disposable: Disposable = commitMutationFn(environment, {
|
104
102
|
...config,
|
105
103
|
mutation,
|
106
104
|
onCompleted: (response, errors) => {
|
@@ -4,25 +4,25 @@
|
|
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 {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
17
|
-
import type {
|
15
|
+
import type {RefetchFn} from './useRefetchableFragment';
|
16
|
+
import type {Options} from './useRefetchableFragmentNode';
|
18
17
|
import type {
|
19
18
|
FragmentType,
|
20
19
|
GraphQLResponse,
|
21
|
-
GraphQLTaggedNode,
|
22
20
|
Observer,
|
23
|
-
|
21
|
+
RefetchableFragment,
|
22
|
+
Variables,
|
24
23
|
} from 'relay-runtime';
|
25
24
|
|
25
|
+
const HooksImplementation = require('./HooksImplementation');
|
26
26
|
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
27
27
|
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
28
28
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
@@ -33,36 +33,28 @@ const {
|
|
33
33
|
getPaginationMetadata,
|
34
34
|
} = require('relay-runtime');
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
// This separate type export is only needed as long as we are injecting
|
37
|
+
// a separate hooks implementation in ./HooksImplementation -- it can
|
38
|
+
// be removed after we stop doing that.
|
39
|
+
export type UsePaginationFragmentType = <
|
40
|
+
TFragmentType: FragmentType,
|
41
|
+
TVariables: Variables,
|
42
|
+
TData,
|
43
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
44
|
+
>(
|
45
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
46
|
+
parentFragmentRef: TKey,
|
47
|
+
) => ReturnType<TVariables, TData, TKey>;
|
46
48
|
|
47
|
-
function
|
48
|
-
|
49
|
-
|
49
|
+
function usePaginationFragment_LEGACY<
|
50
|
+
TFragmentType: FragmentType,
|
51
|
+
TVariables: Variables,
|
52
|
+
TData,
|
53
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
50
54
|
>(
|
51
|
-
fragmentInput:
|
55
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
52
56
|
parentFragmentRef: TKey,
|
53
|
-
): ReturnType<
|
54
|
-
TQuery,
|
55
|
-
TKey,
|
56
|
-
// NOTE: This $Call ensures that the type of the returned data is either:
|
57
|
-
// - nullable if the provided ref type is nullable
|
58
|
-
// - non-nullable if the provided ref type is non-nullable
|
59
|
-
// prettier-ignore
|
60
|
-
$Call<
|
61
|
-
& (<TFragmentData>( { +$data?: TFragmentData, ... }) => TFragmentData)
|
62
|
-
& (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
|
63
|
-
TKey,
|
64
|
-
>,
|
65
|
-
> {
|
57
|
+
): ReturnType<TVariables, TData, TKey> {
|
66
58
|
const fragmentNode = getFragment(fragmentInput);
|
67
59
|
useStaticFragmentNodeWarning(
|
68
60
|
fragmentNode,
|
@@ -78,14 +70,14 @@ function usePaginationFragment<
|
|
78
70
|
} = getPaginationMetadata(fragmentNode, componentDisplayName);
|
79
71
|
|
80
72
|
const {fragmentData, fragmentRef, refetch} = useRefetchableFragmentNode<
|
81
|
-
|
82
|
-
|
73
|
+
$FlowFixMe,
|
74
|
+
$FlowFixMe,
|
83
75
|
>(fragmentNode, parentFragmentRef, componentDisplayName);
|
84
76
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
85
77
|
|
86
78
|
// Backward pagination
|
87
79
|
const [loadPrevious, hasPrevious, isLoadingPrevious, disposeFetchPrevious] =
|
88
|
-
useLoadMore<
|
80
|
+
useLoadMore<TVariables>({
|
89
81
|
componentDisplayName,
|
90
82
|
connectionPathInFragmentData,
|
91
83
|
direction: 'backward',
|
@@ -100,7 +92,7 @@ function usePaginationFragment<
|
|
100
92
|
|
101
93
|
// Forward pagination
|
102
94
|
const [loadNext, hasNext, isLoadingNext, disposeFetchNext] =
|
103
|
-
useLoadMore<
|
95
|
+
useLoadMore<TVariables>({
|
104
96
|
componentDisplayName,
|
105
97
|
connectionPathInFragmentData,
|
106
98
|
direction: 'forward',
|
@@ -113,8 +105,8 @@ function usePaginationFragment<
|
|
113
105
|
paginationRequest,
|
114
106
|
});
|
115
107
|
|
116
|
-
const refetchPagination:
|
117
|
-
(variables, options) => {
|
108
|
+
const refetchPagination: RefetchFn<TVariables, TKey> = useCallback(
|
109
|
+
(variables: TVariables, options: void | Options) => {
|
118
110
|
disposeFetchNext();
|
119
111
|
disposeFetchPrevious();
|
120
112
|
return refetch(variables, {...options, __environment: undefined});
|
@@ -134,7 +126,7 @@ function usePaginationFragment<
|
|
134
126
|
});
|
135
127
|
}
|
136
128
|
return {
|
137
|
-
data: fragmentData,
|
129
|
+
data: (fragmentData: $FlowFixMe),
|
138
130
|
loadNext,
|
139
131
|
loadPrevious,
|
140
132
|
hasNext,
|
@@ -145,7 +137,7 @@ function usePaginationFragment<
|
|
145
137
|
};
|
146
138
|
}
|
147
139
|
|
148
|
-
function useLoadMore<
|
140
|
+
function useLoadMore<TVariables: Variables>(
|
149
141
|
args: $Diff<
|
150
142
|
UseLoadMoreFunctionArgs,
|
151
143
|
{
|
@@ -154,7 +146,7 @@ function useLoadMore<TQuery: OperationType>(
|
|
154
146
|
...
|
155
147
|
},
|
156
148
|
>,
|
157
|
-
): [LoadMoreFn<
|
149
|
+
): [LoadMoreFn<TVariables>, boolean, boolean, () => void] {
|
158
150
|
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
159
151
|
const observer = {
|
160
152
|
start: () => setIsLoadingMore(true),
|
@@ -162,7 +154,7 @@ function useLoadMore<TQuery: OperationType>(
|
|
162
154
|
error: () => setIsLoadingMore(false),
|
163
155
|
};
|
164
156
|
const handleReset = () => setIsLoadingMore(false);
|
165
|
-
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction({
|
157
|
+
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
|
166
158
|
...args,
|
167
159
|
observer,
|
168
160
|
onReset: handleReset,
|
@@ -170,4 +162,44 @@ function useLoadMore<TQuery: OperationType>(
|
|
170
162
|
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
171
163
|
}
|
172
164
|
|
165
|
+
export type ReturnType<TVariables, TData, TKey> = {
|
166
|
+
// NOTE: This $Call ensures that the type of the returned data is either:
|
167
|
+
// - nullable if the provided ref type is nullable
|
168
|
+
// - non-nullable if the provided ref type is non-nullable
|
169
|
+
// prettier-ignore
|
170
|
+
data: $Call<
|
171
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
|
172
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
|
173
|
+
TKey,
|
174
|
+
>,
|
175
|
+
loadNext: LoadMoreFn<TVariables>,
|
176
|
+
loadPrevious: LoadMoreFn<TVariables>,
|
177
|
+
hasNext: boolean,
|
178
|
+
hasPrevious: boolean,
|
179
|
+
isLoadingNext: boolean,
|
180
|
+
isLoadingPrevious: boolean,
|
181
|
+
refetch: RefetchFn<TVariables, TKey>,
|
182
|
+
};
|
183
|
+
|
184
|
+
function usePaginationFragment<
|
185
|
+
TFragmentType: FragmentType,
|
186
|
+
TVariables: Variables,
|
187
|
+
TData,
|
188
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
189
|
+
>(
|
190
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
191
|
+
parentFragmentRef: TKey,
|
192
|
+
): ReturnType<TVariables, TData, TKey> {
|
193
|
+
const impl = HooksImplementation.get();
|
194
|
+
if (impl) {
|
195
|
+
return impl.usePaginationFragment<TFragmentType, TVariables, TData, TKey>(
|
196
|
+
fragmentInput,
|
197
|
+
parentFragmentRef,
|
198
|
+
);
|
199
|
+
} else {
|
200
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
201
|
+
return usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef);
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
173
205
|
module.exports = usePaginationFragment;
|
@@ -4,23 +4,20 @@
|
|
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 {PreloadedQuery} from './EntryPointTypes.flow';
|
17
14
|
import type {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
} from '
|
15
|
+
EnvironmentProviderOptions,
|
16
|
+
PreloadedQueryInner,
|
17
|
+
PreloadedQueryInner_DEPRECATED,
|
18
|
+
} from './EntryPointTypes.flow';
|
19
|
+
import type {Query, RenderPolicy, Variables} from 'relay-runtime';
|
22
20
|
|
23
|
-
const HooksImplementation = require('./HooksImplementation');
|
24
21
|
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
25
22
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
26
23
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
@@ -32,24 +29,44 @@ const {
|
|
32
29
|
} = require('relay-runtime');
|
33
30
|
const warning = require('warning');
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
type PreloadedQuery<
|
33
|
+
TVariables: Variables,
|
34
|
+
TData,
|
35
|
+
TRawResponse,
|
36
|
+
TEnvironmentProviderOptions = EnvironmentProviderOptions,
|
37
|
+
> =
|
38
|
+
| PreloadedQueryInner_DEPRECATED<
|
39
|
+
{
|
40
|
+
variables: TVariables,
|
41
|
+
response: TData,
|
42
|
+
rawResponse?: TRawResponse,
|
43
|
+
},
|
44
|
+
TEnvironmentProviderOptions,
|
45
|
+
>
|
46
|
+
| PreloadedQueryInner<
|
47
|
+
{
|
48
|
+
variables: TVariables,
|
49
|
+
response: TData,
|
50
|
+
rawResponse?: TRawResponse,
|
51
|
+
},
|
52
|
+
TEnvironmentProviderOptions,
|
53
|
+
>;
|
45
54
|
|
46
|
-
function
|
47
|
-
|
48
|
-
|
49
|
-
|
55
|
+
function usePreloadedQuery<
|
56
|
+
TVariables: Variables,
|
57
|
+
TData,
|
58
|
+
TRawResponse: ?{...} = void,
|
59
|
+
>(
|
60
|
+
gqlQuery: Query<TVariables, TData, TRawResponse>,
|
61
|
+
preloadedQuery: PreloadedQuery<
|
62
|
+
TVariables,
|
63
|
+
TData,
|
64
|
+
$NonMaybeType<TRawResponse>,
|
65
|
+
>,
|
66
|
+
options?: {
|
50
67
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
51
|
-
|
52
|
-
):
|
68
|
+
},
|
69
|
+
): TData {
|
53
70
|
// We need to use this hook in order to be able to track if
|
54
71
|
// loadQuery was called during render
|
55
72
|
useTrackLoadQueryInRender();
|
@@ -139,7 +156,12 @@ function usePreloadedQuery_LEGACY<TQuery: OperationType>(
|
|
139
156
|
};
|
140
157
|
}
|
141
158
|
|
142
|
-
const data = useLazyLoadQueryNode
|
159
|
+
const data = useLazyLoadQueryNode<{
|
160
|
+
variables: TVariables,
|
161
|
+
response: TData,
|
162
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
163
|
+
}>(useLazyLoadQueryNodeParams);
|
164
|
+
|
143
165
|
if (__DEV__) {
|
144
166
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
145
167
|
useDebugValue({
|
@@ -154,20 +176,4 @@ function usePreloadedQuery_LEGACY<TQuery: OperationType>(
|
|
154
176
|
return data;
|
155
177
|
}
|
156
178
|
|
157
|
-
|
158
|
-
gqlQuery: GraphQLTaggedNode,
|
159
|
-
preloadedQuery: PreloadedQuery<TQuery>,
|
160
|
-
options?: {|
|
161
|
-
UNSTABLE_renderPolicy?: RenderPolicy,
|
162
|
-
|},
|
163
|
-
): TQuery['response'] {
|
164
|
-
const impl = HooksImplementation.get();
|
165
|
-
if (impl) {
|
166
|
-
return impl.usePreloadedQuery(gqlQuery, preloadedQuery, options);
|
167
|
-
} else {
|
168
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
169
|
-
return usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options);
|
170
|
-
}
|
171
|
-
}
|
172
|
-
|
173
|
-
module.exports = (usePreloadedQuery: UsePreloadedQueryHookType);
|
179
|
+
module.exports = usePreloadedQuery;
|