react-relay 14.0.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 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- 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 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- 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 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- 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 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- 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 -4
- 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 +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- 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 +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
@@ -4,52 +4,38 @@
|
|
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
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
11
|
|
14
|
-
|
12
|
+
'use strict';
|
15
13
|
|
16
14
|
var _require = require('./loadQuery'),
|
17
|
-
|
18
|
-
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
19
16
|
var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
20
|
-
|
21
17
|
var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
22
|
-
|
23
18
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
24
|
-
|
25
19
|
var invariant = require('invariant');
|
26
|
-
|
27
20
|
var _require2 = require('react'),
|
28
|
-
|
29
|
-
|
21
|
+
useDebugValue = _require2.useDebugValue;
|
30
22
|
var _require3 = require('relay-runtime'),
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
// a separate hooks implementation in ./HooksImplementation -- it can
|
37
|
-
// be removed after we stop doing that.
|
38
|
-
|
39
|
-
|
40
|
-
function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
|
23
|
+
_require3$__internal = _require3.__internal,
|
24
|
+
fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
|
25
|
+
fetchQuery = _require3$__internal.fetchQuery;
|
26
|
+
var warning = require("fbjs/lib/warning");
|
27
|
+
function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
41
28
|
// We need to use this hook in order to be able to track if
|
42
29
|
// loadQuery was called during render
|
43
30
|
useTrackLoadQueryInRender();
|
44
31
|
var environment = useRelayEnvironment();
|
45
32
|
var fetchKey = preloadedQuery.fetchKey,
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
33
|
+
fetchPolicy = preloadedQuery.fetchPolicy,
|
34
|
+
source = preloadedQuery.source,
|
35
|
+
variables = preloadedQuery.variables,
|
36
|
+
networkCacheConfig = preloadedQuery.networkCacheConfig;
|
50
37
|
var operation = useMemoOperationDescriptor(gqlQuery, variables, networkCacheConfig);
|
51
38
|
var useLazyLoadQueryNodeParams;
|
52
|
-
|
53
39
|
if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
|
54
40
|
!(operation.request.node.params.name === preloadedQuery.name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'usePreloadedQuery(): Expected data to be prefetched for query `%s`, ' + 'got prefetch results for query `%s`.', operation.request.node.params.name, preloadedQuery.name) : invariant(false) : void 0;
|
55
41
|
useLazyLoadQueryNodeParams = {
|
@@ -75,7 +61,6 @@ function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
|
|
75
61
|
process.env.NODE_ENV !== "production" ? warning(preloadedQuery.isDisposed === false, 'usePreloadedQuery(): Expected preloadedQuery to not be disposed yet. ' + 'This is because disposing the query marks it for future garbage ' + 'collection, and as such query results may no longer be present in the Relay ' + 'store. In the future, this will become a hard error.') : void 0;
|
76
62
|
var fallbackFetchObservable = fetchQuery(environment, operation);
|
77
63
|
var fetchObservable;
|
78
|
-
|
79
64
|
if (source != null && environment === preloadedQuery.environment) {
|
80
65
|
// If the source observable exists and the environments match, reuse
|
81
66
|
// the source observable.
|
@@ -97,7 +82,6 @@ function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
|
|
97
82
|
// fall back and re-execute and de-dupe the query (at render time).
|
98
83
|
fetchObservable = fallbackFetchObservable;
|
99
84
|
}
|
100
|
-
|
101
85
|
useLazyLoadQueryNodeParams = {
|
102
86
|
componentDisplayName: 'usePreloadedQuery()',
|
103
87
|
fetchObservable: fetchObservable,
|
@@ -107,9 +91,7 @@ function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
|
|
107
91
|
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
|
108
92
|
};
|
109
93
|
}
|
110
|
-
|
111
94
|
var data = useLazyLoadQueryNode(useLazyLoadQueryNodeParams);
|
112
|
-
|
113
95
|
if (process.env.NODE_ENV !== "production") {
|
114
96
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
115
97
|
useDebugValue({
|
@@ -121,19 +103,6 @@ function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
|
|
121
103
|
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
|
122
104
|
});
|
123
105
|
}
|
124
|
-
|
125
106
|
return data;
|
126
107
|
}
|
127
|
-
|
128
|
-
function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
129
|
-
var impl = HooksImplementation.get();
|
130
|
-
|
131
|
-
if (impl) {
|
132
|
-
return impl.usePreloadedQuery(gqlQuery, preloadedQuery, options);
|
133
|
-
} else {
|
134
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
135
|
-
return usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options);
|
136
|
-
}
|
137
|
-
}
|
138
|
-
|
139
108
|
module.exports = usePreloadedQuery;
|
@@ -4,47 +4,37 @@
|
|
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
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
11
|
|
14
|
-
|
12
|
+
'use strict';
|
15
13
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
16
15
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
17
|
-
|
18
16
|
var _require = require('./loadQuery'),
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
loadQuery = _require.loadQuery,
|
18
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
22
19
|
var useIsMountedRef = require('./useIsMountedRef');
|
23
|
-
|
24
20
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
25
|
-
|
26
21
|
var _require2 = require('react'),
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
useCallback = _require2.useCallback,
|
23
|
+
useEffect = _require2.useEffect,
|
24
|
+
useRef = _require2.useRef,
|
25
|
+
useState = _require2.useState;
|
32
26
|
var _require3 = require('relay-runtime'),
|
33
|
-
|
34
|
-
|
27
|
+
getRequest = _require3.getRequest;
|
35
28
|
var initialNullQueryReferenceState = {
|
36
29
|
kind: 'NullQueryReference'
|
37
30
|
};
|
38
|
-
|
39
31
|
function requestIsLiveQuery(preloadableRequest) {
|
40
32
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
41
33
|
return preloadableRequest.params.metadata.live !== undefined;
|
42
34
|
}
|
43
|
-
|
44
35
|
var request = getRequest(preloadableRequest);
|
45
36
|
return request.params.metadata.live !== undefined;
|
46
37
|
}
|
47
|
-
|
48
38
|
function useQueryLoader(preloadableRequest, initialQueryReference) {
|
49
39
|
/**
|
50
40
|
* We want to always call `queryReference.dispose()` for every call to
|
@@ -65,24 +55,22 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
65
55
|
* Finally, when the hook unmounts, we also dispose of all remaining uncommitted
|
66
56
|
* query references.
|
67
57
|
*/
|
58
|
+
|
68
59
|
var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
|
69
60
|
var environment = useRelayEnvironment();
|
70
61
|
useTrackLoadQueryInRender();
|
71
62
|
var isMountedRef = useIsMountedRef();
|
72
63
|
var undisposedQueryReferencesRef = useRef(new Set([initialQueryReferenceInternal]));
|
73
|
-
|
74
64
|
var _useState = useState(function () {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
65
|
+
return initialQueryReferenceInternal;
|
66
|
+
}),
|
67
|
+
queryReference = _useState[0],
|
68
|
+
setQueryReference = _useState[1];
|
80
69
|
var _useState2 = useState(function () {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
70
|
+
return initialQueryReferenceInternal;
|
71
|
+
}),
|
72
|
+
previousInitialQueryReference = _useState2[0],
|
73
|
+
setPreviousInitialQueryReference = _useState2[1];
|
86
74
|
if (initialQueryReferenceInternal !== previousInitialQueryReference) {
|
87
75
|
// Rendering the query reference makes it "managed" by this hook, so
|
88
76
|
// we start keeping track of it so we can dispose it when it is no longer
|
@@ -93,7 +81,6 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
93
81
|
setPreviousInitialQueryReference(initialQueryReferenceInternal);
|
94
82
|
setQueryReference(initialQueryReferenceInternal);
|
95
83
|
}
|
96
|
-
|
97
84
|
var disposeQuery = useCallback(function () {
|
98
85
|
if (isMountedRef.current) {
|
99
86
|
undisposedQueryReferencesRef.current.add(initialNullQueryReferenceState);
|
@@ -106,10 +93,8 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
106
93
|
networkCacheConfig: options.networkCacheConfig,
|
107
94
|
__nameForWarning: options.__nameForWarning
|
108
95
|
} : options;
|
109
|
-
|
110
96
|
if (isMountedRef.current) {
|
111
97
|
var _options$__environmen;
|
112
|
-
|
113
98
|
var updatedQueryReference = loadQuery((_options$__environmen = options === null || options === void 0 ? void 0 : options.__environment) !== null && _options$__environmen !== void 0 ? _options$__environmen : environment, preloadableRequest, variables, mergedOptions);
|
114
99
|
undisposedQueryReferencesRef.current.add(updatedQueryReference);
|
115
100
|
setQueryReference(updatedQueryReference);
|
@@ -140,16 +125,16 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
140
125
|
// so that the queryReference is correctly re-retained, and
|
141
126
|
// potentially refetched if necessary.
|
142
127
|
maybeHiddenOrFastRefresh.current = false;
|
143
|
-
|
144
128
|
if (queryReference.kind !== 'NullQueryReference') {
|
145
129
|
queryLoaderCallback(queryReference.variables, {
|
146
130
|
fetchPolicy: queryReference.fetchPolicy,
|
147
131
|
networkCacheConfig: queryReference.networkCacheConfig
|
148
132
|
});
|
149
133
|
}
|
150
|
-
|
151
134
|
return;
|
152
|
-
}
|
135
|
+
}
|
136
|
+
|
137
|
+
// When a new queryReference is committed, we iterate over all
|
153
138
|
// query references in undisposedQueryReferences and dispose all of
|
154
139
|
// the refs that aren't the currently committed one. This ensures
|
155
140
|
// that we don't leave any dangling query references for the
|
@@ -168,24 +153,17 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
168
153
|
// associated with updates that were scheduled prior to the currently
|
169
154
|
// committing state change. (A useEffect callback is called during the commit
|
170
155
|
// phase.)
|
171
|
-
|
172
|
-
|
173
156
|
var undisposedQueryReferences = undisposedQueryReferencesRef.current;
|
174
|
-
|
175
157
|
if (isMountedRef.current) {
|
176
158
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferences),
|
177
|
-
|
178
|
-
|
159
|
+
_step;
|
179
160
|
try {
|
180
161
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
181
162
|
var undisposedQueryReference = _step.value;
|
182
|
-
|
183
163
|
if (undisposedQueryReference === queryReference) {
|
184
164
|
break;
|
185
165
|
}
|
186
|
-
|
187
166
|
undisposedQueryReferences["delete"](undisposedQueryReference);
|
188
|
-
|
189
167
|
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
190
168
|
if (requestIsLiveQuery(preloadableRequest)) {
|
191
169
|
undisposedQueryReference.dispose && undisposedQueryReference.dispose();
|
@@ -206,12 +184,10 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
206
184
|
// undisposedQueryReferences.current is never reassigned
|
207
185
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
208
186
|
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferencesRef.current),
|
209
|
-
|
210
|
-
|
187
|
+
_step2;
|
211
188
|
try {
|
212
189
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
213
190
|
var undisposedQueryReference = _step2.value;
|
214
|
-
|
215
191
|
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
216
192
|
if (requestIsLiveQuery(preloadableRequest)) {
|
217
193
|
undisposedQueryReference.dispose && undisposedQueryReference.dispose();
|
@@ -229,5 +205,4 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
229
205
|
}, [preloadableRequest]);
|
230
206
|
return [queryReference.kind === 'NullQueryReference' ? null : queryReference, queryLoaderCallback, disposeQuery];
|
231
207
|
}
|
232
|
-
|
233
208
|
module.exports = useQueryLoader;
|
@@ -4,31 +4,26 @@
|
|
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
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
|
11
|
+
|
12
12
|
'use strict';
|
13
13
|
|
14
|
+
var HooksImplementation = require('./HooksImplementation');
|
14
15
|
var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
15
|
-
|
16
16
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
17
|
-
|
18
17
|
var _require = require('react'),
|
19
|
-
|
20
|
-
|
18
|
+
useDebugValue = _require.useDebugValue;
|
21
19
|
var _require2 = require('relay-runtime'),
|
22
|
-
|
23
|
-
|
24
|
-
function useRefetchableFragment(fragmentInput, fragmentRef) {
|
20
|
+
getFragment = _require2.getFragment;
|
21
|
+
function useRefetchableFragment_LEGACY(fragmentInput, fragmentRef) {
|
25
22
|
var fragmentNode = getFragment(fragmentInput);
|
26
23
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
|
27
|
-
|
28
24
|
var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
26
|
+
refetch = _useRefetchableFragme.refetch;
|
32
27
|
if (process.env.NODE_ENV !== "production") {
|
33
28
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
34
29
|
useDebugValue({
|
@@ -36,11 +31,18 @@ function useRefetchableFragment(fragmentInput, fragmentRef) {
|
|
36
31
|
data: fragmentData
|
37
32
|
});
|
38
33
|
}
|
39
|
-
/* $FlowExpectedError[prop-missing] : Exposed options is a subset of internal
|
40
|
-
* options */
|
41
|
-
|
42
34
|
|
35
|
+
// $FlowFixMe[incompatible-return]
|
36
|
+
// $FlowFixMe[prop-missing]
|
43
37
|
return [fragmentData, refetch];
|
44
38
|
}
|
45
|
-
|
39
|
+
function useRefetchableFragment(fragmentInput, parentFragmentRef) {
|
40
|
+
var impl = HooksImplementation.get();
|
41
|
+
if (impl) {
|
42
|
+
return impl.useRefetchableFragment(fragmentInput, parentFragmentRef);
|
43
|
+
} else {
|
44
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
45
|
+
return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
|
46
|
+
}
|
47
|
+
}
|
46
48
|
module.exports = useRefetchableFragment;
|