react-relay 13.2.0 → 14.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayFragmentContainer.js.flow +7 -4
- package/ReactRelayPaginationContainer.js.flow +13 -8
- package/ReactRelayQueryFetcher.js.flow +1 -0
- package/ReactRelayQueryRenderer.js.flow +6 -2
- package/ReactRelayRefetchContainer.js.flow +10 -3
- 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/buildReactRelayContainer.js.flow +2 -2
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/ReactRelayQueryFetcher.js +1 -0
- package/lib/ReactRelayQueryRenderer.js +0 -1
- package/lib/readContext.js +2 -1
- package/lib/relay-hooks/FragmentResource.js +52 -10
- package/lib/relay-hooks/HooksImplementation.js +29 -0
- package/lib/relay-hooks/MatchContainer.js +1 -0
- package/lib/relay-hooks/QueryResource.js +2 -1
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +203 -56
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +254 -109
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +51 -0
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +13 -2
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +125 -0
- package/lib/relay-hooks/useFragment.js +15 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +18 -2
- package/lib/relay-hooks/useMutation.js +4 -5
- package/lib/relay-hooks/usePreloadedQuery.js +18 -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 +1 -0
- package/relay-hooks/FragmentResource.js.flow +55 -9
- package/relay-hooks/HooksImplementation.js.flow +45 -0
- package/relay-hooks/MatchContainer.js.flow +8 -1
- package/relay-hooks/QueryResource.js.flow +4 -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/loadQuery.js.flow +2 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +245 -64
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +242 -99
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +74 -0
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +10 -4
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +153 -0
- package/relay-hooks/useFragment.js.flow +17 -10
- package/relay-hooks/useLazyLoadQuery.js.flow +38 -3
- package/relay-hooks/useMutation.js.flow +3 -3
- package/relay-hooks/usePreloadedQuery.js.flow +30 -2
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -11
- package/relay-hooks/useSubscription.js.flow +14 -8
@@ -0,0 +1,153 @@
|
|
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
|
+
* @flow strict-local
|
8
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
// flowlint ambiguous-object-type:error
|
13
|
+
|
14
|
+
'use strict';
|
15
|
+
|
16
|
+
import type {PreloadedQuery} from '../EntryPointTypes.flow';
|
17
|
+
import type {
|
18
|
+
GraphQLTaggedNode,
|
19
|
+
OperationType,
|
20
|
+
RenderPolicy,
|
21
|
+
} from 'relay-runtime';
|
22
|
+
|
23
|
+
const {useTrackLoadQueryInRender} = require('../loadQuery');
|
24
|
+
const useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
|
25
|
+
const useRelayEnvironment = require('../useRelayEnvironment');
|
26
|
+
const getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
|
27
|
+
const useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
28
|
+
const invariant = require('invariant');
|
29
|
+
const {useDebugValue, useEffect} = require('react');
|
30
|
+
const {
|
31
|
+
__internal: {fetchQueryDeduped, fetchQuery},
|
32
|
+
} = require('relay-runtime');
|
33
|
+
const warning = require('warning');
|
34
|
+
|
35
|
+
function usePreloadedQuery_REACT_CACHE<TQuery: OperationType>(
|
36
|
+
gqlQuery: GraphQLTaggedNode,
|
37
|
+
preloadedQuery: PreloadedQuery<TQuery>,
|
38
|
+
options?: {|
|
39
|
+
UNSTABLE_renderPolicy?: RenderPolicy,
|
40
|
+
|},
|
41
|
+
): TQuery['response'] {
|
42
|
+
const environment = useRelayEnvironment();
|
43
|
+
|
44
|
+
useTrackLoadQueryInRender();
|
45
|
+
|
46
|
+
const {fetchKey, fetchPolicy, source, variables, networkCacheConfig} =
|
47
|
+
preloadedQuery;
|
48
|
+
const operation = useMemoOperationDescriptor(
|
49
|
+
gqlQuery,
|
50
|
+
variables,
|
51
|
+
networkCacheConfig,
|
52
|
+
);
|
53
|
+
|
54
|
+
let fetchObservable;
|
55
|
+
if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
|
56
|
+
invariant(
|
57
|
+
operation.request.node.params.name === preloadedQuery.name,
|
58
|
+
'usePreloadedQuery(): Expected data to be prefetched for query `%s`, ' +
|
59
|
+
'got prefetch results for query `%s`.',
|
60
|
+
operation.request.node.params.name,
|
61
|
+
preloadedQuery.name,
|
62
|
+
);
|
63
|
+
fetchObservable = fetchQueryDeduped(
|
64
|
+
environment,
|
65
|
+
operation.request.identifier,
|
66
|
+
() => {
|
67
|
+
if (environment === preloadedQuery.environment && source != null) {
|
68
|
+
return environment.executeWithSource({operation, source});
|
69
|
+
} else {
|
70
|
+
return environment.execute({operation});
|
71
|
+
}
|
72
|
+
},
|
73
|
+
);
|
74
|
+
} else {
|
75
|
+
warning(
|
76
|
+
preloadedQuery.isDisposed === false,
|
77
|
+
'usePreloadedQuery(): Expected preloadedQuery to not be disposed yet. ' +
|
78
|
+
'This is because disposing the query marks it for future garbage ' +
|
79
|
+
'collection, and as such query results may no longer be present in the Relay ' +
|
80
|
+
'store. In the future, this will become a hard error.',
|
81
|
+
);
|
82
|
+
const fallbackFetchObservable = fetchQuery(environment, operation);
|
83
|
+
if (source != null && environment === preloadedQuery.environment) {
|
84
|
+
// If the source observable exists and the environments match, reuse
|
85
|
+
// the source observable.
|
86
|
+
// If the source observable happens to be empty, we need to fall back
|
87
|
+
// and re-execute and de-dupe the query (at render time).
|
88
|
+
fetchObservable = source.ifEmpty(fallbackFetchObservable);
|
89
|
+
} else if (environment !== preloadedQuery.environment) {
|
90
|
+
// If a call to loadQuery is made with a particular environment, and that
|
91
|
+
// preloaded query is passed to usePreloadedQuery in a different environment
|
92
|
+
// context, we cannot re-use the existing preloaded query.
|
93
|
+
// Instead, we need to fall back and re-execute and de-dupe the query with
|
94
|
+
// the new environment (at render time).
|
95
|
+
// TODO T68036756 track occurences of this warning and turn it into a hard error
|
96
|
+
warning(
|
97
|
+
false,
|
98
|
+
'usePreloadedQuery(): usePreloadedQuery was passed a preloaded query ' +
|
99
|
+
'that was created with a different environment than the one that is currently ' +
|
100
|
+
'in context. In the future, this will become a hard error.',
|
101
|
+
);
|
102
|
+
fetchObservable = fallbackFetchObservable;
|
103
|
+
} else {
|
104
|
+
// if (source == null)
|
105
|
+
// If the source observable does not exist, we need to
|
106
|
+
// fall back and re-execute and de-dupe the query (at render time).
|
107
|
+
fetchObservable = fallbackFetchObservable;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
// Get the query going if needed -- this may suspend.
|
112
|
+
const [queryResult, effect] = getQueryResultOrFetchQuery(
|
113
|
+
environment,
|
114
|
+
operation,
|
115
|
+
{
|
116
|
+
fetchPolicy,
|
117
|
+
renderPolicy: options?.UNSTABLE_renderPolicy,
|
118
|
+
fetchKey,
|
119
|
+
fetchObservable,
|
120
|
+
},
|
121
|
+
);
|
122
|
+
|
123
|
+
useEffect(effect);
|
124
|
+
|
125
|
+
// Read the query's root fragment -- this may suspend.
|
126
|
+
const {fragmentNode, fragmentRef} = queryResult;
|
127
|
+
// $FlowExpectedError[incompatible-return] Is this a fixable incompatible-return?
|
128
|
+
const data = useFragmentInternal(
|
129
|
+
fragmentNode,
|
130
|
+
fragmentRef,
|
131
|
+
'usePreloadedQuery()',
|
132
|
+
{
|
133
|
+
fetchPolicy: fetchPolicy,
|
134
|
+
networkCacheConfig: networkCacheConfig,
|
135
|
+
},
|
136
|
+
);
|
137
|
+
|
138
|
+
if (__DEV__) {
|
139
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
140
|
+
useDebugValue({
|
141
|
+
query: preloadedQuery.name,
|
142
|
+
variables: preloadedQuery.variables,
|
143
|
+
data,
|
144
|
+
fetchKey,
|
145
|
+
fetchPolicy,
|
146
|
+
renderPolicy: options?.UNSTABLE_renderPolicy,
|
147
|
+
});
|
148
|
+
}
|
149
|
+
|
150
|
+
return data;
|
151
|
+
}
|
152
|
+
|
153
|
+
module.exports = usePreloadedQuery_REACT_CACHE;
|
@@ -15,6 +15,7 @@
|
|
15
15
|
|
16
16
|
import type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
|
17
17
|
|
18
|
+
const HooksImplementation = require('./HooksImplementation');
|
18
19
|
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
19
20
|
const useFragmentNode = require('./useFragmentNode');
|
20
21
|
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
@@ -32,25 +33,19 @@ declare function useFragment<TFragmentType: FragmentType, TData>(
|
|
32
33
|
key: HasSpread<TFragmentType>,
|
33
34
|
): TData;
|
34
35
|
|
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
36
|
// if the key is a non-nullable array of keys, return non-nullable array
|
42
37
|
declare function useFragment<TFragmentType: FragmentType, TData>(
|
43
38
|
fragment: Fragment<TFragmentType, TData>,
|
44
39
|
key: $ReadOnlyArray<HasSpread<TFragmentType>>,
|
45
40
|
): TData;
|
46
41
|
|
47
|
-
// if the key is
|
42
|
+
// if the key is null/void, return null/void value
|
48
43
|
declare function useFragment<TFragmentType: FragmentType, TData>(
|
49
44
|
fragment: Fragment<TFragmentType, TData>,
|
50
|
-
key:
|
51
|
-
):
|
45
|
+
key: null | void,
|
46
|
+
): null | void;
|
52
47
|
|
53
|
-
function
|
48
|
+
function useFragment_LEGACY(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
54
49
|
// We need to use this hook in order to be able to track if
|
55
50
|
// loadQuery was called during render
|
56
51
|
useTrackLoadQueryInRender();
|
@@ -65,4 +60,16 @@ function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
|
65
60
|
return data;
|
66
61
|
}
|
67
62
|
|
63
|
+
function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
64
|
+
const impl = HooksImplementation.get();
|
65
|
+
if (impl) {
|
66
|
+
// $FlowFixMe This is safe because impl.useFragment has the type of useFragment...
|
67
|
+
return impl.useFragment(fragment, key);
|
68
|
+
// (i.e. type declared above, but not the supertype used in this function definition)
|
69
|
+
} else {
|
70
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
71
|
+
return useFragment_LEGACY(fragment, key);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
68
75
|
module.exports = useFragment;
|
@@ -15,12 +15,14 @@
|
|
15
15
|
|
16
16
|
import type {
|
17
17
|
CacheConfig,
|
18
|
+
ClientQuery,
|
18
19
|
FetchPolicy,
|
19
20
|
Query,
|
20
21
|
RenderPolicy,
|
21
22
|
Variables,
|
22
23
|
} from 'relay-runtime';
|
23
24
|
|
25
|
+
const HooksImplementation = require('./HooksImplementation');
|
24
26
|
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
25
27
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
26
28
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
@@ -29,8 +31,22 @@ const {
|
|
29
31
|
__internal: {fetchQuery},
|
30
32
|
} = require('relay-runtime');
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
// This separate type export is only needed as long as we are injecting
|
35
|
+
// a separate hooks implementation in ./HooksImplementation -- it can
|
36
|
+
// be removed after we stop doing that.
|
37
|
+
export type UseLazyLoadQueryHookType = <TVariables: Variables, TData>(
|
38
|
+
gqlQuery: Query<TVariables, TData> | ClientQuery<TVariables, TData>,
|
39
|
+
variables: TVariables,
|
40
|
+
options?: {|
|
41
|
+
fetchKey?: string | number,
|
42
|
+
fetchPolicy?: FetchPolicy,
|
43
|
+
networkCacheConfig?: CacheConfig,
|
44
|
+
UNSTABLE_renderPolicy?: RenderPolicy,
|
45
|
+
|},
|
46
|
+
) => TData;
|
47
|
+
|
48
|
+
function useLazyLoadQuery_LEGACY<TVariables: Variables, TData>(
|
49
|
+
gqlQuery: Query<TVariables, TData> | ClientQuery<TVariables, TData>,
|
34
50
|
variables: TVariables,
|
35
51
|
options?: {|
|
36
52
|
fetchKey?: string | number,
|
@@ -63,4 +79,23 @@ function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
63
79
|
return data;
|
64
80
|
}
|
65
81
|
|
66
|
-
|
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
|
+
module.exports = (useLazyLoadQuery: UseLazyLoadQueryHookType);
|
@@ -97,6 +97,9 @@ function useMutation<TMutation: MutationParameters>(
|
|
97
97
|
|
98
98
|
const commit = useCallback(
|
99
99
|
(config: UseMutationConfig<TMutation>) => {
|
100
|
+
if (isMountedRef.current) {
|
101
|
+
setMutationInFlight(true);
|
102
|
+
}
|
100
103
|
const disposable = commitMutationFn(environment, {
|
101
104
|
...config,
|
102
105
|
mutation,
|
@@ -117,9 +120,6 @@ function useMutation<TMutation: MutationParameters>(
|
|
117
120
|
},
|
118
121
|
});
|
119
122
|
inFlightMutationsRef.current.add(disposable);
|
120
|
-
if (isMountedRef.current) {
|
121
|
-
setMutationInFlight(true);
|
122
|
-
}
|
123
123
|
return disposable;
|
124
124
|
},
|
125
125
|
[cleanup, commitMutationFn, environment, isMountedRef, mutation],
|
@@ -20,6 +20,7 @@ import type {
|
|
20
20
|
RenderPolicy,
|
21
21
|
} from 'relay-runtime';
|
22
22
|
|
23
|
+
const HooksImplementation = require('./HooksImplementation');
|
23
24
|
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
24
25
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
25
26
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
@@ -31,7 +32,18 @@ const {
|
|
31
32
|
} = require('relay-runtime');
|
32
33
|
const warning = require('warning');
|
33
34
|
|
34
|
-
|
35
|
+
// This separate type export is only needed as long as we are injecting
|
36
|
+
// a separate hooks implementation in ./HooksImplementation -- it can
|
37
|
+
// be removed after we stop doing that.
|
38
|
+
export type UsePreloadedQueryHookType = <TQuery: OperationType>(
|
39
|
+
gqlQuery: GraphQLTaggedNode,
|
40
|
+
preloadedQuery: PreloadedQuery<TQuery>,
|
41
|
+
options?: {|
|
42
|
+
UNSTABLE_renderPolicy?: RenderPolicy,
|
43
|
+
|},
|
44
|
+
) => TQuery['response'];
|
45
|
+
|
46
|
+
function usePreloadedQuery_LEGACY<TQuery: OperationType>(
|
35
47
|
gqlQuery: GraphQLTaggedNode,
|
36
48
|
preloadedQuery: PreloadedQuery<TQuery>,
|
37
49
|
options?: {|
|
@@ -142,4 +154,20 @@ function usePreloadedQuery<TQuery: OperationType>(
|
|
142
154
|
return data;
|
143
155
|
}
|
144
156
|
|
145
|
-
|
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
|
+
module.exports = (usePreloadedQuery: UsePreloadedQueryHookType);
|
@@ -15,6 +15,7 @@
|
|
15
15
|
|
16
16
|
import type {LoaderFn} from './useQueryLoader';
|
17
17
|
import type {
|
18
|
+
ConcreteRequest,
|
18
19
|
Disposable,
|
19
20
|
FetchPolicy,
|
20
21
|
IEnvironment,
|
@@ -241,7 +242,7 @@ function useRefetchableFragmentNode<
|
|
241
242
|
);
|
242
243
|
}
|
243
244
|
|
244
|
-
const handleQueryCompleted = maybeError => {
|
245
|
+
const handleQueryCompleted = (maybeError: void | Error) => {
|
245
246
|
onComplete && onComplete(maybeError ?? null);
|
246
247
|
};
|
247
248
|
|
@@ -358,17 +359,31 @@ function useRefetchableFragmentNode<
|
|
358
359
|
}
|
359
360
|
|
360
361
|
function useRefetchFunction<TQuery: OperationType>(
|
361
|
-
componentDisplayName,
|
362
|
-
dispatch
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
362
|
+
componentDisplayName: string,
|
363
|
+
dispatch: (
|
364
|
+
| {|
|
365
|
+
environment: IEnvironment,
|
366
|
+
fragmentIdentifier: string,
|
367
|
+
type: 'reset',
|
368
|
+
|}
|
369
|
+
| {|
|
370
|
+
fetchPolicy?: FetchPolicy,
|
371
|
+
onComplete?: (Error | null) => void,
|
372
|
+
refetchEnvironment: ?IEnvironment,
|
373
|
+
refetchQuery: OperationDescriptor,
|
374
|
+
renderPolicy?: RenderPolicy,
|
375
|
+
type: 'refetch',
|
376
|
+
|},
|
377
|
+
) => void,
|
378
|
+
disposeQuery: () => void,
|
379
|
+
fragmentData: mixed,
|
380
|
+
fragmentIdentifier: string,
|
381
|
+
fragmentNode: ReaderFragment,
|
382
|
+
fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
|
383
|
+
identifierField: ?string,
|
369
384
|
loadQuery: LoaderFn<TQuery>,
|
370
|
-
parentFragmentRef,
|
371
|
-
refetchableRequest,
|
385
|
+
parentFragmentRef: mixed,
|
386
|
+
refetchableRequest: ConcreteRequest,
|
372
387
|
): RefetchFn<TQuery, InternalOptions> {
|
373
388
|
const isMountedRef = useIsMountedRef();
|
374
389
|
const identifierValue =
|
@@ -16,27 +16,33 @@ import type {
|
|
16
16
|
Disposable,
|
17
17
|
GraphQLSubscriptionConfig,
|
18
18
|
IEnvironment,
|
19
|
-
SubscriptionParameters,
|
20
19
|
} from 'relay-runtime';
|
21
20
|
|
22
21
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
23
22
|
const {useEffect} = require('react');
|
24
23
|
const {requestSubscription} = require('relay-runtime');
|
25
24
|
|
26
|
-
type RequestSubscriptionFn<
|
25
|
+
type RequestSubscriptionFn<TVariables, TData, TRawResponse> = (
|
27
26
|
environment: IEnvironment,
|
28
|
-
config: GraphQLSubscriptionConfig<
|
27
|
+
config: GraphQLSubscriptionConfig<TVariables, TData, TRawResponse>,
|
29
28
|
) => Disposable;
|
30
29
|
|
31
|
-
function useSubscription<
|
32
|
-
config: GraphQLSubscriptionConfig<
|
33
|
-
requestSubscriptionFn?: RequestSubscriptionFn<
|
30
|
+
function useSubscription<TVariables, TData, TRawResponse>(
|
31
|
+
config: GraphQLSubscriptionConfig<TVariables, TData, TRawResponse>,
|
32
|
+
requestSubscriptionFn?: RequestSubscriptionFn<
|
33
|
+
TVariables,
|
34
|
+
TData,
|
35
|
+
TRawResponse,
|
36
|
+
>,
|
34
37
|
): void {
|
35
38
|
// N.B. this will re-subscribe every render if config or requestSubscriptionFn
|
36
39
|
// are not memoized.
|
37
40
|
// Please do not pass an object defined in-line.
|
38
|
-
const actualRequestSubscription: RequestSubscriptionFn<
|
39
|
-
|
41
|
+
const actualRequestSubscription: RequestSubscriptionFn<
|
42
|
+
TVariables,
|
43
|
+
TData,
|
44
|
+
TRawResponse,
|
45
|
+
> = requestSubscriptionFn ?? (requestSubscription: $FlowFixMe);
|
40
46
|
const environment = useRelayEnvironment();
|
41
47
|
useEffect(() => {
|
42
48
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|