react-relay 14.1.0 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +20 -10
- package/ReactRelayQueryRenderer.js.flow +15 -11
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +2 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +10 -6
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +0 -11
- package/lib/ReactRelayContext.js +1 -12
- package/lib/ReactRelayFragmentContainer.js +23 -122
- package/lib/ReactRelayFragmentMockRenderer.js +0 -12
- package/lib/ReactRelayLocalQueryRenderer.js +12 -41
- package/lib/ReactRelayPaginationContainer.js +45 -341
- package/lib/ReactRelayQueryFetcher.js +36 -111
- package/lib/ReactRelayQueryRenderer.js +29 -137
- package/lib/ReactRelayQueryRendererContext.js +0 -10
- package/lib/ReactRelayRefetchContainer.js +33 -166
- package/lib/ReactRelayTestMocker.js +18 -128
- package/lib/ReactRelayTypes.js +0 -9
- package/lib/RelayContext.js +0 -23
- package/lib/assertFragmentMap.js +0 -16
- package/lib/buildReactRelayContainer.js +7 -41
- package/lib/getRootVariablesForFragments.js +2 -19
- package/lib/hooks.js +3 -30
- package/lib/index.js +3 -39
- package/lib/isRelayEnvironment.js +1 -16
- package/lib/jest-react/enqueueTask.js +1 -25
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +2 -51
- package/lib/legacy.js +0 -20
- package/lib/multi-actor/ActorChange.js +0 -14
- package/lib/multi-actor/index.js +0 -10
- package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
- package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
- package/lib/relay-hooks/FragmentResource.js +130 -280
- package/lib/relay-hooks/HooksImplementation.js +0 -14
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -39
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
- package/lib/relay-hooks/MatchContainer.js +9 -111
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -14
- package/lib/relay-hooks/QueryResource.js +14 -149
- package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
- package/lib/relay-hooks/SuspenseResource.js +2 -59
- package/lib/relay-hooks/loadEntryPoint.js +10 -45
- package/lib/relay-hooks/loadQuery.js +29 -169
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
- package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
- package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
- package/lib/relay-hooks/useClientQuery.js +0 -21
- package/lib/relay-hooks/useEntryPointLoader.js +12 -100
- package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
- package/lib/relay-hooks/useFragment.js +5 -32
- package/lib/relay-hooks/useFragmentNode.js +14 -55
- package/lib/relay-hooks/useIsMountedRef.js +2 -14
- package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
- package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
- package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
- package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
- package/lib/relay-hooks/useMemoVariables.js +8 -43
- package/lib/relay-hooks/useMutation.js +6 -34
- package/lib/relay-hooks/usePaginationFragment.js +49 -89
- package/lib/relay-hooks/usePreloadedQuery.js +10 -54
- package/lib/relay-hooks/useQueryLoader.js +18 -116
- package/lib/relay-hooks/useRefetchableFragment.js +4 -30
- package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
- package/lib/relay-hooks/useRelayEnvironment.js +2 -16
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
- package/lib/relay-hooks/useSubscription.js +3 -22
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
- package/relay-hooks/FragmentResource.js.flow +148 -34
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
- 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 +40 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +15 -8
- package/relay-hooks/loadQuery.js.flow +32 -8
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
- package/relay-hooks/useClientQuery.js.flow +3 -3
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +7 -6
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +30 -13
- package/relay-hooks/usePaginationFragment.js.flow +55 -54
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +78 -21
- package/relay-hooks/useRefetchableFragment.js.flow +65 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
@@ -1,57 +1,33 @@
|
|
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
|
-
* @emails oncall+relay
|
8
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
1
|
'use strict';
|
12
2
|
|
13
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
-
|
15
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
|
17
5
|
var ProfilerContext = require('../ProfilerContext');
|
18
|
-
|
19
6
|
var _require = require('../QueryResource'),
|
20
|
-
|
21
|
-
|
7
|
+
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
22
8
|
var useIsMountedRef = require('../useIsMountedRef');
|
23
|
-
|
24
9
|
var useQueryLoader = require('../useQueryLoader');
|
25
|
-
|
26
10
|
var useRelayEnvironment = require('../useRelayEnvironment');
|
27
|
-
|
28
11
|
var readFragmentInternal = require('./readFragmentInternal_REACT_CACHE');
|
29
|
-
|
30
12
|
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
31
|
-
|
32
13
|
var invariant = require('invariant');
|
33
|
-
|
34
14
|
var _require2 = require('react'),
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
15
|
+
useCallback = _require2.useCallback,
|
16
|
+
useContext = _require2.useContext,
|
17
|
+
useReducer = _require2.useReducer;
|
39
18
|
var _require3 = require('relay-runtime'),
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
19
|
+
fetchQuery = _require3.__internal.fetchQuery,
|
20
|
+
createOperationDescriptor = _require3.createOperationDescriptor,
|
21
|
+
getFragmentIdentifier = _require3.getFragmentIdentifier,
|
22
|
+
getRefetchMetadata = _require3.getRefetchMetadata,
|
23
|
+
getSelector = _require3.getSelector,
|
24
|
+
getValueAtPath = _require3.getValueAtPath;
|
47
25
|
var warning = require("fbjs/lib/warning");
|
48
|
-
|
49
26
|
function reducer(state, action) {
|
50
27
|
switch (action.type) {
|
51
28
|
case 'refetch':
|
52
29
|
{
|
53
30
|
var _action$refetchEnviro;
|
54
|
-
|
55
31
|
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
56
32
|
fetchPolicy: action.fetchPolicy,
|
57
33
|
mirroredEnvironment: (_action$refetchEnviro = action.refetchEnvironment) !== null && _action$refetchEnviro !== void 0 ? _action$refetchEnviro : state.mirroredEnvironment,
|
@@ -61,7 +37,6 @@ function reducer(state, action) {
|
|
61
37
|
renderPolicy: action.renderPolicy
|
62
38
|
});
|
63
39
|
}
|
64
|
-
|
65
40
|
case 'reset':
|
66
41
|
{
|
67
42
|
return {
|
@@ -73,7 +48,6 @@ function reducer(state, action) {
|
|
73
48
|
renderPolicy: undefined
|
74
49
|
};
|
75
50
|
}
|
76
|
-
|
77
51
|
default:
|
78
52
|
{
|
79
53
|
action.type;
|
@@ -81,48 +55,40 @@ function reducer(state, action) {
|
|
81
55
|
}
|
82
56
|
}
|
83
57
|
}
|
84
|
-
|
85
58
|
function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName) {
|
86
59
|
var parentEnvironment = useRelayEnvironment();
|
87
|
-
|
88
60
|
var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
61
|
+
refetchableRequest = _getRefetchMetadata.refetchableRequest,
|
62
|
+
fragmentRefPathInResponse = _getRefetchMetadata.fragmentRefPathInResponse,
|
63
|
+
identifierInfo = _getRefetchMetadata.identifierInfo;
|
93
64
|
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, parentFragmentRef);
|
94
|
-
|
95
65
|
var _useReducer = useReducer(reducer, {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
66
|
+
fetchPolicy: undefined,
|
67
|
+
mirroredEnvironment: parentEnvironment,
|
68
|
+
mirroredFragmentIdentifier: fragmentIdentifier,
|
69
|
+
onComplete: undefined,
|
70
|
+
refetchEnvironment: null,
|
71
|
+
refetchQuery: null,
|
72
|
+
renderPolicy: undefined
|
73
|
+
}),
|
74
|
+
refetchState = _useReducer[0],
|
75
|
+
dispatch = _useReducer[1];
|
107
76
|
var fetchPolicy = refetchState.fetchPolicy,
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
77
|
+
mirroredEnvironment = refetchState.mirroredEnvironment,
|
78
|
+
mirroredFragmentIdentifier = refetchState.mirroredFragmentIdentifier,
|
79
|
+
onComplete = refetchState.onComplete,
|
80
|
+
refetchEnvironment = refetchState.refetchEnvironment,
|
81
|
+
refetchQuery = refetchState.refetchQuery,
|
82
|
+
renderPolicy = refetchState.renderPolicy;
|
114
83
|
var environment = refetchEnvironment !== null && refetchEnvironment !== void 0 ? refetchEnvironment : parentEnvironment;
|
115
84
|
var QueryResource = getQueryResourceForEnvironment(environment);
|
116
85
|
var profilerContext = useContext(ProfilerContext);
|
117
86
|
var shouldReset = environment !== mirroredEnvironment || fragmentIdentifier !== mirroredFragmentIdentifier;
|
118
|
-
|
119
87
|
var _useQueryLoader = useQueryLoader(refetchableRequest),
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
88
|
+
queryRef = _useQueryLoader[0],
|
89
|
+
loadQuery = _useQueryLoader[1],
|
90
|
+
disposeQuery = _useQueryLoader[2];
|
124
91
|
var fragmentRef = parentFragmentRef;
|
125
|
-
|
126
92
|
if (shouldReset) {
|
127
93
|
dispatch({
|
128
94
|
type: 'reset',
|
@@ -131,103 +97,54 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
131
97
|
});
|
132
98
|
disposeQuery();
|
133
99
|
} else if (refetchQuery != null && queryRef != null) {
|
134
|
-
// If refetch was called, we expect to have a refetchQuery and queryRef
|
135
|
-
// in state, since both state updates to set the refetchQuery and the
|
136
|
-
// queryRef occur simultaneously.
|
137
|
-
// In this case, we need to read the refetched query data (potentially
|
138
|
-
// suspending if it's in flight), and extract the new fragment ref
|
139
|
-
// from the query in order read the current @refetchable fragment
|
140
|
-
// with the updated fragment owner as the new refetchQuery.
|
141
|
-
// Before observing the refetch, record the current ID and typename
|
142
|
-
// so that, if we are refetching existing data on
|
143
|
-
// a field that implements Node, after refetching we
|
144
|
-
// can validate that the received data is consistent
|
145
100
|
var debugPreviousIDAndTypename;
|
146
|
-
|
147
101
|
if (process.env.NODE_ENV !== "production") {
|
148
|
-
debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(refetchQuery.request.variables, fragmentRefPathInResponse, environment);
|
102
|
+
debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(refetchQuery.request.variables, fragmentRefPathInResponse, identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierQueryVariableName, environment);
|
149
103
|
}
|
150
|
-
|
151
104
|
var handleQueryCompleted = function handleQueryCompleted(maybeError) {
|
152
105
|
onComplete && onComplete(maybeError !== null && maybeError !== void 0 ? maybeError : null);
|
153
|
-
};
|
154
|
-
|
155
|
-
// started. Otherwise, given that QueryResource.prepare
|
156
|
-
// always expects an observable we fall back to a new network
|
157
|
-
// observable. Note however that if loadQuery did not make a network
|
158
|
-
// request, we don't expect to make one here, unless the state of
|
159
|
-
// the cache has changed between the call to refetch and this
|
160
|
-
// render.
|
161
|
-
|
162
|
-
|
163
|
-
var fetchObservable = queryRef.source != null ? queryRef.source : fetchQuery(environment, refetchQuery); // Now wwe can we read the refetch query here using the
|
164
|
-
// queryRef provided from useQueryLoader. Note that the
|
165
|
-
// network request is started during the call to refetch,
|
166
|
-
// but if the refetch query is still in flight, we will suspend
|
167
|
-
// at this point:
|
168
|
-
|
106
|
+
};
|
107
|
+
var fetchObservable = queryRef.source != null ? queryRef.source : fetchQuery(environment, refetchQuery);
|
169
108
|
var queryResult = profilerContext.wrapPrepareQueryResource(function () {
|
170
109
|
return QueryResource.prepare(refetchQuery, fetchObservable, fetchPolicy, renderPolicy, {
|
171
110
|
error: handleQueryCompleted,
|
172
111
|
complete: function complete() {
|
173
|
-
// Validate that the type of the object we got back matches the type
|
174
|
-
// of the object already in the store
|
175
112
|
if (process.env.NODE_ENV !== "production") {
|
176
113
|
debugFunctions.checkSameTypeAfterRefetch(debugPreviousIDAndTypename, environment, fragmentNode, componentDisplayName);
|
177
114
|
}
|
178
|
-
|
179
115
|
handleQueryCompleted();
|
180
116
|
}
|
181
117
|
}, queryRef.fetchKey, profilerContext);
|
182
118
|
});
|
183
119
|
var queryData = readFragmentInternal(environment, queryResult.fragmentNode, queryResult.fragmentRef, componentDisplayName).data;
|
184
|
-
!(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;
|
185
|
-
// refetch query response the new fragment ref we need to use to read
|
186
|
-
// the fragment. The new fragment ref will point to the refetch query
|
187
|
-
// as its fragment owner.
|
188
|
-
|
120
|
+
!(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;
|
189
121
|
var refetchedFragmentRef = getValueAtPath(queryData, fragmentRefPathInResponse);
|
190
122
|
fragmentRef = refetchedFragmentRef;
|
191
|
-
|
192
123
|
if (process.env.NODE_ENV !== "production") {
|
193
|
-
// Validate that the id of the object we got back matches the id
|
194
|
-
// we queried for in the variables.
|
195
|
-
// We do this during render instead of onComplete to make sure we are
|
196
|
-
// only validating the most recent refetch.
|
197
124
|
debugFunctions.checkSameIDAfterRefetch(debugPreviousIDAndTypename, fragmentRef, fragmentNode, componentDisplayName);
|
198
125
|
}
|
199
|
-
}
|
200
|
-
// If refetch was called, we read the fragment using the new computed
|
201
|
-
// fragment ref from the refetch query response; otherwise, we use the
|
202
|
-
// fragment ref passed by the caller as normal.
|
203
|
-
|
204
|
-
|
126
|
+
}
|
205
127
|
var fragmentData = useFragmentInternal(fragmentNode, fragmentRef, componentDisplayName);
|
206
|
-
var refetch = useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse,
|
128
|
+
var refetch = useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierInfo, loadQuery, parentFragmentRef, refetchableRequest);
|
207
129
|
return {
|
208
130
|
fragmentData: fragmentData,
|
209
131
|
fragmentRef: fragmentRef,
|
210
132
|
refetch: refetch
|
211
133
|
};
|
212
134
|
}
|
213
|
-
|
214
|
-
function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierField, loadQuery, parentFragmentRef, refetchableRequest) {
|
135
|
+
function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierInfo, loadQuery, parentFragmentRef, refetchableRequest) {
|
215
136
|
var isMountedRef = useIsMountedRef();
|
216
|
-
var identifierValue = identifierField != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierField] : null;
|
137
|
+
var identifierValue = (identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierField) != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierInfo.identifierField] : null;
|
217
138
|
return useCallback(function (providedRefetchVariables, options) {
|
218
|
-
// Bail out and warn if we're trying to refetch after the component
|
219
|
-
// has unmounted
|
220
139
|
if (isMountedRef.current !== true) {
|
221
140
|
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;
|
222
141
|
return {
|
223
142
|
dispose: function dispose() {}
|
224
143
|
};
|
225
144
|
}
|
226
|
-
|
227
145
|
if (parentFragmentRef == null) {
|
228
146
|
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;
|
229
147
|
}
|
230
|
-
|
231
148
|
var refetchEnvironment = options === null || options === void 0 ? void 0 : options.__environment;
|
232
149
|
var fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy;
|
233
150
|
var renderPolicy = options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy;
|
@@ -235,48 +152,27 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
235
152
|
var fragmentSelector = getSelector(fragmentNode, parentFragmentRef);
|
236
153
|
var parentVariables;
|
237
154
|
var fragmentVariables;
|
238
|
-
|
239
155
|
if (fragmentSelector == null) {
|
240
156
|
parentVariables = {};
|
241
157
|
fragmentVariables = {};
|
242
158
|
} else if (fragmentSelector.kind === 'PluralReaderSelector') {
|
243
159
|
var _fragmentSelector$sel, _fragmentSelector$sel2, _fragmentSelector$sel3, _fragmentSelector$sel4;
|
244
|
-
|
245
160
|
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 : {};
|
246
161
|
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 : {};
|
247
162
|
} else {
|
248
163
|
parentVariables = fragmentSelector.owner.variables;
|
249
164
|
fragmentVariables = fragmentSelector.variables;
|
250
|
-
}
|
251
|
-
|
252
|
-
|
253
|
-
// variables from the original parent fragment owner.
|
254
|
-
|
255
|
-
|
256
|
-
var refetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables), providedRefetchVariables); // If the query needs an identifier value ('id' or similar) and one
|
257
|
-
// was not explicitly provided, read it from the fragment data.
|
258
|
-
|
259
|
-
if (identifierField != null && !providedRefetchVariables.hasOwnProperty('id')) {
|
260
|
-
// @refetchable fragments are guaranteed to have an `id` selection
|
261
|
-
// if the type is Node, implements Node, or is @fetchable. Double-check
|
262
|
-
// that there actually is a value at runtime.
|
165
|
+
}
|
166
|
+
var refetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables), providedRefetchVariables);
|
167
|
+
if (identifierInfo != null && !providedRefetchVariables.hasOwnProperty(identifierInfo.identifierQueryVariableName)) {
|
263
168
|
if (typeof identifierValue !== 'string') {
|
264
|
-
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;
|
169
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected result to have a string ' + '`%s` in order to refetch, got `%s`.', identifierInfo.identifierField, identifierValue) : void 0;
|
265
170
|
}
|
266
|
-
|
267
|
-
refetchVariables.id = identifierValue;
|
171
|
+
refetchVariables[identifierInfo.identifierQueryVariableName] = identifierValue;
|
268
172
|
}
|
269
|
-
|
270
173
|
var refetchQuery = createOperationDescriptor(refetchableRequest, refetchVariables, {
|
271
174
|
force: true
|
272
|
-
});
|
273
|
-
// and update the querRef from useQueryLoader.
|
274
|
-
// Note the following:
|
275
|
-
// - loadQuery will dispose of any previously refetched queries.
|
276
|
-
// - We use the variables extracted off the OperationDescriptor
|
277
|
-
// so that they have been filtered out to include only the
|
278
|
-
// variables actually declared in the query.
|
279
|
-
|
175
|
+
});
|
280
176
|
loadQuery(refetchQuery.request.variables, {
|
281
177
|
fetchPolicy: fetchPolicy,
|
282
178
|
__environment: refetchEnvironment,
|
@@ -293,38 +189,24 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
293
189
|
return {
|
294
190
|
dispose: disposeQuery
|
295
191
|
};
|
296
|
-
},
|
297
|
-
// - We know fragmentRefPathInResponse is static, so it can be omitted from
|
298
|
-
// deps
|
299
|
-
// - We know fragmentNode is static, so it can be omitted from deps.
|
300
|
-
// - fragmentNode and parentFragmentRef are also captured by including
|
301
|
-
// fragmentIdentifier
|
302
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
303
|
-
[fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery]);
|
192
|
+
}, [fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery]);
|
304
193
|
}
|
305
|
-
|
306
194
|
var debugFunctions;
|
307
|
-
|
308
195
|
if (process.env.NODE_ENV !== "production") {
|
309
196
|
debugFunctions = {
|
310
|
-
getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, environment) {
|
197
|
+
getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, identifierQueryVariableName, environment) {
|
311
198
|
var _require4 = require('relay-runtime'),
|
312
|
-
|
313
|
-
|
314
|
-
var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables.id;
|
315
|
-
|
199
|
+
Record = _require4.Record;
|
200
|
+
var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables[identifierQueryVariableName !== null && identifierQueryVariableName !== void 0 ? identifierQueryVariableName : 'id'];
|
316
201
|
if (fragmentRefPathInResponse.length !== 1 || fragmentRefPathInResponse[0] !== 'node' || id == null) {
|
317
202
|
return null;
|
318
203
|
}
|
319
|
-
|
320
204
|
var recordSource = environment.getStore().getSource();
|
321
205
|
var record = recordSource.get(id);
|
322
|
-
var typename = record
|
323
|
-
|
206
|
+
var typename = record == null ? null : Record.getType(record);
|
324
207
|
if (typename == null) {
|
325
208
|
return null;
|
326
209
|
}
|
327
|
-
|
328
210
|
return {
|
329
211
|
id: id,
|
330
212
|
typename: typename
|
@@ -332,16 +214,13 @@ if (process.env.NODE_ENV !== "production") {
|
|
332
214
|
},
|
333
215
|
checkSameTypeAfterRefetch: function checkSameTypeAfterRefetch(previousIDAndType, environment, fragmentNode, componentDisplayName) {
|
334
216
|
var _require5 = require('relay-runtime'),
|
335
|
-
|
336
|
-
|
217
|
+
Record = _require5.Record;
|
337
218
|
if (!previousIDAndType) {
|
338
219
|
return;
|
339
220
|
}
|
340
|
-
|
341
221
|
var recordSource = environment.getStore().getSource();
|
342
222
|
var record = recordSource.get(previousIDAndType.id);
|
343
223
|
var typename = record && Record.getType(record);
|
344
|
-
|
345
224
|
if (typename !== previousIDAndType.typename) {
|
346
225
|
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;
|
347
226
|
}
|
@@ -350,18 +229,13 @@ if (process.env.NODE_ENV !== "production") {
|
|
350
229
|
if (previousIDAndTypename == null) {
|
351
230
|
return;
|
352
231
|
}
|
353
|
-
|
354
232
|
var _require6 = require('relay-runtime'),
|
355
|
-
|
356
|
-
|
357
|
-
|
233
|
+
ID_KEY = _require6.ID_KEY;
|
358
234
|
var resultID = refetchedFragmentRef[ID_KEY];
|
359
|
-
|
360
235
|
if (resultID != null && resultID !== previousIDAndTypename.id) {
|
361
236
|
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;
|
362
237
|
}
|
363
238
|
}
|
364
239
|
};
|
365
240
|
}
|
366
|
-
|
367
241
|
module.exports = useRefetchableFragmentNode;
|
@@ -1,45 +1,23 @@
|
|
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
|
-
* @emails oncall+relay
|
8
|
-
*
|
9
|
-
* @format
|
10
|
-
*/
|
11
1
|
'use strict';
|
12
2
|
|
13
|
-
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
14
|
-
|
15
3
|
var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
|
16
|
-
|
4
|
+
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
|
17
5
|
var _require = require('react'),
|
18
|
-
|
19
|
-
|
6
|
+
useDebugValue = _require.useDebugValue;
|
20
7
|
var _require2 = require('relay-runtime'),
|
21
|
-
|
22
|
-
|
8
|
+
getFragment = _require2.getFragment;
|
23
9
|
function useRefetchableFragment(fragmentInput, fragmentRef) {
|
24
10
|
var fragmentNode = getFragment(fragmentInput);
|
25
11
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
|
26
|
-
|
27
12
|
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
fragmentData = _useRefetchableFragme.fragmentData,
|
14
|
+
refetch = _useRefetchableFragme.refetch;
|
31
15
|
if (process.env.NODE_ENV !== "production") {
|
32
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
33
16
|
useDebugValue({
|
34
17
|
fragment: fragmentNode.name,
|
35
18
|
data: fragmentData
|
36
19
|
});
|
37
20
|
}
|
38
|
-
/* $FlowExpectedError[prop-missing] : Exposed options is a subset of internal
|
39
|
-
* options */
|
40
|
-
|
41
|
-
|
42
21
|
return [fragmentData, refetch];
|
43
22
|
}
|
44
|
-
|
45
23
|
module.exports = useRefetchableFragment;
|