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