react-relay 11.0.1 → 13.0.0-rc.1
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +2 -3
- package/ReactRelayFragmentContainer.js.flow +24 -24
- package/ReactRelayFragmentMockRenderer.js.flow +1 -1
- package/ReactRelayLocalQueryRenderer.js.flow +6 -7
- package/ReactRelayPaginationContainer.js.flow +111 -58
- package/ReactRelayQueryFetcher.js.flow +9 -10
- package/ReactRelayQueryRenderer.js.flow +115 -81
- package/ReactRelayRefetchContainer.js.flow +41 -38
- package/ReactRelayTestMocker.js.flow +16 -14
- package/ReactRelayTypes.js.flow +10 -10
- package/RelayContext.js.flow +3 -3
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +1 -2
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +11 -7
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +10 -6
- package/__flowtests__/RelayModern-flowtest.js.flow +78 -46
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +4 -3
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +4 -3
- 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 +2 -2
- package/buildReactRelayContainer.js.flow +15 -12
- package/getRootVariablesForFragments.js.flow +2 -4
- package/hooks.js +1 -1
- package/hooks.js.flow +5 -6
- package/index.js +1 -1
- package/index.js.flow +6 -7
- package/jest-react/enqueueTask.js.flow +56 -0
- package/jest-react/index.js.flow +12 -0
- package/jest-react/internalAct.js.flow +139 -0
- package/legacy.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +21 -15
- package/lib/ReactRelayFragmentMockRenderer.js +2 -2
- package/lib/ReactRelayLocalQueryRenderer.js +7 -8
- package/lib/ReactRelayPaginationContainer.js +96 -38
- package/lib/ReactRelayQueryFetcher.js +3 -3
- package/lib/ReactRelayQueryRenderer.js +86 -53
- package/lib/ReactRelayRefetchContainer.js +38 -25
- package/lib/ReactRelayTestMocker.js +8 -9
- package/lib/RelayContext.js +3 -2
- package/lib/assertFragmentMap.js +3 -2
- package/lib/buildReactRelayContainer.js +14 -11
- package/lib/getRootVariablesForFragments.js +1 -2
- package/lib/hooks.js +5 -5
- package/lib/index.js +7 -7
- package/lib/jest-react/enqueueTask.js +53 -0
- package/lib/jest-react/index.js +13 -0
- package/lib/jest-react/internalAct.js +116 -0
- 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/relay-hooks/EntryPointContainer.react.js +3 -3
- package/lib/relay-hooks/FragmentResource.js +347 -92
- package/lib/relay-hooks/LRUCache.js +1 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +4 -4
- package/lib/relay-hooks/MatchContainer.js +1 -1
- package/lib/relay-hooks/QueryResource.js +172 -29
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -3
- package/lib/relay-hooks/SuspenseResource.js +130 -0
- package/lib/relay-hooks/loadQuery.js +42 -20
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +24 -15
- package/lib/relay-hooks/useBlockingPaginationFragment.js +4 -5
- package/lib/relay-hooks/useEntryPointLoader.js +2 -2
- package/lib/relay-hooks/useFetchTrackingRef.js +2 -1
- package/lib/relay-hooks/useFragment.js +8 -7
- package/lib/relay-hooks/useFragmentNode.js +4 -4
- package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
- package/lib/relay-hooks/useLazyLoadQuery.js +3 -3
- package/lib/relay-hooks/useLazyLoadQueryNode.js +10 -4
- package/lib/relay-hooks/useLoadMoreFunction.js +8 -12
- package/lib/relay-hooks/useMemoOperationDescriptor.js +2 -2
- package/lib/relay-hooks/useMemoVariables.js +2 -2
- package/lib/relay-hooks/useMutation.js +17 -6
- package/lib/relay-hooks/usePaginationFragment.js +2 -3
- package/lib/relay-hooks/usePreloadedQuery.js +8 -7
- package/lib/relay-hooks/useQueryLoader.js +30 -10
- package/lib/relay-hooks/useRefetchableFragmentNode.js +13 -17
- package/lib/relay-hooks/useRelayEnvironment.js +3 -3
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -2
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +2 -1
- package/lib/relay-hooks/useSubscription.js +10 -7
- 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 -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 +8 -15
- package/relay-hooks/EntryPointTypes.flow.js.flow +24 -25
- package/relay-hooks/FragmentResource.js.flow +368 -94
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +32 -46
- package/relay-hooks/MatchContainer.js.flow +3 -2
- package/relay-hooks/QueryResource.js.flow +216 -25
- package/relay-hooks/RelayEnvironmentProvider.js.flow +14 -4
- package/relay-hooks/SuspenseResource.js.flow +115 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +4 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +8 -7
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/utils.js.flow +8 -12
- package/relay-hooks/loadEntryPoint.js.flow +6 -12
- package/relay-hooks/loadQuery.js.flow +49 -31
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +30 -21
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +6 -12
- package/relay-hooks/useBlockingPaginationFragment.js.flow +13 -11
- package/relay-hooks/useEntryPointLoader.js.flow +7 -10
- package/relay-hooks/useFetchTrackingRef.js.flow +2 -2
- package/relay-hooks/useFragment.js.flow +26 -46
- package/relay-hooks/useFragmentNode.js.flow +5 -7
- package/relay-hooks/useIsOperationNodeActive.js.flow +3 -5
- package/relay-hooks/useIsParentQueryActive.js.flow +3 -4
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -10
- package/relay-hooks/useLazyLoadQueryNode.js.flow +19 -13
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -29
- package/relay-hooks/useMemoOperationDescriptor.js.flow +5 -7
- package/relay-hooks/useMemoVariables.js.flow +6 -6
- package/relay-hooks/useMutation.js.flow +26 -26
- package/relay-hooks/usePaginationFragment.js.flow +38 -44
- package/relay-hooks/usePreloadedQuery.js.flow +18 -14
- package/relay-hooks/useQueryLoader.js.flow +41 -22
- package/relay-hooks/useRefetchableFragment.js.flow +7 -8
- package/relay-hooks/useRefetchableFragmentNode.js.flow +24 -32
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +2 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +3 -6
- package/relay-hooks/useSubscription.js.flow +20 -10
- 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
@@ -13,24 +13,26 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
const getPaginationMetadata = require('./getPaginationMetadata');
|
17
|
-
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
18
|
-
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
19
|
-
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
20
|
-
|
21
|
-
const {useCallback, useDebugValue, useState} = require('react');
|
22
|
-
const {getFragment, getFragmentIdentifier} = require('relay-runtime');
|
23
|
-
|
24
16
|
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
25
17
|
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
|
26
18
|
import type {
|
19
|
+
FragmentType,
|
27
20
|
GraphQLResponse,
|
28
21
|
GraphQLTaggedNode,
|
29
22
|
Observer,
|
30
23
|
OperationType,
|
31
|
-
FragmentReference,
|
32
24
|
} from 'relay-runtime';
|
33
25
|
|
26
|
+
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
27
|
+
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
28
|
+
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
29
|
+
const {useCallback, useDebugValue, useState} = require('react');
|
30
|
+
const {
|
31
|
+
getFragment,
|
32
|
+
getFragmentIdentifier,
|
33
|
+
getPaginationMetadata,
|
34
|
+
} = require('relay-runtime');
|
35
|
+
|
34
36
|
export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
|
35
37
|
data: TFragmentData,
|
36
38
|
loadNext: LoadMoreFn<TQuery>,
|
@@ -44,7 +46,7 @@ export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
|
|
44
46
|
|
45
47
|
function usePaginationFragment<
|
46
48
|
TQuery: OperationType,
|
47
|
-
TKey: ?{+$data?: mixed, +$
|
49
|
+
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
48
50
|
>(
|
49
51
|
fragmentInput: GraphQLTaggedNode,
|
50
52
|
parentFragmentRef: TKey,
|
@@ -82,42 +84,34 @@ function usePaginationFragment<
|
|
82
84
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
83
85
|
|
84
86
|
// Backward pagination
|
85
|
-
const [
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
identifierField,
|
99
|
-
paginationMetadata,
|
100
|
-
paginationRequest,
|
101
|
-
});
|
87
|
+
const [loadPrevious, hasPrevious, isLoadingPrevious, disposeFetchPrevious] =
|
88
|
+
useLoadMore<TQuery>({
|
89
|
+
componentDisplayName,
|
90
|
+
connectionPathInFragmentData,
|
91
|
+
direction: 'backward',
|
92
|
+
fragmentData,
|
93
|
+
fragmentIdentifier,
|
94
|
+
fragmentNode,
|
95
|
+
fragmentRef,
|
96
|
+
identifierField,
|
97
|
+
paginationMetadata,
|
98
|
+
paginationRequest,
|
99
|
+
});
|
102
100
|
|
103
101
|
// Forward pagination
|
104
|
-
const [
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
identifierField,
|
118
|
-
paginationMetadata,
|
119
|
-
paginationRequest,
|
120
|
-
});
|
102
|
+
const [loadNext, hasNext, isLoadingNext, disposeFetchNext] =
|
103
|
+
useLoadMore<TQuery>({
|
104
|
+
componentDisplayName,
|
105
|
+
connectionPathInFragmentData,
|
106
|
+
direction: 'forward',
|
107
|
+
fragmentData,
|
108
|
+
fragmentIdentifier,
|
109
|
+
fragmentNode,
|
110
|
+
fragmentRef,
|
111
|
+
identifierField,
|
112
|
+
paginationMetadata,
|
113
|
+
paginationRequest,
|
114
|
+
});
|
121
115
|
|
122
116
|
const refetchPagination: RefetchFnDynamic<TQuery, TKey> = useCallback(
|
123
117
|
(variables, options) => {
|
@@ -13,24 +13,23 @@
|
|
13
13
|
|
14
14
|
'use strict';
|
15
15
|
|
16
|
-
|
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');
|
17
24
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
18
25
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
19
26
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
20
|
-
const
|
21
|
-
|
22
|
-
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
27
|
+
const invariant = require('invariant');
|
23
28
|
const {useDebugValue} = require('react');
|
24
29
|
const {
|
25
30
|
__internal: {fetchQueryDeduped, fetchQuery},
|
26
31
|
} = require('relay-runtime');
|
27
|
-
|
28
|
-
import type {PreloadedQuery} from './EntryPointTypes.flow';
|
29
|
-
import type {
|
30
|
-
GraphQLTaggedNode,
|
31
|
-
OperationType,
|
32
|
-
RenderPolicy,
|
33
|
-
} from 'relay-runtime';
|
32
|
+
const warning = require('warning');
|
34
33
|
|
35
34
|
function usePreloadedQuery<TQuery: OperationType>(
|
36
35
|
gqlQuery: GraphQLTaggedNode,
|
@@ -38,14 +37,19 @@ function usePreloadedQuery<TQuery: OperationType>(
|
|
38
37
|
options?: {|
|
39
38
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
40
39
|
|},
|
41
|
-
):
|
40
|
+
): TQuery['response'] {
|
42
41
|
// We need to use this hook in order to be able to track if
|
43
42
|
// loadQuery was called during render
|
44
43
|
useTrackLoadQueryInRender();
|
45
44
|
|
46
45
|
const environment = useRelayEnvironment();
|
47
|
-
const {fetchKey, fetchPolicy, source, variables} =
|
48
|
-
|
46
|
+
const {fetchKey, fetchPolicy, source, variables, networkCacheConfig} =
|
47
|
+
preloadedQuery;
|
48
|
+
const operation = useMemoOperationDescriptor(
|
49
|
+
gqlQuery,
|
50
|
+
variables,
|
51
|
+
networkCacheConfig,
|
52
|
+
);
|
49
53
|
|
50
54
|
let useLazyLoadQueryNodeParams;
|
51
55
|
if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
|
@@ -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,
|
@@ -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,
|
@@ -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 ||
|
@@ -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);
|
@@ -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,
|
@@ -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);
|
@@ -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("fbjs/lib/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("fbjs/lib/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;
|