react-relay 14.0.0 → 14.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +0 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +0 -2
- package/ReactRelayFragmentContainer.js.flow +0 -2
- package/ReactRelayFragmentMockRenderer.js.flow +0 -2
- package/ReactRelayLocalQueryRenderer.js.flow +0 -2
- package/ReactRelayPaginationContainer.js.flow +0 -2
- package/ReactRelayQueryFetcher.js.flow +9 -11
- package/ReactRelayQueryRenderer.js.flow +10 -12
- package/ReactRelayQueryRendererContext.js.flow +1 -3
- package/ReactRelayRefetchContainer.js.flow +0 -4
- package/ReactRelayTestMocker.js.flow +0 -2
- package/ReactRelayTypes.js.flow +6 -8
- package/RelayContext.js.flow +0 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -4
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +3 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +3 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +2 -4
- package/assertFragmentMap.js.flow +0 -2
- package/buildReactRelayContainer.js.flow +0 -2
- package/getRootVariablesForFragments.js.flow +0 -2
- package/hooks.js +1 -1
- package/hooks.js.flow +0 -2
- package/index.js +1 -1
- package/index.js.flow +2 -2
- package/isRelayEnvironment.js.flow +0 -2
- package/legacy.js +1 -1
- package/legacy.js.flow +0 -2
- package/lib/ReactRelayContainerUtils.js +0 -1
- package/lib/ReactRelayContext.js +0 -1
- package/lib/ReactRelayFragmentContainer.js +10 -9
- package/lib/ReactRelayFragmentMockRenderer.js +0 -1
- package/lib/ReactRelayLocalQueryRenderer.js +0 -1
- package/lib/ReactRelayPaginationContainer.js +14 -11
- package/lib/ReactRelayQueryFetcher.js +1 -2
- package/lib/ReactRelayQueryRenderer.js +1 -2
- package/lib/ReactRelayQueryRendererContext.js +0 -1
- package/lib/ReactRelayRefetchContainer.js +11 -14
- package/lib/ReactRelayTestMocker.js +1 -2
- package/lib/ReactRelayTypes.js +0 -1
- package/lib/RelayContext.js +0 -1
- package/lib/assertFragmentMap.js +0 -1
- package/lib/buildReactRelayContainer.js +1 -2
- package/lib/getRootVariablesForFragments.js +1 -2
- package/lib/hooks.js +0 -1
- package/lib/index.js +3 -1
- package/lib/isRelayEnvironment.js +0 -1
- package/lib/legacy.js +0 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +0 -1
- package/lib/readContext.js +0 -1
- package/lib/relay-hooks/EntryPointContainer.react.js +0 -1
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -1
- package/lib/relay-hooks/FragmentResource.js +7 -7
- package/lib/relay-hooks/HooksImplementation.js +1 -1
- package/lib/relay-hooks/InternalLogger.js +0 -1
- package/lib/relay-hooks/LRUCache.js +0 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -1
- package/lib/relay-hooks/MatchContainer.js +1 -2
- package/lib/relay-hooks/ProfilerContext.js +0 -1
- package/lib/relay-hooks/QueryResource.js +1 -2
- package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -1
- package/lib/relay-hooks/SuspenseResource.js +1 -2
- package/lib/relay-hooks/loadQuery.js +1 -1
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +1 -2
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -1
- package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -1
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +3 -3
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +239 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +183 -125
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +0 -1
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -1
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +150 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -1
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +367 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +45 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +4 -3
- package/lib/relay-hooks/useClientQuery.js +33 -0
- package/lib/relay-hooks/useEntryPointLoader.js +1 -2
- package/lib/relay-hooks/useFetchTrackingRef.js +0 -1
- package/lib/relay-hooks/useFragment.js +0 -1
- package/lib/relay-hooks/useFragmentNode.js +0 -1
- package/lib/relay-hooks/useIsMountedRef.js +0 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +1 -15
- package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -1
- package/lib/relay-hooks/useLoadMoreFunction.js +1 -2
- package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -1
- package/lib/relay-hooks/useMemoVariables.js +0 -1
- package/lib/relay-hooks/useMutation.js +1 -2
- package/lib/relay-hooks/usePaginationFragment.js +15 -3
- package/lib/relay-hooks/usePreloadedQuery.js +1 -15
- package/lib/relay-hooks/useQueryLoader.js +1 -2
- package/lib/relay-hooks/useRefetchableFragment.js +14 -2
- package/lib/relay-hooks/useRefetchableFragmentNode.js +1 -2
- package/lib/relay-hooks/useRelayEnvironment.js +0 -1
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -1
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -1
- package/lib/relay-hooks/useSubscription.js +0 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +0 -2
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/readContext.js.flow +0 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +2 -4
- package/relay-hooks/EntryPointTypes.flow.js.flow +30 -32
- package/relay-hooks/FragmentResource.js.flow +9 -11
- package/relay-hooks/HooksImplementation.js.flow +6 -8
- package/relay-hooks/InternalLogger.js.flow +0 -2
- package/relay-hooks/LRUCache.js.flow +0 -2
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -6
- package/relay-hooks/MatchContainer.js.flow +5 -7
- package/relay-hooks/ProfilerContext.js.flow +0 -2
- package/relay-hooks/QueryResource.js.flow +4 -6
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -4
- package/relay-hooks/SuspenseResource.js.flow +0 -2
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +4 -6
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +0 -2
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +4 -6
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +0 -2
- package/relay-hooks/__flowtests__/utils.js.flow +8 -10
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +4 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +0 -2
- package/relay-hooks/react-cache/RelayReactCache.js.flow +0 -2
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +22 -16
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +134 -94
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +0 -2
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +2 -4
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +171 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +2 -4
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +595 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +4 -6
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +6 -8
- package/relay-hooks/useFetchTrackingRef.js.flow +2 -4
- package/relay-hooks/useFragment.js.flow +0 -2
- package/relay-hooks/useFragmentNode.js.flow +2 -4
- package/relay-hooks/useIsMountedRef.js.flow +1 -3
- package/relay-hooks/useLazyLoadQuery.js.flow +7 -30
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -4
- package/relay-hooks/useLoadMoreFunction.js.flow +6 -8
- package/relay-hooks/useMemoOperationDescriptor.js.flow +0 -2
- package/relay-hooks/useMemoVariables.js.flow +0 -2
- package/relay-hooks/useMutation.js.flow +2 -4
- package/relay-hooks/usePaginationFragment.js.flow +44 -19
- package/relay-hooks/usePreloadedQuery.js.flow +5 -24
- package/relay-hooks/useQueryLoader.js.flow +4 -6
- package/relay-hooks/useRefetchableFragment.js.flow +32 -3
- package/relay-hooks/useRefetchableFragmentNode.js.flow +16 -18
- package/relay-hooks/useRelayEnvironment.js.flow +0 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +0 -2
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +0 -2
- package/relay-hooks/useSubscription.js.flow +0 -2
@@ -0,0 +1,39 @@
|
|
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
|
+
* @emails oncall+relay
|
8
|
+
* @flow strict-local
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
import type {ClientQuery, Query, RenderPolicy, Variables} from 'relay-runtime';
|
15
|
+
|
16
|
+
const useLazyLoadQuery = require('./useLazyLoadQuery');
|
17
|
+
|
18
|
+
/**
|
19
|
+
* This hook can be used to render client-only queries.
|
20
|
+
* These queries are consist of queries for client-only data,
|
21
|
+
* schematized via local schema extensions and/or Relay resolvers.
|
22
|
+
*/
|
23
|
+
function useClientQuery<TVariables: Variables, TData>(
|
24
|
+
gqlQuery: ClientQuery<TVariables, TData>,
|
25
|
+
variables: TVariables,
|
26
|
+
options?: {
|
27
|
+
UNSTABLE_renderPolicy?: RenderPolicy,
|
28
|
+
},
|
29
|
+
): TData {
|
30
|
+
// $FlowFixMe[incompatible-type] client queries can be used with useLazyLoadQuery, but only with `store-only` policy.
|
31
|
+
const query: Query<TVariables, TData> = gqlQuery;
|
32
|
+
|
33
|
+
return useLazyLoadQuery(query, variables, {
|
34
|
+
...options,
|
35
|
+
fetchPolicy: 'store-only',
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
module.exports = useClientQuery;
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
@@ -47,9 +45,9 @@ type UseEntryPointLoaderHookReturnType<
|
|
47
45
|
// NullEntryPointReference needs to implement referential equality,
|
48
46
|
// so that multiple NullEntryPointReferences can be in the same set
|
49
47
|
// (corresponding to multiple calls to disposeEntryPoint).
|
50
|
-
type NullEntryPointReference = {
|
48
|
+
type NullEntryPointReference = {
|
51
49
|
kind: 'NullEntryPointReference',
|
52
|
-
|
50
|
+
};
|
53
51
|
const initialNullEntryPointReferenceState = {kind: 'NullEntryPointReference'};
|
54
52
|
|
55
53
|
function useLoadEntryPoint<
|
@@ -68,14 +66,14 @@ function useLoadEntryPoint<
|
|
68
66
|
>(
|
69
67
|
environmentProvider: IEnvironmentProvider<EnvironmentProviderOptions>,
|
70
68
|
entryPoint: TEntryPoint,
|
71
|
-
options?: ?{
|
69
|
+
options?: ?{
|
72
70
|
// TODO(T83890478): Remove once Offscreen API lands in xplat
|
73
71
|
// and we can use it in tests
|
74
|
-
TEST_ONLY__initialEntryPointData?: ?{
|
72
|
+
TEST_ONLY__initialEntryPointData?: ?{
|
75
73
|
entryPointReference: ?PreloadedEntryPoint<TEntryPointComponent>,
|
76
74
|
entryPointParams: ?TEntryPointParams,
|
77
|
-
|
78
|
-
|
75
|
+
},
|
76
|
+
},
|
79
77
|
): UseEntryPointLoaderHookReturnType<
|
80
78
|
TEntryPointParams,
|
81
79
|
TPreloadedQueries,
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {Subscription} from 'relay-runtime';
|
@@ -29,12 +27,12 @@ const {useCallback, useEffect, useRef} = require('react');
|
|
29
27
|
* The additional functions returned by this Hook can be used to mutate
|
30
28
|
* the ref.
|
31
29
|
*/
|
32
|
-
function useFetchTrackingRef(): {
|
30
|
+
function useFetchTrackingRef(): {
|
33
31
|
isFetchingRef: {current: ?boolean, ...},
|
34
32
|
startFetch: Subscription => void,
|
35
33
|
disposeFetch: () => void,
|
36
34
|
completeFetch: () => void,
|
37
|
-
|
35
|
+
} {
|
38
36
|
const subscriptionRef = useRef<?Subscription>(null);
|
39
37
|
const isFetchingRef = useRef<?boolean>(false);
|
40
38
|
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
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';
|
@@ -21,11 +19,11 @@ const {useEffect, useRef, useState} = require('react');
|
|
21
19
|
const {getFragmentIdentifier} = require('relay-runtime');
|
22
20
|
const warning = require('warning');
|
23
21
|
|
24
|
-
type ReturnType<TFragmentData: mixed> = {
|
22
|
+
type ReturnType<TFragmentData: mixed> = {
|
25
23
|
data: TFragmentData,
|
26
24
|
disableStoreUpdates: () => void,
|
27
25
|
enableStoreUpdates: () => void,
|
28
|
-
|
26
|
+
};
|
29
27
|
|
30
28
|
function useFragmentNode<TFragmentData: mixed>(
|
31
29
|
fragmentNode: ReaderFragment,
|
@@ -9,13 +9,11 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
const {useEffect, useRef} = require('react');
|
17
15
|
|
18
|
-
function useIsMountedRef(): {
|
16
|
+
function useIsMountedRef(): {current: boolean} {
|
19
17
|
const isMountedRef = useRef(true);
|
20
18
|
|
21
19
|
useEffect(() => {
|
@@ -9,20 +9,16 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
17
15
|
CacheConfig,
|
18
|
-
ClientQuery,
|
19
16
|
FetchPolicy,
|
20
17
|
Query,
|
21
18
|
RenderPolicy,
|
22
19
|
Variables,
|
23
20
|
} from 'relay-runtime';
|
24
21
|
|
25
|
-
const HooksImplementation = require('./HooksImplementation');
|
26
22
|
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
27
23
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
28
24
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
@@ -35,25 +31,25 @@ const {
|
|
35
31
|
// a separate hooks implementation in ./HooksImplementation -- it can
|
36
32
|
// be removed after we stop doing that.
|
37
33
|
export type UseLazyLoadQueryHookType = <TVariables: Variables, TData>(
|
38
|
-
gqlQuery: Query<TVariables, TData
|
34
|
+
gqlQuery: Query<TVariables, TData>,
|
39
35
|
variables: TVariables,
|
40
|
-
options?: {
|
36
|
+
options?: {
|
41
37
|
fetchKey?: string | number,
|
42
38
|
fetchPolicy?: FetchPolicy,
|
43
39
|
networkCacheConfig?: CacheConfig,
|
44
40
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
45
|
-
|
41
|
+
},
|
46
42
|
) => TData;
|
47
43
|
|
48
|
-
function
|
49
|
-
gqlQuery: Query<TVariables, TData
|
44
|
+
function useLazyLoadQuery<TVariables: Variables, TData>(
|
45
|
+
gqlQuery: Query<TVariables, TData>,
|
50
46
|
variables: TVariables,
|
51
|
-
options?: {
|
47
|
+
options?: {
|
52
48
|
fetchKey?: string | number,
|
53
49
|
fetchPolicy?: FetchPolicy,
|
54
50
|
networkCacheConfig?: CacheConfig,
|
55
51
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
56
|
-
|
52
|
+
},
|
57
53
|
): TData {
|
58
54
|
// We need to use this hook in order to be able to track if
|
59
55
|
// loadQuery was called during render
|
@@ -79,23 +75,4 @@ function useLazyLoadQuery_LEGACY<TVariables: Variables, TData>(
|
|
79
75
|
return data;
|
80
76
|
}
|
81
77
|
|
82
|
-
function useLazyLoadQuery<TVariables: Variables, TData>(
|
83
|
-
gqlQuery: Query<TVariables, TData> | ClientQuery<TVariables, TData>,
|
84
|
-
variables: TVariables,
|
85
|
-
options?: {|
|
86
|
-
fetchKey?: string | number,
|
87
|
-
fetchPolicy?: FetchPolicy,
|
88
|
-
networkCacheConfig?: CacheConfig,
|
89
|
-
UNSTABLE_renderPolicy?: RenderPolicy,
|
90
|
-
|},
|
91
|
-
): TData {
|
92
|
-
const impl = HooksImplementation.get();
|
93
|
-
if (impl) {
|
94
|
-
return impl.useLazyLoadQuery(gqlQuery, variables, options);
|
95
|
-
} else {
|
96
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
97
|
-
return useLazyLoadQuery_LEGACY(gqlQuery, variables, options);
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
78
|
module.exports = (useLazyLoadQuery: UseLazyLoadQueryHookType);
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
@@ -41,14 +39,14 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
|
|
41
39
|
fetchPolicy,
|
42
40
|
fetchKey,
|
43
41
|
renderPolicy,
|
44
|
-
}: {
|
42
|
+
}: {
|
45
43
|
query: OperationDescriptor,
|
46
44
|
componentDisplayName: string,
|
47
45
|
fetchObservable: Observable<GraphQLResponse>,
|
48
46
|
fetchPolicy?: ?FetchPolicy,
|
49
47
|
fetchKey?: ?string | ?number,
|
50
48
|
renderPolicy?: ?RenderPolicy,
|
51
|
-
|
49
|
+
}): TQuery['response'] {
|
52
50
|
const environment = useRelayEnvironment();
|
53
51
|
const profilerContext = useContext(ProfilerContext);
|
54
52
|
const QueryResource = getQueryResourceForEnvironment(environment);
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
@@ -43,13 +41,13 @@ const warning = require('warning');
|
|
43
41
|
|
44
42
|
export type LoadMoreFn<TQuery: OperationType> = (
|
45
43
|
count: number,
|
46
|
-
options?: {
|
44
|
+
options?: {
|
47
45
|
onComplete?: (Error | null) => void,
|
48
46
|
UNSTABLE_extraVariables?: $Shape<VariablesOf<TQuery>>,
|
49
|
-
|
47
|
+
},
|
50
48
|
) => Disposable;
|
51
49
|
|
52
|
-
export type UseLoadMoreFunctionArgs = {
|
50
|
+
export type UseLoadMoreFunctionArgs = {
|
53
51
|
direction: Direction,
|
54
52
|
fragmentNode: ReaderFragment,
|
55
53
|
fragmentRef: mixed,
|
@@ -62,7 +60,7 @@ export type UseLoadMoreFunctionArgs = {|
|
|
62
60
|
componentDisplayName: string,
|
63
61
|
observer: Observer<GraphQLResponse>,
|
64
62
|
onReset: () => void,
|
65
|
-
|
63
|
+
};
|
66
64
|
|
67
65
|
function useLoadMoreFunction<TQuery: OperationType>(
|
68
66
|
args: UseLoadMoreFunctionArgs,
|
@@ -265,10 +263,10 @@ function getConnectionState(
|
|
265
263
|
fragmentNode: ReaderFragment,
|
266
264
|
fragmentData: mixed,
|
267
265
|
connectionPathInFragmentData: $ReadOnlyArray<string | number>,
|
268
|
-
): {
|
266
|
+
): {
|
269
267
|
cursor: ?string,
|
270
268
|
hasMore: boolean,
|
271
|
-
|
269
|
+
} {
|
272
270
|
const {
|
273
271
|
EDGES,
|
274
272
|
PAGE_INFO,
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
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,
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
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';
|
@@ -23,6 +21,7 @@ import type {
|
|
23
21
|
OperationType,
|
24
22
|
} from 'relay-runtime';
|
25
23
|
|
24
|
+
const HooksImplementation = require('./HooksImplementation');
|
26
25
|
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
27
26
|
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
28
27
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
@@ -33,8 +32,16 @@ const {
|
|
33
32
|
getPaginationMetadata,
|
34
33
|
} = require('relay-runtime');
|
35
34
|
|
36
|
-
export type ReturnType<TQuery: OperationType, TKey
|
37
|
-
data:
|
35
|
+
export type ReturnType<TQuery: OperationType, TKey> = {
|
36
|
+
// NOTE: This $Call ensures that the type of the returned data is either:
|
37
|
+
// - nullable if the provided ref type is nullable
|
38
|
+
// - non-nullable if the provided ref type is non-nullable
|
39
|
+
// prettier-ignore
|
40
|
+
data: $Call<
|
41
|
+
& (<TFragmentData>( { +$data?: TFragmentData, ... }) => TFragmentData)
|
42
|
+
& (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
|
43
|
+
TKey,
|
44
|
+
>,
|
38
45
|
loadNext: LoadMoreFn<TQuery>,
|
39
46
|
loadPrevious: LoadMoreFn<TQuery>,
|
40
47
|
hasNext: boolean,
|
@@ -42,27 +49,26 @@ export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
|
|
42
49
|
isLoadingNext: boolean,
|
43
50
|
isLoadingPrevious: boolean,
|
44
51
|
refetch: RefetchFnDynamic<TQuery, TKey>,
|
45
|
-
|
52
|
+
};
|
46
53
|
|
47
|
-
|
54
|
+
// This separate type export is only needed as long as we are injecting
|
55
|
+
// a separate hooks implementation in ./HooksImplementation -- it can
|
56
|
+
// be removed after we stop doing that.
|
57
|
+
export type UsePaginationFragmentType = <
|
48
58
|
TQuery: OperationType,
|
49
59
|
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
50
60
|
>(
|
51
61
|
fragmentInput: GraphQLTaggedNode,
|
52
62
|
parentFragmentRef: TKey,
|
53
|
-
)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
& (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
|
63
|
-
TKey,
|
64
|
-
>,
|
65
|
-
> {
|
63
|
+
) => ReturnType<TQuery, TKey>;
|
64
|
+
|
65
|
+
function usePaginationFragment_LEGACY<
|
66
|
+
TQuery: OperationType,
|
67
|
+
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
68
|
+
>(
|
69
|
+
fragmentInput: GraphQLTaggedNode,
|
70
|
+
parentFragmentRef: TKey,
|
71
|
+
): ReturnType<TQuery, TKey> {
|
66
72
|
const fragmentNode = getFragment(fragmentInput);
|
67
73
|
useStaticFragmentNodeWarning(
|
68
74
|
fragmentNode,
|
@@ -170,4 +176,23 @@ function useLoadMore<TQuery: OperationType>(
|
|
170
176
|
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
171
177
|
}
|
172
178
|
|
179
|
+
function usePaginationFragment<
|
180
|
+
TQuery: OperationType,
|
181
|
+
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
182
|
+
>(
|
183
|
+
fragmentInput: GraphQLTaggedNode,
|
184
|
+
parentFragmentRef: TKey,
|
185
|
+
): ReturnType<TQuery, TKey> {
|
186
|
+
const impl = HooksImplementation.get();
|
187
|
+
if (impl) {
|
188
|
+
return impl.usePaginationFragment<TQuery, TKey>(
|
189
|
+
fragmentInput,
|
190
|
+
parentFragmentRef,
|
191
|
+
);
|
192
|
+
} else {
|
193
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
194
|
+
return usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef);
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
173
198
|
module.exports = usePaginationFragment;
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {PreloadedQuery} from './EntryPointTypes.flow';
|
@@ -20,7 +18,6 @@ import type {
|
|
20
18
|
RenderPolicy,
|
21
19
|
} 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');
|
@@ -38,17 +35,17 @@ const warning = require('warning');
|
|
38
35
|
export type UsePreloadedQueryHookType = <TQuery: OperationType>(
|
39
36
|
gqlQuery: GraphQLTaggedNode,
|
40
37
|
preloadedQuery: PreloadedQuery<TQuery>,
|
41
|
-
options?: {
|
38
|
+
options?: {
|
42
39
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
43
|
-
|
40
|
+
},
|
44
41
|
) => TQuery['response'];
|
45
42
|
|
46
|
-
function
|
43
|
+
function usePreloadedQuery<TQuery: OperationType>(
|
47
44
|
gqlQuery: GraphQLTaggedNode,
|
48
45
|
preloadedQuery: PreloadedQuery<TQuery>,
|
49
|
-
options?: {
|
46
|
+
options?: {
|
50
47
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
51
|
-
|
48
|
+
},
|
52
49
|
): TQuery['response'] {
|
53
50
|
// We need to use this hook in order to be able to track if
|
54
51
|
// loadQuery was called during render
|
@@ -154,20 +151,4 @@ function usePreloadedQuery_LEGACY<TQuery: OperationType>(
|
|
154
151
|
return data;
|
155
152
|
}
|
156
153
|
|
157
|
-
function usePreloadedQuery<TQuery: OperationType>(
|
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
154
|
module.exports = (usePreloadedQuery: UsePreloadedQueryHookType);
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
@@ -35,10 +33,10 @@ export type LoaderFn<TQuery: OperationType> = (
|
|
35
33
|
options?: UseQueryLoaderLoadQueryOptions,
|
36
34
|
) => void;
|
37
35
|
|
38
|
-
export type UseQueryLoaderLoadQueryOptions = $ReadOnly<{
|
36
|
+
export type UseQueryLoaderLoadQueryOptions = $ReadOnly<{
|
39
37
|
...LoadQueryOptions,
|
40
38
|
+__environment?: ?IEnvironment,
|
41
|
-
|
39
|
+
}>;
|
42
40
|
|
43
41
|
type UseQueryLoaderHookReturnType<TQuery: OperationType> = [
|
44
42
|
?PreloadedQuery<TQuery>,
|
@@ -49,9 +47,9 @@ type UseQueryLoaderHookReturnType<TQuery: OperationType> = [
|
|
49
47
|
// NullQueryReference needs to implement referential equality,
|
50
48
|
// so that multiple NullQueryReferences can be in the same set
|
51
49
|
// (corresponding to multiple calls to disposeQuery).
|
52
|
-
type NullQueryReference = {
|
50
|
+
type NullQueryReference = {
|
53
51
|
kind: 'NullQueryReference',
|
54
|
-
|
52
|
+
};
|
55
53
|
const initialNullQueryReferenceState = {kind: 'NullQueryReference'};
|
56
54
|
|
57
55
|
function requestIsLiveQuery<TQuery: OperationType>(
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
|
@@ -20,6 +18,7 @@ import type {
|
|
20
18
|
OperationType,
|
21
19
|
} from 'relay-runtime';
|
22
20
|
|
21
|
+
const HooksImplementation = require('./HooksImplementation');
|
23
22
|
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
24
23
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
25
24
|
const {useDebugValue} = require('react');
|
@@ -38,7 +37,18 @@ type ReturnType<TQuery: OperationType, TKey: ?{+$data?: mixed, ...}> = [
|
|
38
37
|
RefetchFnDynamic<TQuery, TKey>,
|
39
38
|
];
|
40
39
|
|
41
|
-
|
40
|
+
// This separate type export is only needed as long as we are injecting
|
41
|
+
// a separate hooks implementation in ./HooksImplementation -- it can
|
42
|
+
// be removed after we stop doing that.
|
43
|
+
export type UseRefetchableFragmentType = <
|
44
|
+
TQuery: OperationType,
|
45
|
+
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
46
|
+
>(
|
47
|
+
fragmentInput: GraphQLTaggedNode,
|
48
|
+
fragmentRef: TKey,
|
49
|
+
) => ReturnType<TQuery, TKey>;
|
50
|
+
|
51
|
+
function useRefetchableFragment_LEGACY<
|
42
52
|
TQuery: OperationType,
|
43
53
|
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
44
54
|
>(
|
@@ -64,4 +74,23 @@ function useRefetchableFragment<
|
|
64
74
|
return [fragmentData, (refetch: RefetchFnDynamic<TQuery, TKey>)];
|
65
75
|
}
|
66
76
|
|
77
|
+
function useRefetchableFragment<
|
78
|
+
TQuery: OperationType,
|
79
|
+
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
80
|
+
>(
|
81
|
+
fragmentInput: GraphQLTaggedNode,
|
82
|
+
parentFragmentRef: TKey,
|
83
|
+
): ReturnType<TQuery, TKey> {
|
84
|
+
const impl = HooksImplementation.get();
|
85
|
+
if (impl) {
|
86
|
+
return impl.useRefetchableFragment<TQuery, TKey>(
|
87
|
+
fragmentInput,
|
88
|
+
parentFragmentRef,
|
89
|
+
);
|
90
|
+
} else {
|
91
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
92
|
+
return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
67
96
|
module.exports = useRefetchableFragment;
|