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
@@ -0,0 +1,325 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
* @format
|
9
|
+
* @oncall relay
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
+
var ProfilerContext = require('../ProfilerContext');
|
17
|
+
var _require = require('../QueryResource'),
|
18
|
+
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
19
|
+
var useIsMountedRef = require('../useIsMountedRef');
|
20
|
+
var useQueryLoader = require('../useQueryLoader');
|
21
|
+
var useRelayEnvironment = require('../useRelayEnvironment');
|
22
|
+
var readFragmentInternal = require('./readFragmentInternal_REACT_CACHE');
|
23
|
+
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
24
|
+
var invariant = require('invariant');
|
25
|
+
var _require2 = require('react'),
|
26
|
+
useCallback = _require2.useCallback,
|
27
|
+
useContext = _require2.useContext,
|
28
|
+
useReducer = _require2.useReducer;
|
29
|
+
var _require3 = require('relay-runtime'),
|
30
|
+
fetchQuery = _require3.__internal.fetchQuery,
|
31
|
+
createOperationDescriptor = _require3.createOperationDescriptor,
|
32
|
+
getFragmentIdentifier = _require3.getFragmentIdentifier,
|
33
|
+
getRefetchMetadata = _require3.getRefetchMetadata,
|
34
|
+
getSelector = _require3.getSelector,
|
35
|
+
getValueAtPath = _require3.getValueAtPath;
|
36
|
+
var warning = require("fbjs/lib/warning");
|
37
|
+
function reducer(state, action) {
|
38
|
+
switch (action.type) {
|
39
|
+
case 'refetch':
|
40
|
+
{
|
41
|
+
var _action$refetchEnviro;
|
42
|
+
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
43
|
+
fetchPolicy: action.fetchPolicy,
|
44
|
+
mirroredEnvironment: (_action$refetchEnviro = action.refetchEnvironment) !== null && _action$refetchEnviro !== void 0 ? _action$refetchEnviro : state.mirroredEnvironment,
|
45
|
+
onComplete: action.onComplete,
|
46
|
+
refetchEnvironment: action.refetchEnvironment,
|
47
|
+
refetchQuery: action.refetchQuery,
|
48
|
+
renderPolicy: action.renderPolicy
|
49
|
+
});
|
50
|
+
}
|
51
|
+
case 'reset':
|
52
|
+
{
|
53
|
+
return {
|
54
|
+
fetchPolicy: undefined,
|
55
|
+
mirroredEnvironment: action.environment,
|
56
|
+
mirroredFragmentIdentifier: action.fragmentIdentifier,
|
57
|
+
onComplete: undefined,
|
58
|
+
refetchQuery: null,
|
59
|
+
renderPolicy: undefined
|
60
|
+
};
|
61
|
+
}
|
62
|
+
default:
|
63
|
+
{
|
64
|
+
action.type;
|
65
|
+
throw new Error('useRefetchableFragmentNode: Unexpected action type');
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName) {
|
70
|
+
var parentEnvironment = useRelayEnvironment();
|
71
|
+
var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
|
72
|
+
refetchableRequest = _getRefetchMetadata.refetchableRequest,
|
73
|
+
fragmentRefPathInResponse = _getRefetchMetadata.fragmentRefPathInResponse,
|
74
|
+
identifierField = _getRefetchMetadata.identifierField;
|
75
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, parentFragmentRef);
|
76
|
+
var _useReducer = useReducer(reducer, {
|
77
|
+
fetchPolicy: undefined,
|
78
|
+
mirroredEnvironment: parentEnvironment,
|
79
|
+
mirroredFragmentIdentifier: fragmentIdentifier,
|
80
|
+
onComplete: undefined,
|
81
|
+
refetchEnvironment: null,
|
82
|
+
refetchQuery: null,
|
83
|
+
renderPolicy: undefined
|
84
|
+
}),
|
85
|
+
refetchState = _useReducer[0],
|
86
|
+
dispatch = _useReducer[1];
|
87
|
+
var fetchPolicy = refetchState.fetchPolicy,
|
88
|
+
mirroredEnvironment = refetchState.mirroredEnvironment,
|
89
|
+
mirroredFragmentIdentifier = refetchState.mirroredFragmentIdentifier,
|
90
|
+
onComplete = refetchState.onComplete,
|
91
|
+
refetchEnvironment = refetchState.refetchEnvironment,
|
92
|
+
refetchQuery = refetchState.refetchQuery,
|
93
|
+
renderPolicy = refetchState.renderPolicy;
|
94
|
+
var environment = refetchEnvironment !== null && refetchEnvironment !== void 0 ? refetchEnvironment : parentEnvironment;
|
95
|
+
var QueryResource = getQueryResourceForEnvironment(environment);
|
96
|
+
var profilerContext = useContext(ProfilerContext);
|
97
|
+
var shouldReset = environment !== mirroredEnvironment || fragmentIdentifier !== mirroredFragmentIdentifier;
|
98
|
+
var _useQueryLoader = useQueryLoader(refetchableRequest),
|
99
|
+
queryRef = _useQueryLoader[0],
|
100
|
+
loadQuery = _useQueryLoader[1],
|
101
|
+
disposeQuery = _useQueryLoader[2];
|
102
|
+
var fragmentRef = parentFragmentRef;
|
103
|
+
if (shouldReset) {
|
104
|
+
dispatch({
|
105
|
+
type: 'reset',
|
106
|
+
environment: environment,
|
107
|
+
fragmentIdentifier: fragmentIdentifier
|
108
|
+
});
|
109
|
+
disposeQuery();
|
110
|
+
} else if (refetchQuery != null && queryRef != null) {
|
111
|
+
// If refetch was called, we expect to have a refetchQuery and queryRef
|
112
|
+
// in state, since both state updates to set the refetchQuery and the
|
113
|
+
// queryRef occur simultaneously.
|
114
|
+
// In this case, we need to read the refetched query data (potentially
|
115
|
+
// suspending if it's in flight), and extract the new fragment ref
|
116
|
+
// from the query in order read the current @refetchable fragment
|
117
|
+
// with the updated fragment owner as the new refetchQuery.
|
118
|
+
|
119
|
+
// Before observing the refetch, record the current ID and typename
|
120
|
+
// so that, if we are refetching existing data on
|
121
|
+
// a field that implements Node, after refetching we
|
122
|
+
// can validate that the received data is consistent
|
123
|
+
var debugPreviousIDAndTypename;
|
124
|
+
if (process.env.NODE_ENV !== "production") {
|
125
|
+
debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(refetchQuery.request.variables, fragmentRefPathInResponse, environment);
|
126
|
+
}
|
127
|
+
var handleQueryCompleted = function handleQueryCompleted(maybeError) {
|
128
|
+
onComplete && onComplete(maybeError !== null && maybeError !== void 0 ? maybeError : null);
|
129
|
+
};
|
130
|
+
|
131
|
+
// The queryRef.source obtained from useQueryLoader will be
|
132
|
+
// an observable we can consume /if/ a network request was
|
133
|
+
// started. Otherwise, given that QueryResource.prepare
|
134
|
+
// always expects an observable we fall back to a new network
|
135
|
+
// observable. Note however that if loadQuery did not make a network
|
136
|
+
// request, we don't expect to make one here, unless the state of
|
137
|
+
// the cache has changed between the call to refetch and this
|
138
|
+
// render.
|
139
|
+
var fetchObservable = queryRef.source != null ? queryRef.source : fetchQuery(environment, refetchQuery);
|
140
|
+
|
141
|
+
// Now wwe can we read the refetch query here using the
|
142
|
+
// queryRef provided from useQueryLoader. Note that the
|
143
|
+
// network request is started during the call to refetch,
|
144
|
+
// but if the refetch query is still in flight, we will suspend
|
145
|
+
// at this point:
|
146
|
+
var queryResult = profilerContext.wrapPrepareQueryResource(function () {
|
147
|
+
return QueryResource.prepare(refetchQuery, fetchObservable, fetchPolicy, renderPolicy, {
|
148
|
+
error: handleQueryCompleted,
|
149
|
+
complete: function complete() {
|
150
|
+
// Validate that the type of the object we got back matches the type
|
151
|
+
// of the object already in the store
|
152
|
+
if (process.env.NODE_ENV !== "production") {
|
153
|
+
debugFunctions.checkSameTypeAfterRefetch(debugPreviousIDAndTypename, environment, fragmentNode, componentDisplayName);
|
154
|
+
}
|
155
|
+
handleQueryCompleted();
|
156
|
+
}
|
157
|
+
}, queryRef.fetchKey, profilerContext);
|
158
|
+
});
|
159
|
+
var queryData = readFragmentInternal(environment, queryResult.fragmentNode, queryResult.fragmentRef, componentDisplayName).data;
|
160
|
+
!(queryData != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to be able to read refetch query response. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
161
|
+
|
162
|
+
// After reading/fetching the refetch query, we extract from the
|
163
|
+
// refetch query response the new fragment ref we need to use to read
|
164
|
+
// the fragment. The new fragment ref will point to the refetch query
|
165
|
+
// as its fragment owner.
|
166
|
+
var refetchedFragmentRef = getValueAtPath(queryData, fragmentRefPathInResponse);
|
167
|
+
fragmentRef = refetchedFragmentRef;
|
168
|
+
if (process.env.NODE_ENV !== "production") {
|
169
|
+
// Validate that the id of the object we got back matches the id
|
170
|
+
// we queried for in the variables.
|
171
|
+
// We do this during render instead of onComplete to make sure we are
|
172
|
+
// only validating the most recent refetch.
|
173
|
+
debugFunctions.checkSameIDAfterRefetch(debugPreviousIDAndTypename, fragmentRef, fragmentNode, componentDisplayName);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
// We read and subscribe to the fragment using useFragmentNode.
|
178
|
+
// If refetch was called, we read the fragment using the new computed
|
179
|
+
// fragment ref from the refetch query response; otherwise, we use the
|
180
|
+
// fragment ref passed by the caller as normal.
|
181
|
+
var fragmentData = useFragmentInternal(fragmentNode, fragmentRef, componentDisplayName);
|
182
|
+
var refetch = useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierField, loadQuery, parentFragmentRef, refetchableRequest);
|
183
|
+
return {
|
184
|
+
fragmentData: fragmentData,
|
185
|
+
fragmentRef: fragmentRef,
|
186
|
+
refetch: refetch
|
187
|
+
};
|
188
|
+
}
|
189
|
+
function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierField, loadQuery, parentFragmentRef, refetchableRequest) {
|
190
|
+
var isMountedRef = useIsMountedRef();
|
191
|
+
var identifierValue = identifierField != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierField] : null;
|
192
|
+
return useCallback(function (providedRefetchVariables, options) {
|
193
|
+
// Bail out and warn if we're trying to refetch after the component
|
194
|
+
// has unmounted
|
195
|
+
if (isMountedRef.current !== true) {
|
196
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected call to `refetch` on unmounted component for fragment ' + '`%s` in `%s`. It looks like some instances of your component are ' + 'still trying to fetch data but they already unmounted. ' + 'Please make sure you clear all timers, intervals, ' + 'async calls, etc that may trigger a fetch.', fragmentNode.name, componentDisplayName) : void 0;
|
197
|
+
return {
|
198
|
+
dispose: function dispose() {}
|
199
|
+
};
|
200
|
+
}
|
201
|
+
if (parentFragmentRef == null) {
|
202
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected call to `refetch` while using a null fragment ref ' + 'for fragment `%s` in `%s`. When calling `refetch`, we expect ' + "initial fragment data to be non-null. Please make sure you're " + 'passing a valid fragment ref to `%s` before calling ' + '`refetch`, or make sure you pass all required variables to `refetch`.', fragmentNode.name, componentDisplayName, componentDisplayName) : void 0;
|
203
|
+
}
|
204
|
+
var refetchEnvironment = options === null || options === void 0 ? void 0 : options.__environment;
|
205
|
+
var fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy;
|
206
|
+
var renderPolicy = options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy;
|
207
|
+
var onComplete = options === null || options === void 0 ? void 0 : options.onComplete;
|
208
|
+
var fragmentSelector = getSelector(fragmentNode, parentFragmentRef);
|
209
|
+
var parentVariables;
|
210
|
+
var fragmentVariables;
|
211
|
+
if (fragmentSelector == null) {
|
212
|
+
parentVariables = {};
|
213
|
+
fragmentVariables = {};
|
214
|
+
} else if (fragmentSelector.kind === 'PluralReaderSelector') {
|
215
|
+
var _fragmentSelector$sel, _fragmentSelector$sel2, _fragmentSelector$sel3, _fragmentSelector$sel4;
|
216
|
+
parentVariables = (_fragmentSelector$sel = (_fragmentSelector$sel2 = fragmentSelector.selectors[0]) === null || _fragmentSelector$sel2 === void 0 ? void 0 : _fragmentSelector$sel2.owner.variables) !== null && _fragmentSelector$sel !== void 0 ? _fragmentSelector$sel : {};
|
217
|
+
fragmentVariables = (_fragmentSelector$sel3 = (_fragmentSelector$sel4 = fragmentSelector.selectors[0]) === null || _fragmentSelector$sel4 === void 0 ? void 0 : _fragmentSelector$sel4.variables) !== null && _fragmentSelector$sel3 !== void 0 ? _fragmentSelector$sel3 : {};
|
218
|
+
} else {
|
219
|
+
parentVariables = fragmentSelector.owner.variables;
|
220
|
+
fragmentVariables = fragmentSelector.variables;
|
221
|
+
}
|
222
|
+
|
223
|
+
// A user of `useRefetchableFragment()` may pass a subset of
|
224
|
+
// all variables required by the fragment when calling `refetch()`.
|
225
|
+
// We fill in any variables not passed by the call to `refetch()` with the
|
226
|
+
// variables from the original parent fragment owner.
|
227
|
+
var refetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables), providedRefetchVariables);
|
228
|
+
|
229
|
+
// If the query needs an identifier value ('id' or similar) and one
|
230
|
+
// was not explicitly provided, read it from the fragment data.
|
231
|
+
if (identifierField != null && !providedRefetchVariables.hasOwnProperty('id')) {
|
232
|
+
// @refetchable fragments are guaranteed to have an `id` selection
|
233
|
+
// if the type is Node, implements Node, or is @fetchable. Double-check
|
234
|
+
// that there actually is a value at runtime.
|
235
|
+
if (typeof identifierValue !== 'string') {
|
236
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected result to have a string ' + '`%s` in order to refetch, got `%s`.', identifierField, identifierValue) : void 0;
|
237
|
+
}
|
238
|
+
refetchVariables.id = identifierValue;
|
239
|
+
}
|
240
|
+
var refetchQuery = createOperationDescriptor(refetchableRequest, refetchVariables, {
|
241
|
+
force: true
|
242
|
+
});
|
243
|
+
|
244
|
+
// We call loadQuery which will start a network request if necessary
|
245
|
+
// and update the querRef from useQueryLoader.
|
246
|
+
// Note the following:
|
247
|
+
// - loadQuery will dispose of any previously refetched queries.
|
248
|
+
// - We use the variables extracted off the OperationDescriptor
|
249
|
+
// so that they have been filtered out to include only the
|
250
|
+
// variables actually declared in the query.
|
251
|
+
loadQuery(refetchQuery.request.variables, {
|
252
|
+
fetchPolicy: fetchPolicy,
|
253
|
+
__environment: refetchEnvironment,
|
254
|
+
__nameForWarning: 'refetch'
|
255
|
+
});
|
256
|
+
dispatch({
|
257
|
+
type: 'refetch',
|
258
|
+
fetchPolicy: fetchPolicy,
|
259
|
+
onComplete: onComplete,
|
260
|
+
refetchEnvironment: refetchEnvironment,
|
261
|
+
refetchQuery: refetchQuery,
|
262
|
+
renderPolicy: renderPolicy
|
263
|
+
});
|
264
|
+
return {
|
265
|
+
dispose: disposeQuery
|
266
|
+
};
|
267
|
+
},
|
268
|
+
// NOTE: We disable react-hooks-deps warning because:
|
269
|
+
// - We know fragmentRefPathInResponse is static, so it can be omitted from
|
270
|
+
// deps
|
271
|
+
// - We know fragmentNode is static, so it can be omitted from deps.
|
272
|
+
// - fragmentNode and parentFragmentRef are also captured by including
|
273
|
+
// fragmentIdentifier
|
274
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
275
|
+
[fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery]);
|
276
|
+
}
|
277
|
+
var debugFunctions;
|
278
|
+
if (process.env.NODE_ENV !== "production") {
|
279
|
+
debugFunctions = {
|
280
|
+
getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, environment) {
|
281
|
+
var _require4 = require('relay-runtime'),
|
282
|
+
Record = _require4.Record;
|
283
|
+
var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables.id;
|
284
|
+
if (fragmentRefPathInResponse.length !== 1 || fragmentRefPathInResponse[0] !== 'node' || id == null) {
|
285
|
+
return null;
|
286
|
+
}
|
287
|
+
var recordSource = environment.getStore().getSource();
|
288
|
+
var record = recordSource.get(id);
|
289
|
+
var typename = record && Record.getType(record);
|
290
|
+
if (typename == null) {
|
291
|
+
return null;
|
292
|
+
}
|
293
|
+
return {
|
294
|
+
id: id,
|
295
|
+
typename: typename
|
296
|
+
};
|
297
|
+
},
|
298
|
+
checkSameTypeAfterRefetch: function checkSameTypeAfterRefetch(previousIDAndType, environment, fragmentNode, componentDisplayName) {
|
299
|
+
var _require5 = require('relay-runtime'),
|
300
|
+
Record = _require5.Record;
|
301
|
+
if (!previousIDAndType) {
|
302
|
+
return;
|
303
|
+
}
|
304
|
+
var recordSource = environment.getStore().getSource();
|
305
|
+
var record = recordSource.get(previousIDAndType.id);
|
306
|
+
var typename = record && Record.getType(record);
|
307
|
+
if (typename !== previousIDAndType.typename) {
|
308
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Call to `refetch` returned data with a different ' + '__typename: was `%s`, now `%s`, on `%s` in `%s`. ' + 'Please make sure the server correctly implements' + 'unique id requirement.', previousIDAndType.typename, typename, fragmentNode.name, componentDisplayName) : void 0;
|
309
|
+
}
|
310
|
+
},
|
311
|
+
checkSameIDAfterRefetch: function checkSameIDAfterRefetch(previousIDAndTypename, refetchedFragmentRef, fragmentNode, componentDisplayName) {
|
312
|
+
if (previousIDAndTypename == null) {
|
313
|
+
return;
|
314
|
+
}
|
315
|
+
var _require6 = require('relay-runtime'),
|
316
|
+
ID_KEY = _require6.ID_KEY;
|
317
|
+
// $FlowExpectedError[incompatible-use]
|
318
|
+
var resultID = refetchedFragmentRef[ID_KEY];
|
319
|
+
if (resultID != null && resultID !== previousIDAndTypename.id) {
|
320
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Call to `refetch` returned a different id, expected ' + '`%s`, got `%s`, on `%s` in `%s`. ' + 'Please make sure the server correctly implements ' + 'unique id requirement.', resultID, previousIDAndTypename.id, fragmentNode.name, componentDisplayName) : void 0;
|
321
|
+
}
|
322
|
+
}
|
323
|
+
};
|
324
|
+
}
|
325
|
+
module.exports = useRefetchableFragmentNode;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
* @format
|
9
|
+
* @oncall relay
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
15
|
+
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
16
|
+
var _require = require('react'),
|
17
|
+
useDebugValue = _require.useDebugValue;
|
18
|
+
var _require2 = require('relay-runtime'),
|
19
|
+
getFragment = _require2.getFragment;
|
20
|
+
function useRefetchableFragment(fragmentInput, fragmentRef) {
|
21
|
+
var fragmentNode = getFragment(fragmentInput);
|
22
|
+
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
|
23
|
+
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
|
24
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
25
|
+
refetch = _useRefetchableFragme.refetch;
|
26
|
+
if (process.env.NODE_ENV !== "production") {
|
27
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
28
|
+
useDebugValue({
|
29
|
+
fragment: fragmentNode.name,
|
30
|
+
data: fragmentData
|
31
|
+
});
|
32
|
+
}
|
33
|
+
/* $FlowExpectedError[prop-missing] : Exposed options is a subset of internal
|
34
|
+
* options */
|
35
|
+
return [fragmentData, refetch];
|
36
|
+
}
|
37
|
+
module.exports = useRefetchableFragment;
|
@@ -4,98 +4,86 @@
|
|
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 _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
17
|
-
|
18
16
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
19
|
-
|
17
|
+
var _excluded = ["disableStoreUpdates", "enableStoreUpdates"];
|
20
18
|
var useLoadMoreFunction = require('./useLoadMoreFunction');
|
21
|
-
|
22
19
|
var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
23
|
-
|
24
20
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
25
|
-
|
26
21
|
var invariant = require('invariant');
|
27
|
-
|
28
22
|
var _require = require('react'),
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
useCallback = _require.useCallback,
|
24
|
+
useEffect = _require.useEffect,
|
25
|
+
useRef = _require.useRef,
|
26
|
+
useState = _require.useState;
|
34
27
|
var _require2 = require('relay-runtime'),
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
getFragment = _require2.getFragment,
|
29
|
+
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
30
|
+
getPaginationMetadata = _require2.getPaginationMetadata;
|
39
31
|
function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
|
40
32
|
var componentDisplayName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'useBlockingPaginationFragment()';
|
41
33
|
var fragmentNode = getFragment(fragmentInput);
|
42
34
|
useStaticFragmentNodeWarning(fragmentNode, "first argument of ".concat(componentDisplayName));
|
43
|
-
|
44
35
|
var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
36
|
+
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
37
|
+
identifierField = _getPaginationMetadat.identifierField,
|
38
|
+
paginationRequest = _getPaginationMetadat.paginationRequest,
|
39
|
+
paginationMetadata = _getPaginationMetadat.paginationMetadata,
|
40
|
+
stream = _getPaginationMetadat.stream;
|
51
41
|
!(stream === false) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: @stream_connection is not compatible with `useBlockingPaginationFragment`. ' + 'Use `useStreamingPaginationFragment` instead.') : invariant(false) : void 0;
|
52
|
-
|
53
42
|
var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName),
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
43
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
44
|
+
fragmentRef = _useRefetchableFragme.fragmentRef,
|
45
|
+
refetch = _useRefetchableFragme.refetch,
|
46
|
+
disableStoreUpdates = _useRefetchableFragme.disableStoreUpdates,
|
47
|
+
enableStoreUpdates = _useRefetchableFragme.enableStoreUpdates;
|
48
|
+
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
49
|
+
|
50
|
+
// Backward pagination
|
62
51
|
var _useLoadMore = useLoadMore({
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
52
|
+
componentDisplayName: componentDisplayName,
|
53
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
54
|
+
direction: 'backward',
|
55
|
+
disableStoreUpdates: disableStoreUpdates,
|
56
|
+
enableStoreUpdates: enableStoreUpdates,
|
57
|
+
fragmentData: fragmentData,
|
58
|
+
fragmentIdentifier: fragmentIdentifier,
|
59
|
+
fragmentNode: fragmentNode,
|
60
|
+
fragmentRef: fragmentRef,
|
61
|
+
identifierField: identifierField,
|
62
|
+
paginationMetadata: paginationMetadata,
|
63
|
+
paginationRequest: paginationRequest
|
64
|
+
}),
|
65
|
+
loadPrevious = _useLoadMore[0],
|
66
|
+
hasPrevious = _useLoadMore[1],
|
67
|
+
disposeFetchPrevious = _useLoadMore[2];
|
68
|
+
|
69
|
+
// Forward pagination
|
81
70
|
var _useLoadMore2 = useLoadMore({
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
71
|
+
componentDisplayName: componentDisplayName,
|
72
|
+
connectionPathInFragmentData: connectionPathInFragmentData,
|
73
|
+
direction: 'forward',
|
74
|
+
disableStoreUpdates: disableStoreUpdates,
|
75
|
+
enableStoreUpdates: enableStoreUpdates,
|
76
|
+
fragmentData: fragmentData,
|
77
|
+
fragmentIdentifier: fragmentIdentifier,
|
78
|
+
fragmentNode: fragmentNode,
|
79
|
+
fragmentRef: fragmentRef,
|
80
|
+
identifierField: identifierField,
|
81
|
+
paginationMetadata: paginationMetadata,
|
82
|
+
paginationRequest: paginationRequest
|
83
|
+
}),
|
84
|
+
loadNext = _useLoadMore2[0],
|
85
|
+
hasNext = _useLoadMore2[1],
|
86
|
+
disposeFetchNext = _useLoadMore2[2];
|
99
87
|
var refetchPagination = useCallback(function (variables, options) {
|
100
88
|
disposeFetchNext();
|
101
89
|
disposeFetchPrevious();
|
@@ -104,6 +92,7 @@ function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
|
|
104
92
|
}));
|
105
93
|
}, [disposeFetchNext, disposeFetchPrevious, refetch]);
|
106
94
|
return {
|
95
|
+
// $FlowFixMe[incompatible-cast]
|
107
96
|
data: fragmentData,
|
108
97
|
loadNext: loadNext,
|
109
98
|
loadPrevious: loadPrevious,
|
@@ -112,30 +101,24 @@ function useBlockingPaginationFragment(fragmentInput, parentFragmentRef) {
|
|
112
101
|
refetch: refetchPagination
|
113
102
|
};
|
114
103
|
}
|
115
|
-
|
116
104
|
function useLoadMore(args) {
|
117
105
|
var disableStoreUpdates = args.disableStoreUpdates,
|
118
|
-
|
119
|
-
|
120
|
-
|
106
|
+
enableStoreUpdates = args.enableStoreUpdates,
|
107
|
+
loadMoreArgs = (0, _objectWithoutPropertiesLoose2["default"])(args, _excluded);
|
121
108
|
var _useState = useState(null),
|
122
|
-
|
123
|
-
|
124
|
-
|
109
|
+
requestPromise = _useState[0],
|
110
|
+
setRequestPromise = _useState[1];
|
125
111
|
var requestPromiseRef = useRef(null);
|
126
112
|
var promiseResolveRef = useRef(null);
|
127
|
-
|
128
113
|
var promiseResolve = function promiseResolve() {
|
129
114
|
if (promiseResolveRef.current != null) {
|
130
115
|
promiseResolveRef.current();
|
131
116
|
promiseResolveRef.current = null;
|
132
117
|
}
|
133
118
|
};
|
134
|
-
|
135
119
|
var handleReset = function handleReset() {
|
136
120
|
promiseResolve();
|
137
121
|
};
|
138
|
-
|
139
122
|
var observer = {
|
140
123
|
complete: promiseResolve,
|
141
124
|
// NOTE: loadMore is a no-op if a request is already in flight, so we
|
@@ -165,34 +148,31 @@ function useLoadMore(args) {
|
|
165
148
|
// and blow away the whole list of items.
|
166
149
|
error: promiseResolve
|
167
150
|
};
|
168
|
-
|
169
151
|
var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, loadMoreArgs), {}, {
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
152
|
+
observer: observer,
|
153
|
+
onReset: handleReset
|
154
|
+
})),
|
155
|
+
loadMore = _useLoadMoreFunction[0],
|
156
|
+
hasMore = _useLoadMoreFunction[1],
|
157
|
+
disposeFetch = _useLoadMoreFunction[2];
|
158
|
+
|
159
|
+
// NOTE: To determine if we need to suspend, we check that the promise in
|
176
160
|
// state is the same as the promise on the ref, which ensures that we
|
177
161
|
// wont incorrectly suspend on other higher-pri updates before the update
|
178
162
|
// to suspend has committed.
|
179
|
-
|
180
|
-
|
181
163
|
if (requestPromise != null && requestPromise === requestPromiseRef.current) {
|
182
164
|
throw requestPromise;
|
183
165
|
}
|
184
|
-
|
185
166
|
useEffect(function () {
|
186
167
|
if (requestPromise !== requestPromiseRef.current) {
|
187
168
|
// NOTE: After suspense pagination has resolved, we re-enable store updates
|
188
169
|
// for this fragment. This may cause the component to re-render if
|
189
170
|
// we missed any updates to the fragment data other than the pagination update.
|
190
171
|
enableStoreUpdates();
|
191
|
-
}
|
172
|
+
}
|
173
|
+
// NOTE: We know the identity of enableStoreUpdates wont change
|
192
174
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
193
|
-
|
194
175
|
}, [requestPromise]);
|
195
176
|
return [loadMore, hasMore, disposeFetch];
|
196
177
|
}
|
197
|
-
|
198
178
|
module.exports = useBlockingPaginationFragment;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
* @format
|
9
|
+
* @oncall relay
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
+
var useLazyLoadQuery = require('./useLazyLoadQuery');
|
17
|
+
|
18
|
+
/**
|
19
|
+
* This hook can be used to render client-only queries.
|
20
|
+
* These queries are consist of queries for client-only data,
|
21
|
+
* schematized via local schema extensions and/or Relay resolvers.
|
22
|
+
*/
|
23
|
+
function useClientQuery(gqlQuery, variables, options) {
|
24
|
+
// $FlowFixMe[incompatible-type] client queries can be used with useLazyLoadQuery, but only with `store-only` policy.
|
25
|
+
var query = gqlQuery;
|
26
|
+
return useLazyLoadQuery(query, variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
|
27
|
+
fetchPolicy: 'store-only'
|
28
|
+
}));
|
29
|
+
}
|
30
|
+
module.exports = useClientQuery;
|