react-relay 14.1.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +19 -5
- package/ReactRelayQueryRenderer.js.flow +32 -1
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +1 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +7 -5
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +2 -2
- package/lib/ReactRelayContext.js +3 -3
- package/lib/ReactRelayFragmentContainer.js +39 -66
- package/lib/ReactRelayFragmentMockRenderer.js +2 -3
- package/lib/ReactRelayLocalQueryRenderer.js +18 -30
- package/lib/ReactRelayPaginationContainer.js +66 -159
- package/lib/ReactRelayQueryFetcher.js +48 -74
- package/lib/ReactRelayQueryRenderer.js +62 -82
- package/lib/ReactRelayQueryRendererContext.js +2 -1
- package/lib/ReactRelayRefetchContainer.js +52 -99
- package/lib/ReactRelayTestMocker.js +32 -66
- package/lib/ReactRelayTypes.js +2 -0
- package/lib/RelayContext.js +4 -6
- package/lib/assertFragmentMap.js +3 -4
- package/lib/buildReactRelayContainer.js +10 -25
- package/lib/getRootVariablesForFragments.js +5 -8
- package/lib/hooks.js +5 -17
- package/lib/index.js +5 -24
- package/lib/isRelayEnvironment.js +5 -3
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -7
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -7
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
- package/lib/relay-hooks/FragmentResource.js +102 -196
- package/lib/relay-hooks/HooksImplementation.js +2 -5
- package/lib/relay-hooks/InternalLogger.js +2 -2
- package/lib/relay-hooks/LRUCache.js +2 -19
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
- package/lib/relay-hooks/MatchContainer.js +14 -22
- package/lib/relay-hooks/ProfilerContext.js +3 -2
- package/lib/relay-hooks/QueryResource.js +30 -99
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
- package/lib/relay-hooks/SuspenseResource.js +8 -31
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +41 -77
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
- package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
- package/lib/relay-hooks/useClientQuery.js +3 -6
- package/lib/relay-hooks/useEntryPointLoader.js +17 -36
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
- package/lib/relay-hooks/useFragment.js +8 -18
- package/lib/relay-hooks/useFragmentNode.js +20 -31
- package/lib/relay-hooks/useIsMountedRef.js +4 -5
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +6 -9
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
- package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
- package/lib/relay-hooks/useMemoVariables.js +15 -33
- package/lib/relay-hooks/useMutation.js +8 -25
- package/lib/relay-hooks/usePaginationFragment.js +61 -76
- package/lib/relay-hooks/usePreloadedQuery.js +12 -29
- package/lib/relay-hooks/useQueryLoader.js +23 -47
- package/lib/relay-hooks/useRefetchableFragment.js +8 -18
- package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
- package/lib/relay-hooks/useRelayEnvironment.js +4 -7
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
- package/lib/relay-hooks/useSubscription.js +5 -9
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -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/relay-hooks/EntryPointContainer.react.js.flow +1 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
- package/relay-hooks/FragmentResource.js.flow +34 -8
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +35 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
- package/relay-hooks/useClientQuery.js.flow +1 -1
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +5 -4
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +4 -4
- package/relay-hooks/usePaginationFragment.js.flow +53 -46
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +85 -22
- package/relay-hooks/useRefetchableFragment.js.flow +64 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
@@ -6,12 +6,13 @@
|
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
8
|
* @format
|
9
|
-
* @
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
14
|
import type {
|
15
|
+
EnvironmentProviderOptions,
|
15
16
|
LoadQueryOptions,
|
16
17
|
PreloadableConcreteRequest,
|
17
18
|
PreloadedQueryInner,
|
@@ -30,11 +31,11 @@ import type {
|
|
30
31
|
const invariant = require('invariant');
|
31
32
|
const React = require('react');
|
32
33
|
const {
|
34
|
+
__internal: {fetchQueryDeduped},
|
33
35
|
Observable,
|
34
36
|
PreloadableQueryRegistry,
|
35
37
|
RelayFeatureFlags,
|
36
38
|
ReplaySubject,
|
37
|
-
__internal: {fetchQueryDeduped},
|
38
39
|
createOperationDescriptor,
|
39
40
|
getRequest,
|
40
41
|
getRequestIdentifier,
|
@@ -55,7 +56,10 @@ function useTrackLoadQueryInRender() {
|
|
55
56
|
}
|
56
57
|
}
|
57
58
|
|
58
|
-
function loadQuery<
|
59
|
+
function loadQuery<
|
60
|
+
TQuery: OperationType,
|
61
|
+
TEnvironmentProviderOptions = EnvironmentProviderOptions,
|
62
|
+
>(
|
59
63
|
environment: IEnvironment,
|
60
64
|
preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
|
61
65
|
variables: TQuery['variables'],
|
@@ -115,8 +119,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
115
119
|
// allows us to capture the events that occur during the eager execution
|
116
120
|
// of the operation, and then replay them to the Observable we
|
117
121
|
// ultimately return.
|
118
|
-
const executionSubject = new ReplaySubject();
|
119
|
-
const returnedObservable = Observable.create(sink =>
|
122
|
+
const executionSubject = new ReplaySubject<GraphQLResponse>();
|
123
|
+
const returnedObservable = Observable.create<GraphQLResponse>(sink =>
|
120
124
|
executionSubject.subscribe(sink),
|
121
125
|
);
|
122
126
|
|
@@ -139,7 +143,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
139
143
|
didMakeNetworkRequest = true;
|
140
144
|
|
141
145
|
let observable;
|
142
|
-
const subject = new ReplaySubject();
|
146
|
+
const subject = new ReplaySubject<GraphQLResponse>();
|
143
147
|
if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
|
144
148
|
// Here, we are calling fetchQueryDeduped at the network layer level,
|
145
149
|
// which ensures that only a single network request is active for a given
|
@@ -270,7 +274,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
270
274
|
};
|
271
275
|
|
272
276
|
let params;
|
273
|
-
let cancelOnLoadCallback;
|
277
|
+
let cancelOnLoadCallback: () => void;
|
274
278
|
let queryId;
|
275
279
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
276
280
|
const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -31,7 +31,6 @@ import type {
|
|
31
31
|
const {
|
32
32
|
Observable,
|
33
33
|
PreloadableQueryRegistry,
|
34
|
-
RelayFeatureFlags,
|
35
34
|
ReplaySubject,
|
36
35
|
createOperationDescriptor,
|
37
36
|
getRequest,
|
@@ -45,8 +44,8 @@ const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
|
45
44
|
const STORE_OR_NETWORK_DEFAULT: PreloadFetchPolicy = 'store-or-network';
|
46
45
|
|
47
46
|
const pendingQueriesByEnvironment = WEAKMAP_SUPPORTED
|
48
|
-
? new WeakMap()
|
49
|
-
: new Map();
|
47
|
+
? new WeakMap<IEnvironment, Map<string, PendingQueryEntry>>()
|
48
|
+
: new Map<IEnvironment, Map<string, PendingQueryEntry>>();
|
50
49
|
|
51
50
|
type PendingQueryEntry =
|
52
51
|
| $ReadOnly<{
|
@@ -92,7 +91,7 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
92
91
|
);
|
93
92
|
const source =
|
94
93
|
queryEntry.kind === 'network'
|
95
|
-
? Observable.create(sink => {
|
94
|
+
? Observable.create<GraphQLResponse>(sink => {
|
96
95
|
let subscription;
|
97
96
|
if (pendingQueries.get(queryEntry.cacheKey) == null) {
|
98
97
|
const newQueryEntry = preloadQueryDeduped(
|
@@ -205,7 +204,7 @@ function preloadQueryDeduped<TQuery: OperationType>(
|
|
205
204
|
} else if (prevQueryEntry == null || prevQueryEntry.kind !== 'network') {
|
206
205
|
// Should fetch but we're not already fetching: fetch!
|
207
206
|
const source = network.execute(params, variables, networkCacheConfig, null);
|
208
|
-
const subject = new ReplaySubject();
|
207
|
+
const subject = new ReplaySubject<GraphQLResponse>();
|
209
208
|
nextQueryEntry = {
|
210
209
|
cacheKey,
|
211
210
|
fetchKey,
|
@@ -4,13 +4,13 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
13
|
-
|
13
|
+
import type {OperationType} from '../../relay-runtime/util/RelayRuntimeTypes';
|
14
14
|
import type {
|
15
15
|
EntryPoint,
|
16
16
|
EntryPointComponent,
|
@@ -40,6 +40,7 @@ function prepareEntryPoint<
|
|
40
40
|
): void {
|
41
41
|
// Start loading the code for the entrypoint
|
42
42
|
if (entryPoint.root.getModuleIfRequired() == null) {
|
43
|
+
// $FlowFixMe[unused-promise]
|
43
44
|
entryPoint.root.load();
|
44
45
|
}
|
45
46
|
const preloadProps = entryPoint.getPreloadProps(entryPointParams);
|
@@ -56,7 +57,7 @@ function prepareEntryPoint<
|
|
56
57
|
environmentProviderOptions,
|
57
58
|
);
|
58
59
|
|
59
|
-
preloadedQueries[queryPropName] = preloadQuery(
|
60
|
+
preloadedQueries[queryPropName] = preloadQuery<OperationType, mixed>(
|
60
61
|
environment,
|
61
62
|
parameters,
|
62
63
|
variables,
|
@@ -75,11 +76,15 @@ function prepareEntryPoint<
|
|
75
76
|
}
|
76
77
|
const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
|
77
78
|
entryPointDescription;
|
78
|
-
preloadedEntryPoints[entryPointPropName] = prepareEntryPoint
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
preloadedEntryPoints[entryPointPropName] = prepareEntryPoint<
|
80
|
+
TEntryPointParams,
|
81
|
+
TPreloadedQueries,
|
82
|
+
TPreloadedEntryPoints,
|
83
|
+
TRuntimeProps,
|
84
|
+
TExtraProps,
|
85
|
+
TEntryPointComponent,
|
86
|
+
TEntryPoint,
|
87
|
+
>(environmentProvider, nestedEntryPoint, nestedParams);
|
83
88
|
});
|
84
89
|
}
|
85
90
|
}
|
@@ -5,8 +5,8 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
|
-
* @emails oncall+relay
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -25,8 +25,8 @@ const SuspenseResource = require('../SuspenseResource');
|
|
25
25
|
const {getCacheForType, getCacheSignal} = require('./RelayReactCache');
|
26
26
|
const invariant = require('invariant');
|
27
27
|
const {
|
28
|
-
RelayFeatureFlags,
|
29
28
|
__internal: {fetchQuery: fetchQueryInternal},
|
29
|
+
RelayFeatureFlags,
|
30
30
|
} = require('relay-runtime');
|
31
31
|
const warning = require('warning');
|
32
32
|
|
@@ -127,7 +127,7 @@ const noopOnCommit = () => {
|
|
127
127
|
return () => undefined;
|
128
128
|
};
|
129
129
|
|
130
|
-
const noopPromise = new Promise(() => {});
|
130
|
+
const noopPromise = new Promise<void>(() => {});
|
131
131
|
|
132
132
|
function getQueryCacheKey(
|
133
133
|
operation: OperationDescriptor,
|
@@ -375,7 +375,7 @@ function executeOperationAndKeepUpToDate(
|
|
375
375
|
customFetchObservable?: Observable<GraphQLResponse>,
|
376
376
|
) {
|
377
377
|
let resolvePromise;
|
378
|
-
const promise = new Promise(r => {
|
378
|
+
const promise = new Promise<void>(r => {
|
379
379
|
resolvePromise = r;
|
380
380
|
});
|
381
381
|
// $FlowExpectedError[prop-missing] Expando to annotate Promises.
|
@@ -5,8 +5,8 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
|
-
* @emails oncall+relay
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -64,7 +64,7 @@ function getMissingClientEdges(
|
|
64
64
|
} else if (state.kind === 'singular') {
|
65
65
|
return state.snapshot.missingClientEdges ?? null;
|
66
66
|
} else {
|
67
|
-
let edges = null;
|
67
|
+
let edges: null | Array<MissingClientEdgeRequestInfo> = null;
|
68
68
|
for (const snapshot of state.snapshots) {
|
69
69
|
if (snapshot.missingClientEdges) {
|
70
70
|
edges = edges ?? [];
|
@@ -223,7 +223,7 @@ function readFragmentInternal_REACT_CACHE(
|
|
223
223
|
if (fragmentNode.metadata?.hasClientEdges === true) {
|
224
224
|
const missingClientEdges = getMissingClientEdges(state);
|
225
225
|
if (missingClientEdges?.length) {
|
226
|
-
clientEdgeQueries = [];
|
226
|
+
clientEdgeQueries = ([]: Array<QueryResult>);
|
227
227
|
for (const edge of missingClientEdges) {
|
228
228
|
clientEdgeQueries.push(
|
229
229
|
handleMissingClientEdge(
|
@@ -5,8 +5,8 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
|
-
* @emails oncall+relay
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -73,7 +73,7 @@ function getMissingClientEdges(
|
|
73
73
|
} else if (state.kind === 'singular') {
|
74
74
|
return state.snapshot.missingClientEdges ?? null;
|
75
75
|
} else {
|
76
|
-
let edges = null;
|
76
|
+
let edges: null | Array<MissingClientEdgeRequestInfo> = null;
|
77
77
|
for (const snapshot of state.snapshots) {
|
78
78
|
if (snapshot.missingClientEdges) {
|
79
79
|
edges = edges ?? [];
|
@@ -94,7 +94,7 @@ function getSuspendingLiveResolver(
|
|
94
94
|
} else if (state.kind === 'singular') {
|
95
95
|
return state.snapshot.missingLiveResolverFields ?? null;
|
96
96
|
} else {
|
97
|
-
let missingFields = null;
|
97
|
+
let missingFields: null | Array<MissingLiveResolverField> = null;
|
98
98
|
for (const snapshot of state.snapshots) {
|
99
99
|
if (snapshot.missingLiveResolverFields) {
|
100
100
|
missingFields = missingFields ?? [];
|
@@ -438,7 +438,7 @@ function useFragmentInternal_REACT_CACHE(
|
|
438
438
|
// eslint-disable-next-line no-shadow
|
439
439
|
let clientEdgeQueries;
|
440
440
|
if (missingClientEdges?.length) {
|
441
|
-
clientEdgeQueries = [];
|
441
|
+
clientEdgeQueries = ([]: Array<QueryResult>);
|
442
442
|
for (const edge of missingClientEdges) {
|
443
443
|
clientEdgeQueries.push(
|
444
444
|
handleMissingClientEdge(
|
@@ -4,14 +4,15 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
14
|
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from '../useLoadMoreFunction';
|
15
|
+
import type {Options} from './useRefetchableFragmentInternal_REACT_CACHE';
|
15
16
|
import type {RefetchFnDynamic} from './useRefetchableFragmentInternal_REACT_CACHE';
|
16
17
|
import type {
|
17
18
|
FragmentType,
|
@@ -19,9 +20,12 @@ import type {
|
|
19
20
|
GraphQLTaggedNode,
|
20
21
|
Observer,
|
21
22
|
OperationType,
|
23
|
+
Variables,
|
22
24
|
} from 'relay-runtime';
|
25
|
+
import type {VariablesOf} from 'relay-runtime/util/RelayRuntimeTypes';
|
23
26
|
|
24
27
|
const useLoadMoreFunction = require('../useLoadMoreFunction');
|
28
|
+
const useRelayEnvironment = require('../useRelayEnvironment');
|
25
29
|
const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
26
30
|
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
27
31
|
const {useCallback, useDebugValue, useState} = require('react');
|
@@ -33,8 +37,8 @@ const {
|
|
33
37
|
|
34
38
|
export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {
|
35
39
|
data: TFragmentData,
|
36
|
-
loadNext: LoadMoreFn<TQuery>,
|
37
|
-
loadPrevious: LoadMoreFn<TQuery>,
|
40
|
+
loadNext: LoadMoreFn<TQuery['variables']>,
|
41
|
+
loadPrevious: LoadMoreFn<TQuery['variables']>,
|
38
42
|
hasNext: boolean,
|
39
43
|
hasPrevious: boolean,
|
40
44
|
isLoadingNext: boolean,
|
@@ -83,7 +87,7 @@ function usePaginationFragment<
|
|
83
87
|
|
84
88
|
// Backward pagination
|
85
89
|
const [loadPrevious, hasPrevious, isLoadingPrevious, disposeFetchPrevious] =
|
86
|
-
useLoadMore<TQuery>({
|
90
|
+
useLoadMore<TQuery['variables']>({
|
87
91
|
componentDisplayName,
|
88
92
|
connectionPathInFragmentData,
|
89
93
|
direction: 'backward',
|
@@ -97,22 +101,23 @@ function usePaginationFragment<
|
|
97
101
|
});
|
98
102
|
|
99
103
|
// Forward pagination
|
100
|
-
const [loadNext, hasNext, isLoadingNext, disposeFetchNext] =
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
104
|
+
const [loadNext, hasNext, isLoadingNext, disposeFetchNext] = useLoadMore<
|
105
|
+
TQuery['variables'],
|
106
|
+
>({
|
107
|
+
componentDisplayName,
|
108
|
+
connectionPathInFragmentData,
|
109
|
+
direction: 'forward',
|
110
|
+
fragmentData,
|
111
|
+
fragmentIdentifier,
|
112
|
+
fragmentNode,
|
113
|
+
fragmentRef,
|
114
|
+
identifierField,
|
115
|
+
paginationMetadata,
|
116
|
+
paginationRequest,
|
117
|
+
});
|
113
118
|
|
114
119
|
const refetchPagination: RefetchFnDynamic<TQuery, TKey> = useCallback(
|
115
|
-
(variables
|
120
|
+
(variables: VariablesOf<TQuery>, options: void | Options) => {
|
116
121
|
disposeFetchNext();
|
117
122
|
disposeFetchPrevious();
|
118
123
|
return refetch(variables, {...options, __environment: undefined});
|
@@ -143,7 +148,7 @@ function usePaginationFragment<
|
|
143
148
|
};
|
144
149
|
}
|
145
150
|
|
146
|
-
function useLoadMore<
|
151
|
+
function useLoadMore<TVariables: Variables>(
|
147
152
|
args: $Diff<
|
148
153
|
UseLoadMoreFunctionArgs,
|
149
154
|
{
|
@@ -152,15 +157,29 @@ function useLoadMore<TQuery: OperationType>(
|
|
152
157
|
...
|
153
158
|
},
|
154
159
|
>,
|
155
|
-
): [LoadMoreFn<
|
156
|
-
const
|
160
|
+
): [LoadMoreFn<TVariables>, boolean, boolean, () => void] {
|
161
|
+
const environment = useRelayEnvironment();
|
162
|
+
const [isLoadingMore, reallySetIsLoadingMore] = useState(false);
|
163
|
+
// Schedule this update since it must be observed by components at the same
|
164
|
+
// batch as when hasNext changes. hasNext is read from the store and store
|
165
|
+
// updates are scheduled, so this must be scheduled too.
|
166
|
+
const setIsLoadingMore = (value: boolean) => {
|
167
|
+
const schedule = environment.getScheduler()?.schedule;
|
168
|
+
if (schedule) {
|
169
|
+
schedule(() => {
|
170
|
+
reallySetIsLoadingMore(value);
|
171
|
+
});
|
172
|
+
} else {
|
173
|
+
reallySetIsLoadingMore(value);
|
174
|
+
}
|
175
|
+
};
|
157
176
|
const observer = {
|
158
177
|
start: () => setIsLoadingMore(true),
|
159
178
|
complete: () => setIsLoadingMore(false),
|
160
179
|
error: () => setIsLoadingMore(false),
|
161
180
|
};
|
162
181
|
const handleReset = () => setIsLoadingMore(false);
|
163
|
-
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction({
|
182
|
+
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
|
164
183
|
...args,
|
165
184
|
observer,
|
166
185
|
onReset: handleReset,
|
@@ -5,8 +5,8 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
* @flow strict-local
|
8
|
-
* @emails oncall+relay
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -122,7 +122,6 @@ function usePreloadedQuery_REACT_CACHE<TQuery: OperationType>(
|
|
122
122
|
|
123
123
|
// Read the query's root fragment -- this may suspend.
|
124
124
|
const {fragmentNode, fragmentRef} = queryResult;
|
125
|
-
// $FlowExpectedError[incompatible-return] Is this a fixable incompatible-return?
|
126
125
|
const data = useFragmentInternal(
|
127
126
|
fragmentNode,
|
128
127
|
fragmentRef,
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -98,7 +98,7 @@ type RefetchFnExact<TQuery: OperationType, TOptions = Options> = RefetchFnBase<
|
|
98
98
|
type RefetchFnInexact<
|
99
99
|
TQuery: OperationType,
|
100
100
|
TOptions = Options,
|
101
|
-
> = RefetchFnBase
|
101
|
+
> = RefetchFnBase<Partial<VariablesOf<TQuery>>, TOptions>;
|
102
102
|
|
103
103
|
type Action =
|
104
104
|
| {
|
@@ -204,8 +204,11 @@ function useRefetchableFragmentNode<
|
|
204
204
|
const shouldReset =
|
205
205
|
environment !== mirroredEnvironment ||
|
206
206
|
fragmentIdentifier !== mirroredFragmentIdentifier;
|
207
|
-
const [queryRef, loadQuery, disposeQuery] =
|
208
|
-
|
207
|
+
const [queryRef, loadQuery, disposeQuery] = useQueryLoader<
|
208
|
+
TQuery['variables'],
|
209
|
+
TQuery['response'],
|
210
|
+
TQuery['rawResponse'],
|
211
|
+
>((refetchableRequest: $FlowFixMe));
|
209
212
|
|
210
213
|
let fragmentRef = parentFragmentRef;
|
211
214
|
if (shouldReset) {
|
@@ -387,7 +390,10 @@ function useRefetchFunction<TQuery: OperationType>(
|
|
387
390
|
? fragmentData[identifierField]
|
388
391
|
: null;
|
389
392
|
return useCallback(
|
390
|
-
(
|
393
|
+
(
|
394
|
+
providedRefetchVariables: VariablesOf<TQuery>,
|
395
|
+
options: void | InternalOptions,
|
396
|
+
) => {
|
391
397
|
// Bail out and warn if we're trying to refetch after the component
|
392
398
|
// has unmounted
|
393
399
|
if (isMountedRef.current !== true) {
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -18,8 +18,8 @@ import type {
|
|
18
18
|
OperationType,
|
19
19
|
} from 'relay-runtime';
|
20
20
|
|
21
|
-
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
22
21
|
const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
22
|
+
const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
23
23
|
const {useDebugValue} = require('react');
|
24
24
|
const {getFragment} = require('relay-runtime');
|
25
25
|
|