react-relay 13.1.1 → 14.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactRelayContainerUtils.js.flow +0 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +0 -2
- package/ReactRelayFragmentContainer.js.flow +7 -6
- package/ReactRelayFragmentMockRenderer.js.flow +0 -2
- package/ReactRelayLocalQueryRenderer.js.flow +1 -3
- package/ReactRelayPaginationContainer.js.flow +13 -10
- package/ReactRelayQueryFetcher.js.flow +10 -11
- package/ReactRelayQueryRenderer.js.flow +15 -16
- package/ReactRelayQueryRendererContext.js.flow +1 -3
- package/ReactRelayRefetchContainer.js.flow +10 -7
- 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/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +2 -2
- package/assertFragmentMap.js.flow +0 -2
- package/buildReactRelayContainer.js.flow +2 -4
- 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/jest-react/internalAct.js.flow +25 -9
- 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 +2 -2
- package/lib/ReactRelayQueryRenderer.js +2 -4
- 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/jest-react/internalAct.js +24 -4
- package/lib/legacy.js +0 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +0 -1
- package/lib/readContext.js +2 -2
- package/lib/relay-hooks/EntryPointContainer.react.js +0 -1
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -1
- package/lib/relay-hooks/FragmentResource.js +68 -29
- package/lib/relay-hooks/HooksImplementation.js +29 -0
- 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 +2 -2
- package/lib/relay-hooks/ProfilerContext.js +0 -1
- package/lib/relay-hooks/QueryResource.js +5 -168
- 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 +8 -13
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -1
- package/lib/relay-hooks/react-cache/RelayReactCache.js +36 -0
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +344 -0
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +239 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +598 -0
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +50 -0
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +55 -0
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +150 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +124 -0
- 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 +15 -2
- package/lib/relay-hooks/useFragmentNode.js +0 -1
- package/lib/relay-hooks/useIsMountedRef.js +0 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +4 -2
- 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 +5 -7
- package/lib/relay-hooks/usePaginationFragment.js +15 -3
- package/lib/relay-hooks/usePreloadedQuery.js +4 -2
- 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 +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/readContext.js.flow +1 -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 +80 -37
- package/relay-hooks/HooksImplementation.js.flow +43 -0
- 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 +11 -6
- package/relay-hooks/ProfilerContext.js.flow +0 -2
- package/relay-hooks/QueryResource.js.flow +12 -209
- 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__/__generated__/useFragmentFlowtest_user.graphql.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.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/loadQuery.js.flow +2 -1
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +11 -20
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +0 -2
- package/relay-hooks/react-cache/RelayReactCache.js.flow +40 -0
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +430 -0
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +599 -0
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +72 -0
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +70 -0
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +171 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +151 -0
- 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 +17 -12
- package/relay-hooks/useFragmentNode.js.flow +2 -4
- package/relay-hooks/useIsMountedRef.js.flow +1 -3
- package/relay-hooks/useLazyLoadQuery.js.flow +17 -5
- 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 +5 -7
- package/relay-hooks/usePaginationFragment.js.flow +44 -19
- package/relay-hooks/usePreloadedQuery.js.flow +14 -5
- package/relay-hooks/useQueryLoader.js.flow +4 -6
- package/relay-hooks/useRefetchableFragment.js.flow +32 -3
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -25
- 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 +14 -10
|
@@ -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,12 +9,11 @@
|
|
|
9
9
|
* @format
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
import type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
|
|
17
15
|
|
|
16
|
+
const HooksImplementation = require('./HooksImplementation');
|
|
18
17
|
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
|
19
18
|
const useFragmentNode = require('./useFragmentNode');
|
|
20
19
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
|
@@ -32,25 +31,19 @@ declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
|
32
31
|
key: HasSpread<TFragmentType>,
|
|
33
32
|
): TData;
|
|
34
33
|
|
|
35
|
-
// if the key is nullable, return nullable value
|
|
36
|
-
declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
37
|
-
fragment: Fragment<TFragmentType, TData>,
|
|
38
|
-
key: ?HasSpread<TFragmentType>,
|
|
39
|
-
): ?TData;
|
|
40
|
-
|
|
41
34
|
// if the key is a non-nullable array of keys, return non-nullable array
|
|
42
35
|
declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
43
36
|
fragment: Fragment<TFragmentType, TData>,
|
|
44
37
|
key: $ReadOnlyArray<HasSpread<TFragmentType>>,
|
|
45
38
|
): TData;
|
|
46
39
|
|
|
47
|
-
// if the key is
|
|
40
|
+
// if the key is null/void, return null/void value
|
|
48
41
|
declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
49
42
|
fragment: Fragment<TFragmentType, TData>,
|
|
50
|
-
key:
|
|
51
|
-
):
|
|
43
|
+
key: null | void,
|
|
44
|
+
): null | void;
|
|
52
45
|
|
|
53
|
-
function
|
|
46
|
+
function useFragment_LEGACY(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
|
54
47
|
// We need to use this hook in order to be able to track if
|
|
55
48
|
// loadQuery was called during render
|
|
56
49
|
useTrackLoadQueryInRender();
|
|
@@ -65,4 +58,16 @@ function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
|
|
65
58
|
return data;
|
|
66
59
|
}
|
|
67
60
|
|
|
61
|
+
function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
|
62
|
+
const impl = HooksImplementation.get();
|
|
63
|
+
if (impl) {
|
|
64
|
+
// $FlowFixMe This is safe because impl.useFragment has the type of useFragment...
|
|
65
|
+
return impl.useFragment(fragment, key);
|
|
66
|
+
// (i.e. type declared above, but not the supertype used in this function definition)
|
|
67
|
+
} else {
|
|
68
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
69
|
+
return useFragment_LEGACY(fragment, key);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
module.exports = useFragment;
|
|
@@ -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,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 {
|
|
@@ -29,15 +27,29 @@ const {
|
|
|
29
27
|
__internal: {fetchQuery},
|
|
30
28
|
} = require('relay-runtime');
|
|
31
29
|
|
|
30
|
+
// This separate type export is only needed as long as we are injecting
|
|
31
|
+
// a separate hooks implementation in ./HooksImplementation -- it can
|
|
32
|
+
// be removed after we stop doing that.
|
|
33
|
+
export type UseLazyLoadQueryHookType = <TVariables: Variables, TData>(
|
|
34
|
+
gqlQuery: Query<TVariables, TData>,
|
|
35
|
+
variables: TVariables,
|
|
36
|
+
options?: {
|
|
37
|
+
fetchKey?: string | number,
|
|
38
|
+
fetchPolicy?: FetchPolicy,
|
|
39
|
+
networkCacheConfig?: CacheConfig,
|
|
40
|
+
UNSTABLE_renderPolicy?: RenderPolicy,
|
|
41
|
+
},
|
|
42
|
+
) => TData;
|
|
43
|
+
|
|
32
44
|
function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
33
45
|
gqlQuery: Query<TVariables, TData>,
|
|
34
46
|
variables: TVariables,
|
|
35
|
-
options?: {
|
|
47
|
+
options?: {
|
|
36
48
|
fetchKey?: string | number,
|
|
37
49
|
fetchPolicy?: FetchPolicy,
|
|
38
50
|
networkCacheConfig?: CacheConfig,
|
|
39
51
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
|
40
|
-
|
|
52
|
+
},
|
|
41
53
|
): TData {
|
|
42
54
|
// We need to use this hook in order to be able to track if
|
|
43
55
|
// loadQuery was called during render
|
|
@@ -63,4 +75,4 @@ function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
|
63
75
|
return data;
|
|
64
76
|
}
|
|
65
77
|
|
|
66
|
-
module.exports = useLazyLoadQuery;
|
|
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,
|
|
@@ -97,6 +95,9 @@ function useMutation<TMutation: MutationParameters>(
|
|
|
97
95
|
|
|
98
96
|
const commit = useCallback(
|
|
99
97
|
(config: UseMutationConfig<TMutation>) => {
|
|
98
|
+
if (isMountedRef.current) {
|
|
99
|
+
setMutationInFlight(true);
|
|
100
|
+
}
|
|
100
101
|
const disposable = commitMutationFn(environment, {
|
|
101
102
|
...config,
|
|
102
103
|
mutation,
|
|
@@ -117,9 +118,6 @@ function useMutation<TMutation: MutationParameters>(
|
|
|
117
118
|
},
|
|
118
119
|
});
|
|
119
120
|
inFlightMutationsRef.current.add(disposable);
|
|
120
|
-
if (isMountedRef.current) {
|
|
121
|
-
setMutationInFlight(true);
|
|
122
|
-
}
|
|
123
121
|
return disposable;
|
|
124
122
|
},
|
|
125
123
|
[cleanup, commitMutationFn, environment, isMountedRef, mutation],
|
|
@@ -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';
|
|
@@ -31,12 +29,23 @@ const {
|
|
|
31
29
|
} = require('relay-runtime');
|
|
32
30
|
const warning = require('warning');
|
|
33
31
|
|
|
32
|
+
// This separate type export is only needed as long as we are injecting
|
|
33
|
+
// a separate hooks implementation in ./HooksImplementation -- it can
|
|
34
|
+
// be removed after we stop doing that.
|
|
35
|
+
export type UsePreloadedQueryHookType = <TQuery: OperationType>(
|
|
36
|
+
gqlQuery: GraphQLTaggedNode,
|
|
37
|
+
preloadedQuery: PreloadedQuery<TQuery>,
|
|
38
|
+
options?: {
|
|
39
|
+
UNSTABLE_renderPolicy?: RenderPolicy,
|
|
40
|
+
},
|
|
41
|
+
) => TQuery['response'];
|
|
42
|
+
|
|
34
43
|
function usePreloadedQuery<TQuery: OperationType>(
|
|
35
44
|
gqlQuery: GraphQLTaggedNode,
|
|
36
45
|
preloadedQuery: PreloadedQuery<TQuery>,
|
|
37
|
-
options?: {
|
|
46
|
+
options?: {
|
|
38
47
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
|
39
|
-
|
|
48
|
+
},
|
|
40
49
|
): TQuery['response'] {
|
|
41
50
|
// We need to use this hook in order to be able to track if
|
|
42
51
|
// loadQuery was called during render
|
|
@@ -142,4 +151,4 @@ function usePreloadedQuery<TQuery: OperationType>(
|
|
|
142
151
|
return data;
|
|
143
152
|
}
|
|
144
153
|
|
|
145
|
-
module.exports = usePreloadedQuery;
|
|
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;
|