react-relay 11.0.2 → 13.0.0-rc.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +47 -0
- package/ReactRelayContainerUtils.js.flow +1 -1
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +3 -4
- package/ReactRelayFragmentContainer.js.flow +25 -25
- package/ReactRelayFragmentMockRenderer.js.flow +2 -2
- package/ReactRelayLocalQueryRenderer.js.flow +7 -8
- package/ReactRelayPaginationContainer.js.flow +112 -59
- package/ReactRelayQueryFetcher.js.flow +10 -11
- package/ReactRelayQueryRenderer.js.flow +116 -82
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +42 -39
- package/ReactRelayTestMocker.js.flow +17 -15
- package/ReactRelayTypes.js.flow +11 -11
- package/RelayContext.js.flow +4 -4
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +12 -8
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +11 -7
- package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
- package/assertFragmentMap.js.flow +3 -3
- package/buildReactRelayContainer.js.flow +12 -11
- package/getRootVariablesForFragments.js.flow +3 -5
- package/hooks.js +1 -1
- package/hooks.js.flow +6 -7
- package/index.js +1 -1
- package/index.js.flow +7 -8
- package/isRelayEnvironment.js.flow +1 -1
- package/jest-react/enqueueTask.js.flow +56 -0
- package/jest-react/index.js.flow +12 -0
- package/jest-react/internalAct.js.flow +138 -0
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -1
- package/lib/ReactRelayContainerUtils.js +1 -1
- package/lib/ReactRelayContext.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +22 -16
- package/lib/ReactRelayFragmentMockRenderer.js +3 -3
- package/lib/ReactRelayLocalQueryRenderer.js +8 -9
- package/lib/ReactRelayPaginationContainer.js +97 -39
- package/lib/ReactRelayQueryFetcher.js +3 -3
- package/lib/ReactRelayQueryRenderer.js +87 -54
- package/lib/ReactRelayQueryRendererContext.js +1 -1
- package/lib/ReactRelayRefetchContainer.js +39 -26
- package/lib/ReactRelayTestMocker.js +8 -9
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +4 -3
- package/lib/assertFragmentMap.js +3 -2
- package/lib/buildReactRelayContainer.js +8 -8
- package/lib/getRootVariablesForFragments.js +2 -3
- package/lib/hooks.js +6 -6
- package/lib/index.js +8 -8
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/jest-react/enqueueTask.js +53 -0
- package/lib/jest-react/index.js +13 -0
- package/lib/jest-react/internalAct.js +115 -0
- package/lib/legacy.js +1 -1
- package/lib/multi-actor/ActorChange.js +30 -0
- package/lib/multi-actor/index.js +11 -0
- package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
- package/lib/readContext.js +1 -1
- package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
- package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
- package/lib/relay-hooks/FragmentResource.js +342 -89
- package/lib/relay-hooks/InternalLogger.js +1 -1
- package/lib/relay-hooks/LRUCache.js +1 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
- package/lib/relay-hooks/MatchContainer.js +2 -2
- package/lib/relay-hooks/ProfilerContext.js +1 -1
- package/lib/relay-hooks/QueryResource.js +172 -29
- package/lib/relay-hooks/RelayEnvironmentProvider.js +6 -4
- package/lib/relay-hooks/SuspenseResource.js +130 -0
- package/lib/relay-hooks/loadEntryPoint.js +1 -1
- package/lib/relay-hooks/loadQuery.js +42 -20
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -16
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
- package/lib/relay-hooks/useBlockingPaginationFragment.js +5 -6
- package/lib/relay-hooks/useEntryPointLoader.js +3 -3
- package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
- package/lib/relay-hooks/useFragment.js +7 -7
- package/lib/relay-hooks/useFragmentNode.js +5 -5
- package/lib/relay-hooks/useIsMountedRef.js +1 -1
- package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
- package/lib/relay-hooks/useLazyLoadQueryNode.js +11 -5
- package/lib/relay-hooks/useLoadMoreFunction.js +9 -13
- package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
- package/lib/relay-hooks/useMemoVariables.js +3 -3
- package/lib/relay-hooks/useMutation.js +18 -7
- package/lib/relay-hooks/usePaginationFragment.js +3 -4
- package/lib/relay-hooks/usePreloadedQuery.js +6 -6
- package/lib/relay-hooks/useQueryLoader.js +31 -11
- package/lib/relay-hooks/useRefetchableFragment.js +1 -1
- package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -18
- package/lib/relay-hooks/useRelayEnvironment.js +3 -3
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
- package/lib/relay-hooks/useSubscription.js +11 -8
- package/multi-actor/ActorChange.js.flow +58 -0
- package/multi-actor/index.js.flow +14 -0
- package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
- 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 -1
- package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
- package/relay-hooks/EntryPointTypes.flow.js.flow +25 -26
- package/relay-hooks/FragmentResource.js.flow +359 -93
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
- package/relay-hooks/MatchContainer.js.flow +4 -3
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +217 -26
- package/relay-hooks/RelayEnvironmentProvider.js.flow +15 -5
- package/relay-hooks/SuspenseResource.js.flow +115 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
- package/relay-hooks/__flowtests__/utils.js.flow +21 -32
- package/relay-hooks/loadEntryPoint.js.flow +7 -13
- package/relay-hooks/loadQuery.js.flow +50 -32
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +31 -22
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
- package/relay-hooks/useBlockingPaginationFragment.js.flow +14 -12
- package/relay-hooks/useEntryPointLoader.js.flow +8 -11
- package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
- package/relay-hooks/useFragment.js.flow +31 -62
- package/relay-hooks/useFragmentNode.js.flow +6 -8
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
- package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
- package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
- package/relay-hooks/useLazyLoadQueryNode.js.flow +20 -14
- package/relay-hooks/useLoadMoreFunction.js.flow +21 -30
- package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
- package/relay-hooks/useMemoVariables.js.flow +7 -7
- package/relay-hooks/useMutation.js.flow +27 -27
- package/relay-hooks/usePaginationFragment.js.flow +39 -45
- package/relay-hooks/usePreloadedQuery.js.flow +14 -20
- package/relay-hooks/useQueryLoader.js.flow +42 -23
- package/relay-hooks/useRefetchableFragment.js.flow +8 -9
- package/relay-hooks/useRefetchableFragmentNode.js.flow +25 -33
- package/relay-hooks/useRelayEnvironment.js.flow +3 -5
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
- package/relay-hooks/useSubscription.js.flow +21 -11
- package/lib/relay-hooks/getPaginationMetadata.js +0 -41
- package/lib/relay-hooks/getPaginationVariables.js +0 -67
- package/lib/relay-hooks/getRefetchMetadata.js +0 -36
- package/lib/relay-hooks/getValueAtPath.js +0 -51
- package/relay-hooks/getPaginationMetadata.js.flow +0 -74
- package/relay-hooks/getPaginationVariables.js.flow +0 -110
- package/relay-hooks/getRefetchMetadata.js.flow +0 -80
- package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,15 +13,9 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
const useIsMountedRef = require('./useIsMountedRef');
|
17
|
-
const useRelayEnvironment = require('./useRelayEnvironment');
|
18
|
-
|
19
|
-
const {loadQuery, useTrackLoadQueryInRender} = require('./loadQuery');
|
20
|
-
const {useCallback, useEffect, useRef, useState} = require('react');
|
21
|
-
|
22
16
|
import type {
|
23
|
-
PreloadableConcreteRequest,
|
24
17
|
LoadQueryOptions,
|
18
|
+
PreloadableConcreteRequest,
|
25
19
|
PreloadedQuery,
|
26
20
|
} from './EntryPointTypes.flow';
|
27
21
|
import type {
|
@@ -30,8 +24,14 @@ import type {
|
|
30
24
|
OperationType,
|
31
25
|
} from 'relay-runtime';
|
32
26
|
|
27
|
+
const {loadQuery, useTrackLoadQueryInRender} = require('./loadQuery');
|
28
|
+
const useIsMountedRef = require('./useIsMountedRef');
|
29
|
+
const useRelayEnvironment = require('./useRelayEnvironment');
|
30
|
+
const {useCallback, useEffect, useRef, useState} = require('react');
|
31
|
+
const {getRequest} = require('relay-runtime');
|
32
|
+
|
33
33
|
export type LoaderFn<TQuery: OperationType> = (
|
34
|
-
variables:
|
34
|
+
variables: TQuery['variables'],
|
35
35
|
options?: UseQueryLoaderLoadQueryOptions,
|
36
36
|
) => void;
|
37
37
|
|
@@ -54,6 +54,16 @@ type NullQueryReference = {|
|
|
54
54
|
|};
|
55
55
|
const initialNullQueryReferenceState = {kind: 'NullQueryReference'};
|
56
56
|
|
57
|
+
function requestIsLiveQuery<TQuery: OperationType>(
|
58
|
+
preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
|
59
|
+
): boolean {
|
60
|
+
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
61
|
+
return (preloadableRequest: $FlowFixMe).params.metadata.live !== undefined;
|
62
|
+
}
|
63
|
+
const request = getRequest(preloadableRequest);
|
64
|
+
return request.params.metadata.live !== undefined;
|
65
|
+
}
|
66
|
+
|
57
67
|
function useQueryLoader<TQuery: OperationType>(
|
58
68
|
preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
|
59
69
|
initialQueryReference?: ?PreloadedQuery<TQuery>,
|
@@ -93,12 +103,10 @@ function useQueryLoader<TQuery: OperationType>(
|
|
93
103
|
PreloadedQuery<TQuery> | NullQueryReference,
|
94
104
|
>(() => initialQueryReferenceInternal);
|
95
105
|
|
96
|
-
const [
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
() => initialQueryReferenceInternal,
|
101
|
-
);
|
106
|
+
const [previousInitialQueryReference, setPreviousInitialQueryReference] =
|
107
|
+
useState<PreloadedQuery<TQuery> | NullQueryReference>(
|
108
|
+
() => initialQueryReferenceInternal,
|
109
|
+
);
|
102
110
|
|
103
111
|
if (initialQueryReferenceInternal !== previousInitialQueryReference) {
|
104
112
|
// Rendering the query reference makes it "managed" by this hook, so
|
@@ -120,7 +128,7 @@ function useQueryLoader<TQuery: OperationType>(
|
|
120
128
|
|
121
129
|
const queryLoaderCallback = useCallback(
|
122
130
|
(
|
123
|
-
variables:
|
131
|
+
variables: TQuery['variables'],
|
124
132
|
options?: ?UseQueryLoaderLoadQueryOptions,
|
125
133
|
) => {
|
126
134
|
const mergedOptions: ?UseQueryLoaderLoadQueryOptions =
|
@@ -209,24 +217,35 @@ function useQueryLoader<TQuery: OperationType>(
|
|
209
217
|
|
210
218
|
undisposedQueryReferences.delete(undisposedQueryReference);
|
211
219
|
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
212
|
-
|
213
|
-
undisposedQueryReference.dispose
|
220
|
+
if (requestIsLiveQuery(preloadableRequest)) {
|
221
|
+
undisposedQueryReference.dispose &&
|
222
|
+
undisposedQueryReference.dispose();
|
223
|
+
} else {
|
224
|
+
undisposedQueryReference.releaseQuery &&
|
225
|
+
undisposedQueryReference.releaseQuery();
|
226
|
+
}
|
214
227
|
}
|
215
228
|
}
|
216
229
|
}
|
217
|
-
}, [queryReference, isMountedRef, queryLoaderCallback]);
|
230
|
+
}, [queryReference, isMountedRef, queryLoaderCallback, preloadableRequest]);
|
218
231
|
|
219
232
|
useEffect(() => {
|
220
233
|
return function disposeAllRemainingQueryReferences() {
|
221
234
|
// undisposedQueryReferences.current is never reassigned
|
222
235
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
223
|
-
for (const
|
224
|
-
if (
|
225
|
-
|
236
|
+
for (const undisposedQueryReference of undisposedQueryReferencesRef.current) {
|
237
|
+
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
238
|
+
if (requestIsLiveQuery(preloadableRequest)) {
|
239
|
+
undisposedQueryReference.dispose &&
|
240
|
+
undisposedQueryReference.dispose();
|
241
|
+
} else {
|
242
|
+
undisposedQueryReference.releaseQuery &&
|
243
|
+
undisposedQueryReference.releaseQuery();
|
244
|
+
}
|
226
245
|
}
|
227
246
|
}
|
228
247
|
};
|
229
|
-
}, []);
|
248
|
+
}, [preloadableRequest]);
|
230
249
|
|
231
250
|
return [
|
232
251
|
queryReference.kind === 'NullQueryReference' ? null : queryReference,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,19 +13,18 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
17
|
-
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
18
|
-
|
19
|
-
const {useDebugValue} = require('react');
|
20
|
-
const {getFragment} = require('relay-runtime');
|
21
|
-
|
22
16
|
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
|
23
17
|
import type {
|
18
|
+
FragmentType,
|
24
19
|
GraphQLTaggedNode,
|
25
20
|
OperationType,
|
26
|
-
FragmentReference,
|
27
21
|
} from 'relay-runtime';
|
28
22
|
|
23
|
+
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
24
|
+
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
25
|
+
const {useDebugValue} = require('react');
|
26
|
+
const {getFragment} = require('relay-runtime');
|
27
|
+
|
29
28
|
type ReturnType<TQuery: OperationType, TKey: ?{+$data?: mixed, ...}> = [
|
30
29
|
// NOTE: This $Call ensures that the type of the returned data is either:
|
31
30
|
// - nullable if the provided ref type is nullable
|
@@ -41,7 +40,7 @@ type ReturnType<TQuery: OperationType, TKey: ?{+$data?: mixed, ...}> = [
|
|
41
40
|
|
42
41
|
function useRefetchableFragment<
|
43
42
|
TQuery: OperationType,
|
44
|
-
TKey: ?{+$data?: mixed, +$
|
43
|
+
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
45
44
|
>(
|
46
45
|
fragmentInput: GraphQLTaggedNode,
|
47
46
|
fragmentRef: TKey,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,27 +13,6 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
const ProfilerContext = require('./ProfilerContext');
|
17
|
-
|
18
|
-
const getRefetchMetadata = require('./getRefetchMetadata');
|
19
|
-
const getValueAtPath = require('./getValueAtPath');
|
20
|
-
const invariant = require('invariant');
|
21
|
-
const useFragmentNode = require('./useFragmentNode');
|
22
|
-
const useIsMountedRef = require('./useIsMountedRef');
|
23
|
-
const useQueryLoader = require('./useQueryLoader');
|
24
|
-
const useRelayEnvironment = require('./useRelayEnvironment');
|
25
|
-
const warning = require('warning');
|
26
|
-
|
27
|
-
const {getFragmentResourceForEnvironment} = require('./FragmentResource');
|
28
|
-
const {getQueryResourceForEnvironment} = require('./QueryResource');
|
29
|
-
const {useCallback, useContext, useReducer} = require('react');
|
30
|
-
const {
|
31
|
-
__internal: {fetchQuery},
|
32
|
-
createOperationDescriptor,
|
33
|
-
getFragmentIdentifier,
|
34
|
-
getSelector,
|
35
|
-
} = require('relay-runtime');
|
36
|
-
|
37
16
|
import type {LoaderFn} from './useQueryLoader';
|
38
17
|
import type {
|
39
18
|
Disposable,
|
@@ -47,6 +26,25 @@ import type {
|
|
47
26
|
VariablesOf,
|
48
27
|
} from 'relay-runtime';
|
49
28
|
|
29
|
+
const {getFragmentResourceForEnvironment} = require('./FragmentResource');
|
30
|
+
const ProfilerContext = require('./ProfilerContext');
|
31
|
+
const {getQueryResourceForEnvironment} = require('./QueryResource');
|
32
|
+
const useFragmentNode = require('./useFragmentNode');
|
33
|
+
const useIsMountedRef = require('./useIsMountedRef');
|
34
|
+
const useQueryLoader = require('./useQueryLoader');
|
35
|
+
const useRelayEnvironment = require('./useRelayEnvironment');
|
36
|
+
const invariant = require('invariant');
|
37
|
+
const {useCallback, useContext, useReducer} = require('react');
|
38
|
+
const {
|
39
|
+
__internal: {fetchQuery},
|
40
|
+
createOperationDescriptor,
|
41
|
+
getFragmentIdentifier,
|
42
|
+
getRefetchMetadata,
|
43
|
+
getSelector,
|
44
|
+
getValueAtPath,
|
45
|
+
} = require('relay-runtime');
|
46
|
+
const warning = require('warning');
|
47
|
+
|
50
48
|
export type RefetchFn<
|
51
49
|
TQuery: OperationType,
|
52
50
|
TOptions = Options,
|
@@ -176,11 +174,8 @@ function useRefetchableFragmentNode<
|
|
176
174
|
componentDisplayName: string,
|
177
175
|
): ReturnType<TQuery, TKey, InternalOptions> {
|
178
176
|
const parentEnvironment = useRelayEnvironment();
|
179
|
-
const {
|
180
|
-
|
181
|
-
fragmentRefPathInResponse,
|
182
|
-
identifierField,
|
183
|
-
} = getRefetchMetadata(fragmentNode, componentDisplayName);
|
177
|
+
const {refetchableRequest, fragmentRefPathInResponse, identifierField} =
|
178
|
+
getRefetchMetadata(fragmentNode, componentDisplayName);
|
184
179
|
const fragmentIdentifier = getFragmentIdentifier(
|
185
180
|
fragmentNode,
|
186
181
|
parentFragmentRef,
|
@@ -213,9 +208,8 @@ function useRefetchableFragmentNode<
|
|
213
208
|
const shouldReset =
|
214
209
|
environment !== mirroredEnvironment ||
|
215
210
|
fragmentIdentifier !== mirroredFragmentIdentifier;
|
216
|
-
const [queryRef, loadQuery, disposeQuery] =
|
217
|
-
refetchableRequest
|
218
|
-
);
|
211
|
+
const [queryRef, loadQuery, disposeQuery] =
|
212
|
+
useQueryLoader<TQuery>(refetchableRequest);
|
219
213
|
|
220
214
|
let fragmentRef = parentFragmentRef;
|
221
215
|
if (shouldReset) {
|
@@ -436,7 +430,6 @@ function useRefetchFunction<TQuery: OperationType>(
|
|
436
430
|
// all variables required by the fragment when calling `refetch()`.
|
437
431
|
// We fill in any variables not passed by the call to `refetch()` with the
|
438
432
|
// variables from the original parent fragment owner.
|
439
|
-
// $FlowFixMe[cannot-spread-interface]
|
440
433
|
const refetchVariables: VariablesOf<TQuery> = {
|
441
434
|
...(parentVariables: $FlowFixMe),
|
442
435
|
...fragmentVariables,
|
@@ -500,7 +493,7 @@ function useRefetchFunction<TQuery: OperationType>(
|
|
500
493
|
// - fragmentNode and parentFragmentRef are also captured by including
|
501
494
|
// fragmentIdentifier
|
502
495
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
503
|
-
[fragmentIdentifier, dispatch, disposeQuery, identifierValue],
|
496
|
+
[fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery],
|
504
497
|
);
|
505
498
|
}
|
506
499
|
|
@@ -513,7 +506,6 @@ if (__DEV__) {
|
|
513
506
|
environment: IEnvironment,
|
514
507
|
): ?DebugIDandTypename {
|
515
508
|
const {Record} = require('relay-runtime');
|
516
|
-
// $FlowFixMe[prop-missing]
|
517
509
|
const id = memoRefetchVariables?.id;
|
518
510
|
if (
|
519
511
|
fragmentRefPathInResponse.length !== 1 ||
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,13 +13,11 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
|
16
|
+
import type {IEnvironment} from 'relay-runtime';
|
17
17
|
|
18
18
|
const invariant = require('invariant');
|
19
|
-
|
20
19
|
const {useContext} = require('react');
|
21
|
-
|
22
|
-
import type {IEnvironment} from 'relay-runtime';
|
20
|
+
const ReactRelayContext = require('react-relay/ReactRelayContext');
|
23
21
|
|
24
22
|
function useRelayEnvironment(): IEnvironment {
|
25
23
|
const context = useContext(ReactRelayContext);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,11 +13,10 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
|
16
|
+
import type {ReaderFragment} from 'relay-runtime';
|
17
17
|
|
18
18
|
const {useRef} = require('react');
|
19
|
-
|
20
|
-
import type {ReaderFragment} from 'relay-runtime';
|
19
|
+
const warning = require('warning');
|
21
20
|
|
22
21
|
function useStaticFragmentNodeWarning(
|
23
22
|
fragmentNode: ReaderFragment,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -13,12 +13,11 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
|
16
|
+
import type {DataID, Disposable, InvalidationState} from 'relay-runtime';
|
17
17
|
|
18
|
+
const useRelayEnvironment = require('./useRelayEnvironment');
|
18
19
|
const {useEffect, useRef} = require('react');
|
19
20
|
|
20
|
-
import type {DataID, Disposable, InvalidationState} from 'relay-runtime';
|
21
|
-
|
22
21
|
/**
|
23
22
|
* This hook subscribes a callback to the invalidation state of the given data
|
24
23
|
* ids.
|
@@ -35,9 +34,7 @@ function useSubscribeToInvalidationState(
|
|
35
34
|
const environment = useRelayEnvironment();
|
36
35
|
const disposableRef = useRef(null);
|
37
36
|
|
38
|
-
const stableDataIDs = Array.from(dataIDs)
|
39
|
-
.sort()
|
40
|
-
.join('');
|
37
|
+
const stableDataIDs = Array.from(dataIDs).sort().join('');
|
41
38
|
useEffect(() => {
|
42
39
|
const store = environment.getStore();
|
43
40
|
const invalidationState = store.lookupInvalidationState(dataIDs);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
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.
|
@@ -12,26 +12,36 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
-
|
15
|
+
import type {
|
16
|
+
Disposable,
|
17
|
+
GraphQLSubscriptionConfig,
|
18
|
+
IEnvironment,
|
19
|
+
SubscriptionParameters,
|
20
|
+
} from 'relay-runtime';
|
16
21
|
|
17
22
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
18
|
-
|
23
|
+
const {useEffect} = require('react');
|
19
24
|
const {requestSubscription} = require('relay-runtime');
|
20
25
|
|
21
|
-
|
26
|
+
type RequestSubscriptionFn<TSubscriptionParameters: SubscriptionParameters> = (
|
27
|
+
environment: IEnvironment,
|
28
|
+
config: GraphQLSubscriptionConfig<TSubscriptionParameters>,
|
29
|
+
) => Disposable;
|
22
30
|
|
23
|
-
function useSubscription<
|
24
|
-
config: GraphQLSubscriptionConfig<
|
25
|
-
requestSubscriptionFn?:
|
31
|
+
function useSubscription<TSubscriptionParameters: SubscriptionParameters>(
|
32
|
+
config: GraphQLSubscriptionConfig<TSubscriptionParameters>,
|
33
|
+
requestSubscriptionFn?: RequestSubscriptionFn<TSubscriptionParameters>,
|
26
34
|
): void {
|
27
35
|
// N.B. this will re-subscribe every render if config or requestSubscriptionFn
|
28
36
|
// are not memoized.
|
29
37
|
// Please do not pass an object defined in-line.
|
30
|
-
const actualRequestSubscription =
|
31
|
-
requestSubscriptionFn ?? requestSubscription;
|
38
|
+
const actualRequestSubscription: RequestSubscriptionFn<TSubscriptionParameters> =
|
39
|
+
requestSubscriptionFn ?? (requestSubscription: $FlowFixMe);
|
32
40
|
const environment = useRelayEnvironment();
|
33
|
-
|
34
|
-
|
41
|
+
useEffect(() => {
|
42
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
43
|
+
const {dispose} = actualRequestSubscription(environment, config);
|
44
|
+
// $FlowFixMe[incompatible-call]
|
35
45
|
return dispose;
|
36
46
|
}, [environment, config, actualRequestSubscription]);
|
37
47
|
}
|
@@ -1,41 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var getRefetchMetadata = require('./getRefetchMetadata');
|
15
|
-
|
16
|
-
var invariant = require('invariant');
|
17
|
-
|
18
|
-
function getPaginationMetadata(fragmentNode, componentDisplayName) {
|
19
|
-
var _fragmentNode$metadat, _fragmentNode$metadat2;
|
20
|
-
|
21
|
-
var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
|
22
|
-
paginationRequest = _getRefetchMetadata.refetchableRequest,
|
23
|
-
refetchMetadata = _getRefetchMetadata.refetchMetadata;
|
24
|
-
|
25
|
-
var paginationMetadata = refetchMetadata.connection;
|
26
|
-
!(paginationMetadata != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getPaginationMetadata(): Expected fragment `%s` to include a ' + 'connection when using `%s`. Did you forget to add a @connection ' + 'directive to the connection field in the fragment?', componentDisplayName, fragmentNode.name) : invariant(false) : void 0;
|
27
|
-
var connectionPathInFragmentData = paginationMetadata.path;
|
28
|
-
var connectionMetadata = ((_fragmentNode$metadat = (_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.connection) !== null && _fragmentNode$metadat !== void 0 ? _fragmentNode$metadat : [])[0];
|
29
|
-
!(connectionMetadata != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getPaginationMetadata(): Expected fragment `%s` to include a ' + 'connection when using `%s`. Did you forget to add a @connection ' + 'directive to the connection field in the fragment?', componentDisplayName, fragmentNode.name) : invariant(false) : void 0;
|
30
|
-
var identifierField = refetchMetadata.identifierField;
|
31
|
-
!(identifierField == null || typeof identifierField === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected `identifierField` to be a string.') : invariant(false) : void 0;
|
32
|
-
return {
|
33
|
-
connectionPathInFragmentData: connectionPathInFragmentData,
|
34
|
-
identifierField: identifierField,
|
35
|
-
paginationRequest: paginationRequest,
|
36
|
-
paginationMetadata: paginationMetadata,
|
37
|
-
stream: connectionMetadata.stream === true
|
38
|
-
};
|
39
|
-
}
|
40
|
-
|
41
|
-
module.exports = getPaginationMetadata;
|
@@ -1,67 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
15
|
-
|
16
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
17
|
-
|
18
|
-
var _objectSpread4 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
19
|
-
|
20
|
-
var invariant = require('invariant');
|
21
|
-
|
22
|
-
var warning = require("fbjs/lib/warning");
|
23
|
-
|
24
|
-
function getPaginationVariables(direction, count, cursor, baseVariables, extraVariables, paginationMetadata) {
|
25
|
-
var _objectSpread3;
|
26
|
-
|
27
|
-
var backwardMetadata = paginationMetadata.backward,
|
28
|
-
forwardMetadata = paginationMetadata.forward;
|
29
|
-
|
30
|
-
if (direction === 'backward') {
|
31
|
-
var _objectSpread2;
|
32
|
-
|
33
|
-
!(backwardMetadata != null && backwardMetadata.count != null && backwardMetadata.cursor != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected backward pagination metadata to be available. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
34
|
-
process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(backwardMetadata.cursor), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain cursor variable `%s`. This variable is automatically ' + 'determined by Relay.', backwardMetadata.cursor) : void 0;
|
35
|
-
process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(backwardMetadata.count), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain count variable `%s`. This variable is automatically ' + 'determined by Relay.', backwardMetadata.count) : void 0; // $FlowFixMe[cannot-spread-interface]
|
36
|
-
|
37
|
-
var _paginationVariables = (0, _objectSpread4["default"])((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, baseVariables), extraVariables), {}, (_objectSpread2 = {}, (0, _defineProperty2["default"])(_objectSpread2, backwardMetadata.cursor, cursor), (0, _defineProperty2["default"])(_objectSpread2, backwardMetadata.count, count), _objectSpread2));
|
38
|
-
|
39
|
-
if (forwardMetadata && forwardMetadata.cursor) {
|
40
|
-
_paginationVariables[forwardMetadata.cursor] = null;
|
41
|
-
}
|
42
|
-
|
43
|
-
if (forwardMetadata && forwardMetadata.count) {
|
44
|
-
_paginationVariables[forwardMetadata.count] = null;
|
45
|
-
}
|
46
|
-
|
47
|
-
return _paginationVariables;
|
48
|
-
}
|
49
|
-
|
50
|
-
!(forwardMetadata != null && forwardMetadata.count != null && forwardMetadata.cursor != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected forward pagination metadata to be available. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
51
|
-
process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(forwardMetadata.cursor), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain cursor variable `%s`. This variable is automatically ' + 'determined by Relay.', forwardMetadata.cursor) : void 0;
|
52
|
-
process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(forwardMetadata.count), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain count variable `%s`. This variable is automatically ' + 'determined by Relay.', forwardMetadata.count) : void 0; // $FlowFixMe[cannot-spread-interface]
|
53
|
-
|
54
|
-
var paginationVariables = (0, _objectSpread4["default"])((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, baseVariables), extraVariables), {}, (_objectSpread3 = {}, (0, _defineProperty2["default"])(_objectSpread3, forwardMetadata.cursor, cursor), (0, _defineProperty2["default"])(_objectSpread3, forwardMetadata.count, count), _objectSpread3));
|
55
|
-
|
56
|
-
if (backwardMetadata && backwardMetadata.cursor) {
|
57
|
-
paginationVariables[backwardMetadata.cursor] = null;
|
58
|
-
}
|
59
|
-
|
60
|
-
if (backwardMetadata && backwardMetadata.count) {
|
61
|
-
paginationVariables[backwardMetadata.count] = null;
|
62
|
-
}
|
63
|
-
|
64
|
-
return paginationVariables;
|
65
|
-
}
|
66
|
-
|
67
|
-
module.exports = getPaginationVariables;
|
@@ -1,36 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var invariant = require('invariant');
|
15
|
-
|
16
|
-
function getRefetchMetadata(fragmentNode, componentDisplayName) {
|
17
|
-
var _fragmentNode$metadat, _fragmentNode$metadat2;
|
18
|
-
|
19
|
-
!(((_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) !== true) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected fragment `%s` not to be plural when using ' + '`%s`. Remove `@relay(plural: true)` from fragment `%s` ' + 'in order to use it with `%s`.', fragmentNode.name, componentDisplayName, fragmentNode.name, componentDisplayName) : invariant(false) : void 0;
|
20
|
-
var refetchMetadata = (_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.refetch;
|
21
|
-
!(refetchMetadata != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected fragment `%s` to be refetchable when using `%s`. ' + 'Did you forget to add a @refetchable directive to the fragment?', componentDisplayName, fragmentNode.name) : invariant(false) : void 0; // handle both commonjs and es modules
|
22
|
-
|
23
|
-
var refetchableRequest = refetchMetadata.operation["default"] ? refetchMetadata.operation["default"] : refetchMetadata.operation;
|
24
|
-
var fragmentRefPathInResponse = refetchMetadata.fragmentPathInResult;
|
25
|
-
!(typeof refetchableRequest !== 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected refetch query to be an ' + "operation and not a string when using `%s`. If you're seeing this, " + 'this is likely a bug in Relay.', componentDisplayName) : invariant(false) : void 0;
|
26
|
-
var identifierField = refetchMetadata.identifierField;
|
27
|
-
!(identifierField == null || typeof identifierField === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected `identifierField` to be a string.') : invariant(false) : void 0;
|
28
|
-
return {
|
29
|
-
fragmentRefPathInResponse: fragmentRefPathInResponse,
|
30
|
-
identifierField: identifierField,
|
31
|
-
refetchableRequest: refetchableRequest,
|
32
|
-
refetchMetadata: refetchMetadata
|
33
|
-
};
|
34
|
-
}
|
35
|
-
|
36
|
-
module.exports = getRefetchMetadata;
|
@@ -1,51 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
15
|
-
|
16
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
17
|
-
|
18
|
-
var invariant = require('invariant');
|
19
|
-
|
20
|
-
function getValueAtPath(data, path) {
|
21
|
-
var result = data;
|
22
|
-
|
23
|
-
var _iterator = (0, _createForOfIteratorHelper2["default"])(path),
|
24
|
-
_step;
|
25
|
-
|
26
|
-
try {
|
27
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
28
|
-
var key = _step.value;
|
29
|
-
|
30
|
-
if (result == null) {
|
31
|
-
return null;
|
32
|
-
}
|
33
|
-
|
34
|
-
if (typeof key === 'number') {
|
35
|
-
!Array.isArray(result) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected an array when extracting value at path. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
36
|
-
result = result[key];
|
37
|
-
} else {
|
38
|
-
!(typeof result === 'object' && !Array.isArray(result)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected an object when extracting value at path. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
39
|
-
result = result[key];
|
40
|
-
}
|
41
|
-
}
|
42
|
-
} catch (err) {
|
43
|
-
_iterator.e(err);
|
44
|
-
} finally {
|
45
|
-
_iterator.f();
|
46
|
-
}
|
47
|
-
|
48
|
-
return result;
|
49
|
-
}
|
50
|
-
|
51
|
-
module.exports = getValueAtPath;
|