react-relay 20.1.1 → 21.0.1
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/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +2 -2
- package/ReactRelayFragmentContainer.js.flow +8 -9
- package/ReactRelayLocalQueryRenderer.js.flow +11 -3
- package/ReactRelayLoggingContext.js.flow +3 -3
- package/ReactRelayPaginationContainer.js.flow +32 -25
- package/ReactRelayQueryFetcher.js.flow +1 -1
- package/ReactRelayQueryRenderer.js.flow +2 -2
- package/ReactRelayQueryRendererContext.js.flow +2 -2
- package/ReactRelayRefetchContainer.js.flow +17 -14
- package/ReactRelayTestMocker.js.flow +10 -10
- package/ReactRelayTypes.d.ts +377 -0
- package/ReactRelayTypes.js.flow +47 -43
- package/RelayContext.js.flow +3 -3
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +11 -11
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +5 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +5 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +32 -32
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +9 -10
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +4 -5
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +9 -10
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +4 -5
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +5 -6
- package/buildReactRelayContainer.js.flow +5 -5
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.d.ts +89 -0
- package/hooks.js +1 -1
- package/hooks.js.flow +23 -8
- package/index.d.ts +9 -0
- package/index.js +1 -1
- package/index.js.flow +40 -14
- package/isRelayEnvironment.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.d.ts +143 -0
- package/legacy.js +1 -1
- package/legacy.js.flow +32 -13
- package/lib/ReactRelayFragmentContainer.js +1 -1
- package/lib/ReactRelayPaginationContainer.js +8 -8
- package/lib/ReactRelayRefetchContainer.js +8 -8
- package/lib/ReactRelayTestMocker.js +5 -5
- package/lib/hooks.js +18 -8
- package/lib/index.js +30 -14
- package/lib/legacy.js +26 -13
- package/lib/relay-hooks/legacy/useBlockingPaginationFragment.js +5 -5
- package/lib/relay-hooks/legacy/useRefetchableFragmentNode.js +34 -34
- package/lib/relay-hooks/loadEntryPoint.js +2 -2
- package/lib/relay-hooks/loadQuery.js +14 -14
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -10
- package/lib/relay-hooks/readFragmentInternal.js +6 -6
- package/lib/relay-hooks/rsc/serverFetchQuery.js +20 -0
- package/lib/relay-hooks/rsc/serverPreloadQuery.js +31 -0
- package/lib/relay-hooks/rsc/serverReadFragment.js +15 -0
- package/lib/relay-hooks/rsc/useQueryFromServer.js +62 -0
- package/lib/relay-hooks/useFragmentInternal_CURRENT.js +49 -25
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +81 -44
- package/lib/relay-hooks/useLazyLoadQueryNode.js +32 -19
- package/lib/relay-hooks/useMutation.js +6 -14
- package/lib/relay-hooks/useMutationAction_EXPERIMENTAL.js +26 -0
- package/lib/relay-hooks/usePreloadedQuery.js +52 -47
- package/lib/relay-hooks/useQueryLoader.js +2 -2
- package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +2 -2
- package/lib/relay-hooks/useRefetchableFragmentInternal.js +31 -31
- package/lib/rsc-client_EXPERIMENTAL.js +7 -0
- package/lib/rsc_EXPERIMENTAL.js +43 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/package.json +3 -2
- package/relay-hooks/EntryPointContainer.react.d.ts +22 -0
- package/relay-hooks/EntryPointContainer.react.js.flow +6 -6
- package/relay-hooks/EntryPointTypes.flow.js.flow +106 -108
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +23 -21
- package/relay-hooks/MatchContainer.d.ts +95 -0
- package/relay-hooks/MatchContainer.js.flow +17 -11
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +3 -9
- package/relay-hooks/ProfilerContext.d.ts +18 -0
- package/relay-hooks/QueryResource.js.flow +9 -9
- package/relay-hooks/RelayEnvironmentProvider.d.ts +16 -0
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -6
- package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +50 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -9
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -4
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +5 -6
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +27 -32
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +25 -25
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +26 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +23 -30
- package/relay-hooks/__flowtests__/utils.js.flow +17 -17
- package/relay-hooks/getConnectionState.js.flow +2 -2
- package/relay-hooks/legacy/FragmentResource.js.flow +13 -13
- package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +28 -25
- package/relay-hooks/legacy/useFragmentNode.js.flow +4 -4
- package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +79 -81
- package/relay-hooks/loadEntryPoint.d.ts +14 -0
- package/relay-hooks/loadEntryPoint.js.flow +15 -13
- package/relay-hooks/loadQuery.d.ts +20 -0
- package/relay-hooks/loadQuery.js.flow +19 -19
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +16 -13
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -7
- package/relay-hooks/readFragmentInternal.js.flow +11 -11
- package/relay-hooks/rsc/serverFetchQuery.js.flow +31 -0
- package/relay-hooks/rsc/serverPreloadQuery.js.flow +69 -0
- package/relay-hooks/rsc/serverReadFragment.js.flow +33 -0
- package/relay-hooks/rsc/useQueryFromServer.js.flow +135 -0
- package/relay-hooks/useClientQuery.d.ts +16 -0
- package/relay-hooks/useClientQuery.js.flow +2 -2
- package/relay-hooks/useEntryPointLoader.d.ts +21 -0
- package/relay-hooks/useEntryPointLoader.js.flow +11 -11
- package/relay-hooks/useFragment.d.ts +36 -0
- package/relay-hooks/useFragment.js.flow +8 -8
- package/relay-hooks/useFragmentInternal.js.flow +1 -1
- package/relay-hooks/useFragmentInternal_CURRENT.js.flow +54 -22
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +95 -46
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +5 -1
- package/relay-hooks/useLazyLoadQuery.d.ts +19 -0
- package/relay-hooks/useLazyLoadQuery.js.flow +14 -7
- package/relay-hooks/useLazyLoadQueryNode.js.flow +67 -28
- package/relay-hooks/useLoadMoreFunction.d.ts +56 -0
- package/relay-hooks/useLoadMoreFunction.js.flow +7 -6
- package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +5 -5
- package/relay-hooks/useMemoVariables.js.flow +1 -1
- package/relay-hooks/useMutation.d.ts +36 -0
- package/relay-hooks/useMutation.js.flow +9 -17
- package/relay-hooks/useMutationAction_EXPERIMENTAL.js.flow +68 -0
- package/relay-hooks/usePaginationFragment.d.ts +33 -0
- package/relay-hooks/usePaginationFragment.js.flow +19 -11
- package/relay-hooks/usePrefetchableForwardPaginationFragment.js.flow +23 -18
- package/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js.flow +23 -18
- package/relay-hooks/usePreloadedQuery.d.ts +17 -0
- package/relay-hooks/usePreloadedQuery.js.flow +119 -85
- package/relay-hooks/useQueryLoader.d.ts +33 -0
- package/relay-hooks/useQueryLoader.js.flow +28 -24
- package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +10 -10
- package/relay-hooks/useRefetchableFragment.d.ts +23 -0
- package/relay-hooks/useRefetchableFragment.js.flow +20 -11
- package/relay-hooks/useRefetchableFragmentInternal.js.flow +77 -79
- package/relay-hooks/useRelayEnvironment.d.ts +10 -0
- package/relay-hooks/useRelayLoggingContext.js.flow +1 -1
- package/relay-hooks/useSubscribeToInvalidationState.d.ts +19 -0
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
- package/relay-hooks/useSubscription.d.ts +14 -0
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/rsc-client_EXPERIMENTAL.d.ts +17 -0
- package/rsc-client_EXPERIMENTAL.js +10 -0
- package/rsc-client_EXPERIMENTAL.js.flow +23 -0
- package/rsc_EXPERIMENTAL.d.ts +48 -0
- package/rsc_EXPERIMENTAL.js +10 -0
- package/rsc_EXPERIMENTAL.js.flow +90 -0
|
@@ -30,14 +30,14 @@ const useRelayEnvironment = require('./useRelayEnvironment');
|
|
|
30
30
|
const {useCallback, useEffect, useRef, useState} = require('react');
|
|
31
31
|
const {RelayFeatureFlags, getRequest} = require('relay-runtime');
|
|
32
32
|
|
|
33
|
-
export type LoaderFn<TQuery
|
|
33
|
+
export type LoaderFn<TQuery extends OperationType> = (
|
|
34
34
|
variables: TQuery['variables'],
|
|
35
35
|
options?: UseQueryLoaderLoadQueryOptions,
|
|
36
36
|
) => void;
|
|
37
37
|
|
|
38
|
-
export type UseQueryLoaderLoadQueryOptions =
|
|
38
|
+
export type UseQueryLoaderLoadQueryOptions = Readonly<{
|
|
39
39
|
...LoadQueryOptions,
|
|
40
|
-
|
|
40
|
+
readonly __environment?: ?IEnvironment,
|
|
41
41
|
}>;
|
|
42
42
|
|
|
43
43
|
// NullQueryReference needs to implement referential equality,
|
|
@@ -51,13 +51,13 @@ const initialNullQueryReferenceState: NullQueryReference = {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
function requestIsLiveQuery<
|
|
54
|
-
TVariables
|
|
54
|
+
TVariables extends Variables,
|
|
55
55
|
TData,
|
|
56
|
-
TRawResponse
|
|
57
|
-
TQuery
|
|
56
|
+
TRawResponse extends ?{...} = void,
|
|
57
|
+
TQuery extends OperationType = {
|
|
58
58
|
response: TData,
|
|
59
59
|
variables: TVariables,
|
|
60
|
-
rawResponse?:
|
|
60
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
61
61
|
},
|
|
62
62
|
>(
|
|
63
63
|
preloadableRequest:
|
|
@@ -72,51 +72,55 @@ function requestIsLiveQuery<
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export type UseQueryLoaderHookReturnType<
|
|
75
|
-
TVariables
|
|
75
|
+
TVariables extends Variables,
|
|
76
76
|
TData,
|
|
77
|
-
TRawResponse
|
|
77
|
+
TRawResponse extends ?{...} = void,
|
|
78
78
|
> = [
|
|
79
79
|
?PreloadedQuery<{
|
|
80
80
|
response: TData,
|
|
81
81
|
variables: TVariables,
|
|
82
|
-
rawResponse?:
|
|
82
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
83
83
|
}>,
|
|
84
84
|
(variables: TVariables, options?: UseQueryLoaderLoadQueryOptions) => void,
|
|
85
85
|
() => void,
|
|
86
86
|
];
|
|
87
87
|
|
|
88
88
|
declare function useQueryLoader<
|
|
89
|
-
TVariables
|
|
89
|
+
TVariables extends Variables,
|
|
90
90
|
TData,
|
|
91
|
-
TRawResponse
|
|
91
|
+
TRawResponse extends ?{...} = void,
|
|
92
92
|
>(
|
|
93
93
|
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
|
94
94
|
): UseQueryLoaderHookReturnType<TVariables, TData>;
|
|
95
95
|
|
|
96
96
|
declare function useQueryLoader<
|
|
97
|
-
TVariables
|
|
97
|
+
TVariables extends Variables,
|
|
98
98
|
TData,
|
|
99
|
-
TRawResponse
|
|
99
|
+
TRawResponse extends ?{...} = void,
|
|
100
100
|
>(
|
|
101
101
|
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
|
102
102
|
initialQueryReference: ?PreloadedQuery<{
|
|
103
103
|
response: TData,
|
|
104
104
|
variables: TVariables,
|
|
105
|
-
rawResponse?:
|
|
105
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
106
106
|
}>,
|
|
107
107
|
): UseQueryLoaderHookReturnType<TVariables, TData>;
|
|
108
108
|
|
|
109
|
-
declare function useQueryLoader<TQuery
|
|
109
|
+
declare function useQueryLoader<TQuery extends OperationType>(
|
|
110
110
|
preloadableRequest: PreloadableConcreteRequest<TQuery>,
|
|
111
111
|
initialQueryReference?: ?PreloadedQuery<TQuery>,
|
|
112
112
|
): UseQueryLoaderHookReturnType<TQuery['variables'], TQuery['response']>;
|
|
113
113
|
|
|
114
|
-
hook useQueryLoader<
|
|
114
|
+
hook useQueryLoader<
|
|
115
|
+
TVariables extends Variables,
|
|
116
|
+
TData,
|
|
117
|
+
TRawResponse extends ?{...} = void,
|
|
118
|
+
>(
|
|
115
119
|
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
|
116
120
|
initialQueryReference?: ?PreloadedQuery<{
|
|
117
121
|
response: TData,
|
|
118
122
|
variables: TVariables,
|
|
119
|
-
rawResponse?:
|
|
123
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
120
124
|
}>,
|
|
121
125
|
): UseQueryLoaderHookReturnType<TVariables, TData> {
|
|
122
126
|
if (RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
|
|
@@ -133,21 +137,21 @@ hook useQueryLoader<TVariables: Variables, TData, TRawResponse: ?{...} = void>(
|
|
|
133
137
|
}
|
|
134
138
|
|
|
135
139
|
hook useQueryLoader_CURRENT<
|
|
136
|
-
TVariables
|
|
140
|
+
TVariables extends Variables,
|
|
137
141
|
TData,
|
|
138
|
-
TRawResponse
|
|
142
|
+
TRawResponse extends ?{...} = void,
|
|
139
143
|
>(
|
|
140
144
|
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
|
141
145
|
initialQueryReference?: ?PreloadedQuery<{
|
|
142
146
|
response: TData,
|
|
143
147
|
variables: TVariables,
|
|
144
|
-
rawResponse?:
|
|
148
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
145
149
|
}>,
|
|
146
150
|
): UseQueryLoaderHookReturnType<TVariables, TData> {
|
|
147
151
|
type QueryType = {
|
|
148
152
|
response: TData,
|
|
149
153
|
variables: TVariables,
|
|
150
|
-
rawResponse?:
|
|
154
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
151
155
|
};
|
|
152
156
|
|
|
153
157
|
/**
|
|
@@ -213,9 +217,9 @@ hook useQueryLoader_CURRENT<
|
|
|
213
217
|
const mergedOptions: ?UseQueryLoaderLoadQueryOptions =
|
|
214
218
|
options != null && options.hasOwnProperty('__environment')
|
|
215
219
|
? {
|
|
220
|
+
__nameForWarning: options.__nameForWarning,
|
|
216
221
|
fetchPolicy: options.fetchPolicy,
|
|
217
222
|
networkCacheConfig: options.networkCacheConfig,
|
|
218
|
-
__nameForWarning: options.__nameForWarning,
|
|
219
223
|
}
|
|
220
224
|
: options;
|
|
221
225
|
if (isMountedRef.current) {
|
|
@@ -223,7 +227,7 @@ hook useQueryLoader_CURRENT<
|
|
|
223
227
|
options?.__environment ?? environment,
|
|
224
228
|
preloadableRequest,
|
|
225
229
|
variables,
|
|
226
|
-
|
|
230
|
+
mergedOptions as $FlowFixMe,
|
|
227
231
|
);
|
|
228
232
|
undisposedQueryReferencesRef.current.add(updatedQueryReference);
|
|
229
233
|
setQueryReference(updatedQueryReference);
|
|
@@ -40,13 +40,13 @@ const initialNullQueryReferenceState: NullQueryReference = {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
function requestIsLiveQuery<
|
|
43
|
-
TVariables
|
|
43
|
+
TVariables extends Variables,
|
|
44
44
|
TData,
|
|
45
|
-
TRawResponse
|
|
46
|
-
TQuery
|
|
45
|
+
TRawResponse extends ?{...} = void,
|
|
46
|
+
TQuery extends OperationType = {
|
|
47
47
|
response: TData,
|
|
48
48
|
variables: TVariables,
|
|
49
|
-
rawResponse?:
|
|
49
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
50
50
|
},
|
|
51
51
|
>(
|
|
52
52
|
preloadableRequest:
|
|
@@ -63,21 +63,21 @@ function requestIsLiveQuery<
|
|
|
63
63
|
const CLEANUP_TIMEOUT = 1000 * 60 * 5; // 5 minutes;
|
|
64
64
|
|
|
65
65
|
hook useQueryLoader_EXPERIMENTAL<
|
|
66
|
-
TVariables
|
|
66
|
+
TVariables extends Variables,
|
|
67
67
|
TData,
|
|
68
|
-
TRawResponse
|
|
68
|
+
TRawResponse extends ?{...} = void,
|
|
69
69
|
>(
|
|
70
70
|
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
|
71
71
|
initialQueryReference?: ?PreloadedQuery<{
|
|
72
72
|
response: TData,
|
|
73
73
|
variables: TVariables,
|
|
74
|
-
rawResponse?:
|
|
74
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
75
75
|
}>,
|
|
76
76
|
): UseQueryLoaderHookReturnType<TVariables, TData> {
|
|
77
77
|
type QueryType = {
|
|
78
78
|
response: TData,
|
|
79
79
|
variables: TVariables,
|
|
80
|
-
rawResponse?:
|
|
80
|
+
rawResponse?: NonNullable<TRawResponse>,
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
/**
|
|
@@ -151,16 +151,16 @@ hook useQueryLoader_EXPERIMENTAL<
|
|
|
151
151
|
const mergedOptions: ?UseQueryLoaderLoadQueryOptions =
|
|
152
152
|
options != null && options.hasOwnProperty('__environment')
|
|
153
153
|
? {
|
|
154
|
+
__nameForWarning: options.__nameForWarning,
|
|
154
155
|
fetchPolicy: options.fetchPolicy,
|
|
155
156
|
networkCacheConfig: options.networkCacheConfig,
|
|
156
|
-
__nameForWarning: options.__nameForWarning,
|
|
157
157
|
}
|
|
158
158
|
: options;
|
|
159
159
|
const updatedQueryReference = loadQuery(
|
|
160
160
|
options?.__environment ?? environment,
|
|
161
161
|
preloadableRequest,
|
|
162
162
|
variables,
|
|
163
|
-
|
|
163
|
+
mergedOptions as $FlowFixMe,
|
|
164
164
|
);
|
|
165
165
|
undisposedQueryReferencesRef.current?.add(updatedQueryReference);
|
|
166
166
|
setQueryReference(updatedQueryReference);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {KeyType, KeyTypeData, RefetchFnDynamic} from '../ReactRelayTypes';
|
|
9
|
+
import {GraphQLTaggedNode, OperationType} from 'relay-runtime';
|
|
10
|
+
|
|
11
|
+
export type useRefetchableFragmentHookType<
|
|
12
|
+
TQuery extends OperationType,
|
|
13
|
+
TKey extends KeyType | null | undefined,
|
|
14
|
+
TFragmentData,
|
|
15
|
+
> = [TFragmentData, RefetchFnDynamic<TQuery, TKey>];
|
|
16
|
+
export function useRefetchableFragment<TQuery extends OperationType, TKey extends KeyType>(
|
|
17
|
+
fragmentInput: GraphQLTaggedNode,
|
|
18
|
+
fragmentRef: TKey,
|
|
19
|
+
): useRefetchableFragmentHookType<TQuery, TKey, KeyTypeData<TKey>>;
|
|
20
|
+
export function useRefetchableFragment<TQuery extends OperationType, TKey extends KeyType>(
|
|
21
|
+
fragmentInput: GraphQLTaggedNode,
|
|
22
|
+
fragmentRef: TKey | null | undefined,
|
|
23
|
+
): useRefetchableFragmentHookType<TQuery, TKey, KeyTypeData<TKey> | null | undefined>;
|
|
@@ -24,11 +24,16 @@ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
|
|
24
24
|
const {useDebugValue} = require('react');
|
|
25
25
|
const {getFragment} = require('relay-runtime');
|
|
26
26
|
|
|
27
|
-
type RefetchVariables<
|
|
27
|
+
type RefetchVariables<
|
|
28
|
+
TVariables,
|
|
29
|
+
TKey extends ?{readonly $fragmentSpreads: unknown, ...},
|
|
30
|
+
> =
|
|
28
31
|
// NOTE: This type ensures that the type of the returned variables is either:
|
|
29
32
|
// - nullable if the provided ref type is nullable
|
|
30
33
|
// - non-nullable if the provided ref type is non-nullable
|
|
31
|
-
[
|
|
34
|
+
[readonly key: TKey] extends [
|
|
35
|
+
readonly key: {readonly $fragmentSpreads: unknown, ...},
|
|
36
|
+
]
|
|
32
37
|
? Partial<TVariables>
|
|
33
38
|
: TVariables;
|
|
34
39
|
|
|
@@ -45,30 +50,34 @@ export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
|
|
|
45
50
|
export type ReturnType<
|
|
46
51
|
TVariables,
|
|
47
52
|
TData,
|
|
48
|
-
TKey
|
|
53
|
+
TKey extends ?{readonly $fragmentSpreads: unknown, ...},
|
|
49
54
|
> = [
|
|
50
55
|
// NOTE: This type ensures that the type of the returned data is either:
|
|
51
56
|
// - nullable if the provided ref type is nullable
|
|
52
57
|
// - non-nullable if the provided ref type is non-nullable
|
|
53
|
-
[
|
|
58
|
+
[readonly key: TKey] extends [
|
|
59
|
+
readonly key: {readonly $fragmentSpreads: unknown, ...},
|
|
60
|
+
]
|
|
61
|
+
? TData
|
|
62
|
+
: ?TData,
|
|
54
63
|
RefetchFn<TVariables, TKey>,
|
|
55
64
|
];
|
|
56
65
|
|
|
57
66
|
export type UseRefetchableFragmentType = <
|
|
58
|
-
TFragmentType
|
|
59
|
-
TVariables
|
|
67
|
+
TFragmentType extends FragmentType,
|
|
68
|
+
TVariables extends Variables,
|
|
60
69
|
TData,
|
|
61
|
-
TKey
|
|
70
|
+
TKey extends ?{readonly $fragmentSpreads: TFragmentType, ...},
|
|
62
71
|
>(
|
|
63
72
|
fragment: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
64
73
|
key: TKey,
|
|
65
74
|
) => ReturnType<TVariables, TData, TKey>;
|
|
66
75
|
|
|
67
76
|
hook useRefetchableFragment<
|
|
68
|
-
TFragmentType
|
|
69
|
-
TVariables
|
|
77
|
+
TFragmentType extends FragmentType,
|
|
78
|
+
TVariables extends Variables,
|
|
70
79
|
TData,
|
|
71
|
-
TKey
|
|
80
|
+
TKey extends ?{readonly $fragmentSpreads: TFragmentType, ...},
|
|
72
81
|
>(
|
|
73
82
|
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
74
83
|
fragmentRef: TKey,
|
|
@@ -88,7 +97,7 @@ hook useRefetchableFragment<
|
|
|
88
97
|
// $FlowFixMe[react-rule-hook-conditional]
|
|
89
98
|
useDebugValue({fragment: fragmentNode.name, data: fragmentData});
|
|
90
99
|
}
|
|
91
|
-
// $FlowFixMe[incompatible-
|
|
100
|
+
// $FlowFixMe[incompatible-type]
|
|
92
101
|
// $FlowFixMe[prop-missing]
|
|
93
102
|
return [fragmentData, refetch];
|
|
94
103
|
}
|
|
@@ -46,7 +46,7 @@ const {
|
|
|
46
46
|
const warning = require('warning');
|
|
47
47
|
|
|
48
48
|
export type RefetchFn<
|
|
49
|
-
TQuery
|
|
49
|
+
TQuery extends OperationType,
|
|
50
50
|
TOptions = Options,
|
|
51
51
|
> = RefetchFnExact<TQuery, TOptions>;
|
|
52
52
|
|
|
@@ -56,20 +56,20 @@ export type RefetchFn<
|
|
|
56
56
|
// - Or, expects /a subset/ of the query variables if the provided key type is
|
|
57
57
|
// /non-null/.
|
|
58
58
|
export type RefetchFnDynamic<
|
|
59
|
-
TQuery
|
|
60
|
-
TKey
|
|
59
|
+
TQuery extends OperationType,
|
|
60
|
+
TKey extends ?{readonly $data?: unknown, ...},
|
|
61
61
|
TOptions = Options,
|
|
62
|
-
> = [TKey] extends [{
|
|
62
|
+
> = [TKey] extends [{readonly $data?: unknown, ...}]
|
|
63
63
|
? RefetchFnInexact<TQuery, TOptions>
|
|
64
64
|
: RefetchFnExact<TQuery, TOptions>;
|
|
65
65
|
|
|
66
66
|
export type ReturnType<
|
|
67
|
-
TQuery
|
|
68
|
-
TKey
|
|
67
|
+
TQuery extends OperationType,
|
|
68
|
+
TKey extends ?{readonly $data?: unknown, ...},
|
|
69
69
|
TOptions = Options,
|
|
70
70
|
> = {
|
|
71
|
-
fragmentData:
|
|
72
|
-
fragmentRef:
|
|
71
|
+
fragmentData: unknown,
|
|
72
|
+
fragmentRef: unknown,
|
|
73
73
|
refetch: RefetchFnDynamic<TQuery, TKey, TOptions>,
|
|
74
74
|
};
|
|
75
75
|
|
|
@@ -89,14 +89,14 @@ type RefetchFnBase<TVars, TOptions> = (
|
|
|
89
89
|
options?: TOptions,
|
|
90
90
|
) => Disposable;
|
|
91
91
|
|
|
92
|
-
type RefetchFnExact<
|
|
93
|
-
|
|
94
|
-
TOptions,
|
|
95
|
-
>;
|
|
92
|
+
type RefetchFnExact<
|
|
93
|
+
TQuery extends OperationType,
|
|
94
|
+
TOptions = Options,
|
|
95
|
+
> = RefetchFnBase<VariablesOf<TQuery>, TOptions>;
|
|
96
96
|
type RefetchFnInexact<
|
|
97
|
-
TQuery
|
|
97
|
+
TQuery extends OperationType,
|
|
98
98
|
TOptions = Options,
|
|
99
|
-
> = RefetchFnBase
|
|
99
|
+
> = RefetchFnBase<Readonly<Partial<VariablesOf<TQuery>>>, TOptions>;
|
|
100
100
|
|
|
101
101
|
type Action =
|
|
102
102
|
| {
|
|
@@ -154,18 +154,18 @@ function reducer(state: RefetchState, action: Action): RefetchState {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
default: {
|
|
157
|
-
|
|
157
|
+
action.type as empty;
|
|
158
158
|
throw new Error('useRefetchableFragmentNode: Unexpected action type');
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
hook useRefetchableFragmentInternal<
|
|
164
|
-
TQuery
|
|
165
|
-
TKey
|
|
164
|
+
TQuery extends OperationType,
|
|
165
|
+
TKey extends ?{readonly $data?: unknown, ...},
|
|
166
166
|
>(
|
|
167
167
|
fragmentNode: ReaderFragment,
|
|
168
|
-
parentFragmentRef:
|
|
168
|
+
parentFragmentRef: unknown,
|
|
169
169
|
componentDisplayName: string,
|
|
170
170
|
): ReturnType<TQuery, TKey, InternalOptions> {
|
|
171
171
|
const parentEnvironment = useRelayEnvironment();
|
|
@@ -184,7 +184,7 @@ hook useRefetchableFragmentInternal<
|
|
|
184
184
|
refetchEnvironment: null,
|
|
185
185
|
refetchQuery: null,
|
|
186
186
|
renderPolicy: undefined,
|
|
187
|
-
});
|
|
187
|
+
} as RefetchState);
|
|
188
188
|
const {
|
|
189
189
|
fetchPolicy,
|
|
190
190
|
mirroredEnvironment,
|
|
@@ -206,14 +206,14 @@ hook useRefetchableFragmentInternal<
|
|
|
206
206
|
TQuery['variables'],
|
|
207
207
|
TQuery['response'],
|
|
208
208
|
TQuery['rawResponse'],
|
|
209
|
-
>(
|
|
209
|
+
>(refetchableRequest as $FlowFixMe);
|
|
210
210
|
|
|
211
211
|
let fragmentRef = parentFragmentRef;
|
|
212
212
|
if (shouldReset) {
|
|
213
213
|
dispatch({
|
|
214
|
-
type: 'reset',
|
|
215
214
|
environment,
|
|
216
215
|
fragmentIdentifier,
|
|
216
|
+
type: 'reset',
|
|
217
217
|
});
|
|
218
218
|
disposeQuery();
|
|
219
219
|
} else if (refetchQuery != null && queryRef != null) {
|
|
@@ -268,7 +268,6 @@ hook useRefetchableFragmentInternal<
|
|
|
268
268
|
fetchPolicy,
|
|
269
269
|
renderPolicy,
|
|
270
270
|
{
|
|
271
|
-
error: handleQueryCompleted,
|
|
272
271
|
complete: () => {
|
|
273
272
|
// Validate that the type of the object we got back matches the type
|
|
274
273
|
// of the object already in the store
|
|
@@ -282,6 +281,7 @@ hook useRefetchableFragmentInternal<
|
|
|
282
281
|
}
|
|
283
282
|
handleQueryCompleted();
|
|
284
283
|
},
|
|
284
|
+
error: handleQueryCompleted,
|
|
285
285
|
},
|
|
286
286
|
queryRef.fetchKey,
|
|
287
287
|
profilerContext,
|
|
@@ -350,12 +350,12 @@ hook useRefetchableFragmentInternal<
|
|
|
350
350
|
return {
|
|
351
351
|
fragmentData,
|
|
352
352
|
fragmentRef,
|
|
353
|
-
// $FlowFixMe[incompatible-
|
|
353
|
+
// $FlowFixMe[incompatible-type] RefetchFn not compatible with RefetchFnDynamic
|
|
354
354
|
refetch,
|
|
355
355
|
};
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
hook useRefetchFunction<TQuery
|
|
358
|
+
hook useRefetchFunction<TQuery extends OperationType>(
|
|
359
359
|
componentDisplayName: string,
|
|
360
360
|
dispatch: (
|
|
361
361
|
| {
|
|
@@ -373,13 +373,13 @@ hook useRefetchFunction<TQuery: OperationType>(
|
|
|
373
373
|
},
|
|
374
374
|
) => void,
|
|
375
375
|
disposeQuery: () => void,
|
|
376
|
-
fragmentData:
|
|
376
|
+
fragmentData: unknown,
|
|
377
377
|
fragmentIdentifier: string,
|
|
378
378
|
fragmentNode: ReaderFragment,
|
|
379
|
-
fragmentRefPathInResponse:
|
|
379
|
+
fragmentRefPathInResponse: ReadonlyArray<string | number>,
|
|
380
380
|
identifierInfo: ?RefetchableIdentifierInfo,
|
|
381
381
|
loadQuery: LoaderFn<TQuery>,
|
|
382
|
-
parentFragmentRef:
|
|
382
|
+
parentFragmentRef: unknown,
|
|
383
383
|
refetchableRequest: ConcreteRequest,
|
|
384
384
|
): RefetchFn<TQuery, InternalOptions> {
|
|
385
385
|
const isMountedRef = useIsMountedRef();
|
|
@@ -446,7 +446,7 @@ hook useRefetchFunction<TQuery: OperationType>(
|
|
|
446
446
|
// We fill in any variables not passed by the call to `refetch()` with the
|
|
447
447
|
// variables from the original parent fragment owner.
|
|
448
448
|
const refetchVariables: VariablesOf<TQuery> = {
|
|
449
|
-
...(parentVariables
|
|
449
|
+
...(parentVariables as $FlowFixMe),
|
|
450
450
|
...fragmentVariables,
|
|
451
451
|
...providedRefetchVariables,
|
|
452
452
|
};
|
|
@@ -471,7 +471,7 @@ hook useRefetchFunction<TQuery: OperationType>(
|
|
|
471
471
|
identifierValue,
|
|
472
472
|
);
|
|
473
473
|
}
|
|
474
|
-
(refetchVariables
|
|
474
|
+
(refetchVariables as $FlowFixMe)[
|
|
475
475
|
identifierInfo.identifierQueryVariableName
|
|
476
476
|
] = identifierValue;
|
|
477
477
|
}
|
|
@@ -492,18 +492,18 @@ hook useRefetchFunction<TQuery: OperationType>(
|
|
|
492
492
|
// so that they have been filtered out to include only the
|
|
493
493
|
// variables actually declared in the query.
|
|
494
494
|
loadQuery(refetchQuery.request.variables, {
|
|
495
|
-
fetchPolicy,
|
|
496
495
|
__environment: refetchEnvironment,
|
|
497
496
|
__nameForWarning: 'refetch',
|
|
497
|
+
fetchPolicy,
|
|
498
498
|
});
|
|
499
499
|
|
|
500
500
|
dispatch({
|
|
501
|
-
type: 'refetch',
|
|
502
501
|
fetchPolicy,
|
|
503
502
|
onComplete,
|
|
504
503
|
refetchEnvironment,
|
|
505
504
|
refetchQuery,
|
|
506
505
|
renderPolicy,
|
|
506
|
+
type: 'refetch',
|
|
507
507
|
});
|
|
508
508
|
return {dispose: disposeQuery};
|
|
509
509
|
},
|
|
@@ -521,33 +521,32 @@ hook useRefetchFunction<TQuery: OperationType>(
|
|
|
521
521
|
let debugFunctions;
|
|
522
522
|
if (__DEV__) {
|
|
523
523
|
debugFunctions = {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
):
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
if (
|
|
533
|
-
fragmentRefPathInResponse.length !== 1 ||
|
|
534
|
-
fragmentRefPathInResponse[0] !== 'node' ||
|
|
535
|
-
id == null
|
|
536
|
-
) {
|
|
537
|
-
return null;
|
|
524
|
+
checkSameIDAfterRefetch(
|
|
525
|
+
previousIDAndTypename: ?DebugIDandTypename,
|
|
526
|
+
refetchedFragmentRef: unknown,
|
|
527
|
+
fragmentNode: ReaderFragment,
|
|
528
|
+
componentDisplayName: string,
|
|
529
|
+
): void {
|
|
530
|
+
if (previousIDAndTypename == null || refetchedFragmentRef == null) {
|
|
531
|
+
return;
|
|
538
532
|
}
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
const
|
|
542
|
-
if (
|
|
543
|
-
|
|
533
|
+
const {ID_KEY} = require('relay-runtime');
|
|
534
|
+
// $FlowExpectedError[incompatible-use]
|
|
535
|
+
const resultID = refetchedFragmentRef[ID_KEY];
|
|
536
|
+
if (resultID != null && resultID !== previousIDAndTypename.id) {
|
|
537
|
+
warning(
|
|
538
|
+
false,
|
|
539
|
+
'Relay: Call to `refetch` returned a different id, expected ' +
|
|
540
|
+
'`%s`, got `%s`, on `%s` in `%s`. ' +
|
|
541
|
+
'Please make sure the server correctly implements ' +
|
|
542
|
+
'unique id requirement.',
|
|
543
|
+
resultID,
|
|
544
|
+
previousIDAndTypename.id,
|
|
545
|
+
fragmentNode.name,
|
|
546
|
+
componentDisplayName,
|
|
547
|
+
);
|
|
544
548
|
}
|
|
545
|
-
return {
|
|
546
|
-
id,
|
|
547
|
-
typename,
|
|
548
|
-
};
|
|
549
549
|
},
|
|
550
|
-
|
|
551
550
|
checkSameTypeAfterRefetch(
|
|
552
551
|
previousIDAndType: ?DebugIDandTypename,
|
|
553
552
|
environment: IEnvironment,
|
|
@@ -575,32 +574,31 @@ if (__DEV__) {
|
|
|
575
574
|
);
|
|
576
575
|
}
|
|
577
576
|
},
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
577
|
+
getInitialIDAndType(
|
|
578
|
+
memoRefetchVariables: ?Variables,
|
|
579
|
+
fragmentRefPathInResponse: ReadonlyArray<string | number>,
|
|
580
|
+
identifierQueryVariableName: ?string,
|
|
581
|
+
environment: IEnvironment,
|
|
582
|
+
): ?DebugIDandTypename {
|
|
583
|
+
const {Record} = require('relay-runtime');
|
|
584
|
+
const id = memoRefetchVariables?.[identifierQueryVariableName ?? 'id'];
|
|
585
|
+
if (
|
|
586
|
+
fragmentRefPathInResponse.length !== 1 ||
|
|
587
|
+
fragmentRefPathInResponse[0] !== 'node' ||
|
|
588
|
+
id == null
|
|
589
|
+
) {
|
|
590
|
+
return null;
|
|
587
591
|
}
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
const
|
|
591
|
-
if (
|
|
592
|
-
|
|
593
|
-
false,
|
|
594
|
-
'Relay: Call to `refetch` returned a different id, expected ' +
|
|
595
|
-
'`%s`, got `%s`, on `%s` in `%s`. ' +
|
|
596
|
-
'Please make sure the server correctly implements ' +
|
|
597
|
-
'unique id requirement.',
|
|
598
|
-
resultID,
|
|
599
|
-
previousIDAndTypename.id,
|
|
600
|
-
fragmentNode.name,
|
|
601
|
-
componentDisplayName,
|
|
602
|
-
);
|
|
592
|
+
const recordSource = environment.getStore().getSource();
|
|
593
|
+
const record = recordSource.get(id);
|
|
594
|
+
const typename = record == null ? null : Record.getType(record);
|
|
595
|
+
if (typename == null) {
|
|
596
|
+
return null;
|
|
603
597
|
}
|
|
598
|
+
return {
|
|
599
|
+
id,
|
|
600
|
+
typename,
|
|
601
|
+
};
|
|
604
602
|
},
|
|
605
603
|
};
|
|
606
604
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Environment } from 'relay-runtime';
|
|
9
|
+
|
|
10
|
+
export function useRelayEnvironment(): Environment;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
const ReactRelayLoggingContext = require('./../ReactRelayLoggingContext');
|
|
15
15
|
const {useContext} = require('react');
|
|
16
16
|
|
|
17
|
-
hook useRelayLoggingContext():
|
|
17
|
+
hook useRelayLoggingContext(): unknown | void {
|
|
18
18
|
return useContext(ReactRelayLoggingContext);
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {DataID, Disposable} from 'relay-runtime';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This hook subscribes a callback to the invalidation state of the given data
|
|
12
|
+
* ids.
|
|
13
|
+
* Any time the invalidation state of the given data ids changes, the provided
|
|
14
|
+
* callback will be called.
|
|
15
|
+
* If new ids or a new callback are provided, the subscription will be
|
|
16
|
+
* re-established and the previous one will be disposed.
|
|
17
|
+
* The subscription will automatically be disposed on unmount
|
|
18
|
+
*/
|
|
19
|
+
export function useSubscribeToInvalidationState(dataIDs: readonly DataID[], callback: () => void): Disposable;
|
|
@@ -26,7 +26,7 @@ const {useEffect, useRef} = require('react');
|
|
|
26
26
|
* The subscription will automatically be disposed on unmount
|
|
27
27
|
*/
|
|
28
28
|
hook useSubscribeToInvalidationState(
|
|
29
|
-
dataIDs:
|
|
29
|
+
dataIDs: ReadonlyArray<DataID>,
|
|
30
30
|
callback: () => void,
|
|
31
31
|
): Disposable {
|
|
32
32
|
const environment = useRelayEnvironment();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {GraphQLSubscriptionConfig, OperationType, requestSubscription} from 'relay-runtime';
|
|
9
|
+
|
|
10
|
+
export function useSubscription<TSubscriptionPayload extends OperationType>(
|
|
11
|
+
// The actual subtype of OperationType is required to allow for type inference inside GraphQLSubscriptionConfig.s
|
|
12
|
+
config: GraphQLSubscriptionConfig<TSubscriptionPayload>,
|
|
13
|
+
requestSubscriptionFn?: typeof requestSubscription,
|
|
14
|
+
): void;
|