react-relay 14.0.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
@@ -4,56 +4,42 @@
|
|
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 _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
|
-
|
18
16
|
var _require = require('./FragmentResource'),
|
19
|
-
|
20
|
-
|
17
|
+
getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
|
21
18
|
var ProfilerContext = require('./ProfilerContext');
|
22
|
-
|
23
19
|
var _require2 = require('./QueryResource'),
|
24
|
-
|
25
|
-
|
20
|
+
getQueryResourceForEnvironment = _require2.getQueryResourceForEnvironment;
|
26
21
|
var useFragmentNode = require('./useFragmentNode');
|
27
|
-
|
28
22
|
var useIsMountedRef = require('./useIsMountedRef');
|
29
|
-
|
30
23
|
var useQueryLoader = require('./useQueryLoader');
|
31
|
-
|
32
24
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
33
|
-
|
34
25
|
var invariant = require('invariant');
|
35
|
-
|
36
26
|
var _require3 = require('react'),
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
useCallback = _require3.useCallback,
|
28
|
+
useContext = _require3.useContext,
|
29
|
+
useReducer = _require3.useReducer;
|
41
30
|
var _require4 = require('relay-runtime'),
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
fetchQuery = _require4.__internal.fetchQuery,
|
32
|
+
createOperationDescriptor = _require4.createOperationDescriptor,
|
33
|
+
getFragmentIdentifier = _require4.getFragmentIdentifier,
|
34
|
+
getRefetchMetadata = _require4.getRefetchMetadata,
|
35
|
+
getSelector = _require4.getSelector,
|
36
|
+
getValueAtPath = _require4.getValueAtPath;
|
49
37
|
var warning = require("fbjs/lib/warning");
|
50
|
-
|
51
38
|
function reducer(state, action) {
|
52
39
|
switch (action.type) {
|
53
40
|
case 'refetch':
|
54
41
|
{
|
55
42
|
var _action$refetchEnviro;
|
56
|
-
|
57
43
|
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
58
44
|
fetchPolicy: action.fetchPolicy,
|
59
45
|
mirroredEnvironment: (_action$refetchEnviro = action.refetchEnvironment) !== null && _action$refetchEnviro !== void 0 ? _action$refetchEnviro : state.mirroredEnvironment,
|
@@ -63,7 +49,6 @@ function reducer(state, action) {
|
|
63
49
|
renderPolicy: action.renderPolicy
|
64
50
|
});
|
65
51
|
}
|
66
|
-
|
67
52
|
case 'reset':
|
68
53
|
{
|
69
54
|
return {
|
@@ -75,7 +60,6 @@ function reducer(state, action) {
|
|
75
60
|
renderPolicy: undefined
|
76
61
|
};
|
77
62
|
}
|
78
|
-
|
79
63
|
default:
|
80
64
|
{
|
81
65
|
action.type;
|
@@ -83,49 +67,41 @@ function reducer(state, action) {
|
|
83
67
|
}
|
84
68
|
}
|
85
69
|
}
|
86
|
-
|
87
70
|
function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName) {
|
88
71
|
var parentEnvironment = useRelayEnvironment();
|
89
|
-
|
90
72
|
var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
73
|
+
refetchableRequest = _getRefetchMetadata.refetchableRequest,
|
74
|
+
fragmentRefPathInResponse = _getRefetchMetadata.fragmentRefPathInResponse,
|
75
|
+
identifierField = _getRefetchMetadata.identifierField;
|
95
76
|
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, parentFragmentRef);
|
96
|
-
|
97
77
|
var _useReducer = useReducer(reducer, {
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
78
|
+
fetchPolicy: undefined,
|
79
|
+
mirroredEnvironment: parentEnvironment,
|
80
|
+
mirroredFragmentIdentifier: fragmentIdentifier,
|
81
|
+
onComplete: undefined,
|
82
|
+
refetchEnvironment: null,
|
83
|
+
refetchQuery: null,
|
84
|
+
renderPolicy: undefined
|
85
|
+
}),
|
86
|
+
refetchState = _useReducer[0],
|
87
|
+
dispatch = _useReducer[1];
|
109
88
|
var fetchPolicy = refetchState.fetchPolicy,
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
89
|
+
mirroredEnvironment = refetchState.mirroredEnvironment,
|
90
|
+
mirroredFragmentIdentifier = refetchState.mirroredFragmentIdentifier,
|
91
|
+
onComplete = refetchState.onComplete,
|
92
|
+
refetchEnvironment = refetchState.refetchEnvironment,
|
93
|
+
refetchQuery = refetchState.refetchQuery,
|
94
|
+
renderPolicy = refetchState.renderPolicy;
|
116
95
|
var environment = refetchEnvironment !== null && refetchEnvironment !== void 0 ? refetchEnvironment : parentEnvironment;
|
117
96
|
var QueryResource = getQueryResourceForEnvironment(environment);
|
118
97
|
var FragmentResource = getFragmentResourceForEnvironment(environment);
|
119
98
|
var profilerContext = useContext(ProfilerContext);
|
120
99
|
var shouldReset = environment !== mirroredEnvironment || fragmentIdentifier !== mirroredFragmentIdentifier;
|
121
|
-
|
122
100
|
var _useQueryLoader = useQueryLoader(refetchableRequest),
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
101
|
+
queryRef = _useQueryLoader[0],
|
102
|
+
loadQuery = _useQueryLoader[1],
|
103
|
+
disposeQuery = _useQueryLoader[2];
|
127
104
|
var fragmentRef = parentFragmentRef;
|
128
|
-
|
129
105
|
if (shouldReset) {
|
130
106
|
dispatch({
|
131
107
|
type: 'reset',
|
@@ -141,19 +117,20 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
141
117
|
// suspending if it's in flight), and extract the new fragment ref
|
142
118
|
// from the query in order read the current @refetchable fragment
|
143
119
|
// with the updated fragment owner as the new refetchQuery.
|
120
|
+
|
144
121
|
// Before observing the refetch, record the current ID and typename
|
145
122
|
// so that, if we are refetching existing data on
|
146
123
|
// a field that implements Node, after refetching we
|
147
124
|
// can validate that the received data is consistent
|
148
125
|
var debugPreviousIDAndTypename;
|
149
|
-
|
150
126
|
if (process.env.NODE_ENV !== "production") {
|
151
127
|
debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(refetchQuery.request.variables, fragmentRefPathInResponse, environment);
|
152
128
|
}
|
153
|
-
|
154
129
|
var handleQueryCompleted = function handleQueryCompleted(maybeError) {
|
155
130
|
onComplete && onComplete(maybeError !== null && maybeError !== void 0 ? maybeError : null);
|
156
|
-
};
|
131
|
+
};
|
132
|
+
|
133
|
+
// The queryRef.source obtained from useQueryLoader will be
|
157
134
|
// an observable we can consume /if/ a network request was
|
158
135
|
// started. Otherwise, given that QueryResource.prepare
|
159
136
|
// always expects an observable we fall back to a new network
|
@@ -161,14 +138,13 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
161
138
|
// request, we don't expect to make one here, unless the state of
|
162
139
|
// the cache has changed between the call to refetch and this
|
163
140
|
// render.
|
141
|
+
var fetchObservable = queryRef.source != null ? queryRef.source : fetchQuery(environment, refetchQuery);
|
164
142
|
|
165
|
-
|
166
|
-
var fetchObservable = queryRef.source != null ? queryRef.source : fetchQuery(environment, refetchQuery); // Now wwe can we read the refetch query here using the
|
143
|
+
// Now wwe can we read the refetch query here using the
|
167
144
|
// queryRef provided from useQueryLoader. Note that the
|
168
145
|
// network request is started during the call to refetch,
|
169
146
|
// but if the refetch query is still in flight, we will suspend
|
170
147
|
// at this point:
|
171
|
-
|
172
148
|
var queryResult = profilerContext.wrapPrepareQueryResource(function () {
|
173
149
|
return QueryResource.prepare(refetchQuery, fetchObservable, fetchPolicy, renderPolicy, {
|
174
150
|
error: handleQueryCompleted,
|
@@ -178,20 +154,19 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
178
154
|
if (process.env.NODE_ENV !== "production") {
|
179
155
|
debugFunctions.checkSameTypeAfterRefetch(debugPreviousIDAndTypename, environment, fragmentNode, componentDisplayName);
|
180
156
|
}
|
181
|
-
|
182
157
|
handleQueryCompleted();
|
183
158
|
}
|
184
159
|
}, queryRef.fetchKey, profilerContext);
|
185
160
|
});
|
186
161
|
var queryData = FragmentResource.read(queryResult.fragmentNode, queryResult.fragmentRef, componentDisplayName).data;
|
187
|
-
!(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;
|
162
|
+
!(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;
|
163
|
+
|
164
|
+
// After reading/fetching the refetch query, we extract from the
|
188
165
|
// refetch query response the new fragment ref we need to use to read
|
189
166
|
// the fragment. The new fragment ref will point to the refetch query
|
190
167
|
// as its fragment owner.
|
191
|
-
|
192
168
|
var refetchedFragmentRef = getValueAtPath(queryData, fragmentRefPathInResponse);
|
193
169
|
fragmentRef = refetchedFragmentRef;
|
194
|
-
|
195
170
|
if (process.env.NODE_ENV !== "production") {
|
196
171
|
// Validate that the id of the object we got back matches the id
|
197
172
|
// we queried for in the variables.
|
@@ -199,17 +174,16 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
199
174
|
// only validating the most recent refetch.
|
200
175
|
debugFunctions.checkSameIDAfterRefetch(debugPreviousIDAndTypename, fragmentRef, fragmentNode, componentDisplayName);
|
201
176
|
}
|
202
|
-
}
|
177
|
+
}
|
178
|
+
|
179
|
+
// We read and subscribe to the fragment using useFragmentNode.
|
203
180
|
// If refetch was called, we read the fragment using the new computed
|
204
181
|
// fragment ref from the refetch query response; otherwise, we use the
|
205
182
|
// fragment ref passed by the caller as normal.
|
206
|
-
|
207
|
-
|
208
183
|
var _useFragmentNode = useFragmentNode(fragmentNode, fragmentRef, componentDisplayName),
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
184
|
+
fragmentData = _useFragmentNode.data,
|
185
|
+
disableStoreUpdates = _useFragmentNode.disableStoreUpdates,
|
186
|
+
enableStoreUpdates = _useFragmentNode.enableStoreUpdates;
|
213
187
|
var refetch = useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierField, loadQuery, parentFragmentRef, refetchableRequest);
|
214
188
|
return {
|
215
189
|
fragmentData: fragmentData,
|
@@ -219,7 +193,6 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
219
193
|
enableStoreUpdates: enableStoreUpdates
|
220
194
|
};
|
221
195
|
}
|
222
|
-
|
223
196
|
function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierField, loadQuery, parentFragmentRef, refetchableRequest) {
|
224
197
|
var isMountedRef = useIsMountedRef();
|
225
198
|
var identifierValue = identifierField != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierField] : null;
|
@@ -232,11 +205,9 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
232
205
|
dispose: function dispose() {}
|
233
206
|
};
|
234
207
|
}
|
235
|
-
|
236
208
|
if (parentFragmentRef == null) {
|
237
209
|
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;
|
238
210
|
}
|
239
|
-
|
240
211
|
var refetchEnvironment = options === null || options === void 0 ? void 0 : options.__environment;
|
241
212
|
var fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy;
|
242
213
|
var renderPolicy = options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy;
|
@@ -244,27 +215,26 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
244
215
|
var fragmentSelector = getSelector(fragmentNode, parentFragmentRef);
|
245
216
|
var parentVariables;
|
246
217
|
var fragmentVariables;
|
247
|
-
|
248
218
|
if (fragmentSelector == null) {
|
249
219
|
parentVariables = {};
|
250
220
|
fragmentVariables = {};
|
251
221
|
} else if (fragmentSelector.kind === 'PluralReaderSelector') {
|
252
222
|
var _fragmentSelector$sel, _fragmentSelector$sel2, _fragmentSelector$sel3, _fragmentSelector$sel4;
|
253
|
-
|
254
223
|
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 : {};
|
255
224
|
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 : {};
|
256
225
|
} else {
|
257
226
|
parentVariables = fragmentSelector.owner.variables;
|
258
227
|
fragmentVariables = fragmentSelector.variables;
|
259
|
-
}
|
228
|
+
}
|
229
|
+
|
230
|
+
// A user of `useRefetchableFragment()` may pass a subset of
|
260
231
|
// all variables required by the fragment when calling `refetch()`.
|
261
232
|
// We fill in any variables not passed by the call to `refetch()` with the
|
262
233
|
// variables from the original parent fragment owner.
|
234
|
+
var refetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables), providedRefetchVariables);
|
263
235
|
|
264
|
-
|
265
|
-
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
|
236
|
+
// If the query needs an identifier value ('id' or similar) and one
|
266
237
|
// was not explicitly provided, read it from the fragment data.
|
267
|
-
|
268
238
|
if (identifierField != null && !providedRefetchVariables.hasOwnProperty('id')) {
|
269
239
|
// @refetchable fragments are guaranteed to have an `id` selection
|
270
240
|
// if the type is Node, implements Node, or is @fetchable. Double-check
|
@@ -272,20 +242,19 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
272
242
|
if (typeof identifierValue !== 'string') {
|
273
243
|
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;
|
274
244
|
}
|
275
|
-
|
276
245
|
refetchVariables.id = identifierValue;
|
277
246
|
}
|
278
|
-
|
279
247
|
var refetchQuery = createOperationDescriptor(refetchableRequest, refetchVariables, {
|
280
248
|
force: true
|
281
|
-
});
|
249
|
+
});
|
250
|
+
|
251
|
+
// We call loadQuery which will start a network request if necessary
|
282
252
|
// and update the querRef from useQueryLoader.
|
283
253
|
// Note the following:
|
284
254
|
// - loadQuery will dispose of any previously refetched queries.
|
285
255
|
// - We use the variables extracted off the OperationDescriptor
|
286
256
|
// so that they have been filtered out to include only the
|
287
257
|
// variables actually declared in the query.
|
288
|
-
|
289
258
|
loadQuery(refetchQuery.request.variables, {
|
290
259
|
fetchPolicy: fetchPolicy,
|
291
260
|
__environment: refetchEnvironment,
|
@@ -302,7 +271,8 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
302
271
|
return {
|
303
272
|
dispose: disposeQuery
|
304
273
|
};
|
305
|
-
},
|
274
|
+
},
|
275
|
+
// NOTE: We disable react-hooks-deps warning because:
|
306
276
|
// - We know fragmentRefPathInResponse is static, so it can be omitted from
|
307
277
|
// deps
|
308
278
|
// - We know fragmentNode is static, so it can be omitted from deps.
|
@@ -311,29 +281,22 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
311
281
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
312
282
|
[fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery]);
|
313
283
|
}
|
314
|
-
|
315
284
|
var debugFunctions;
|
316
|
-
|
317
285
|
if (process.env.NODE_ENV !== "production") {
|
318
286
|
debugFunctions = {
|
319
287
|
getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, environment) {
|
320
288
|
var _require5 = require('relay-runtime'),
|
321
|
-
|
322
|
-
|
289
|
+
Record = _require5.Record;
|
323
290
|
var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables.id;
|
324
|
-
|
325
291
|
if (fragmentRefPathInResponse.length !== 1 || fragmentRefPathInResponse[0] !== 'node' || id == null) {
|
326
292
|
return null;
|
327
293
|
}
|
328
|
-
|
329
294
|
var recordSource = environment.getStore().getSource();
|
330
295
|
var record = recordSource.get(id);
|
331
296
|
var typename = record && Record.getType(record);
|
332
|
-
|
333
297
|
if (typename == null) {
|
334
298
|
return null;
|
335
299
|
}
|
336
|
-
|
337
300
|
return {
|
338
301
|
id: id,
|
339
302
|
typename: typename
|
@@ -341,16 +304,13 @@ if (process.env.NODE_ENV !== "production") {
|
|
341
304
|
},
|
342
305
|
checkSameTypeAfterRefetch: function checkSameTypeAfterRefetch(previousIDAndType, environment, fragmentNode, componentDisplayName) {
|
343
306
|
var _require6 = require('relay-runtime'),
|
344
|
-
|
345
|
-
|
307
|
+
Record = _require6.Record;
|
346
308
|
if (!previousIDAndType) {
|
347
309
|
return;
|
348
310
|
}
|
349
|
-
|
350
311
|
var recordSource = environment.getStore().getSource();
|
351
312
|
var record = recordSource.get(previousIDAndType.id);
|
352
313
|
var typename = record && Record.getType(record);
|
353
|
-
|
354
314
|
if (typename !== previousIDAndType.typename) {
|
355
315
|
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;
|
356
316
|
}
|
@@ -359,18 +319,14 @@ if (process.env.NODE_ENV !== "production") {
|
|
359
319
|
if (previousIDAndTypename == null) {
|
360
320
|
return;
|
361
321
|
}
|
362
|
-
|
363
322
|
var _require7 = require('relay-runtime'),
|
364
|
-
|
365
|
-
|
366
|
-
|
323
|
+
ID_KEY = _require7.ID_KEY;
|
324
|
+
// $FlowExpectedError[incompatible-use]
|
367
325
|
var resultID = refetchedFragmentRef[ID_KEY];
|
368
|
-
|
369
326
|
if (resultID != null && resultID !== previousIDAndTypename.id) {
|
370
327
|
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;
|
371
328
|
}
|
372
329
|
}
|
373
330
|
};
|
374
331
|
}
|
375
|
-
|
376
332
|
module.exports = useRefetchableFragmentNode;
|
@@ -4,24 +4,20 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
|
11
|
+
|
12
12
|
'use strict';
|
13
13
|
|
14
|
+
var ReactRelayContext = require('./../ReactRelayContext');
|
14
15
|
var invariant = require('invariant');
|
15
|
-
|
16
16
|
var _require = require('react'),
|
17
|
-
|
18
|
-
|
19
|
-
var ReactRelayContext = require('react-relay/ReactRelayContext');
|
20
|
-
|
17
|
+
useContext = _require.useContext;
|
21
18
|
function useRelayEnvironment() {
|
22
19
|
var context = useContext(ReactRelayContext);
|
23
20
|
!(context != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'useRelayEnvironment: Expected to have found a Relay environment provided by ' + 'a `RelayEnvironmentProvider` component. ' + 'This usually means that useRelayEnvironment was used in a ' + 'component that is not a descendant of a `RelayEnvironmentProvider`. ' + 'Please make sure a `RelayEnvironmentProvider` has been rendered somewhere ' + 'as a parent or ancestor of your component.') : invariant(false) : void 0;
|
24
21
|
return context.environment;
|
25
22
|
}
|
26
|
-
|
27
23
|
module.exports = useRelayEnvironment;
|
@@ -4,27 +4,23 @@
|
|
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
|
-
|
15
|
-
useRef = _require.useRef;
|
12
|
+
'use strict';
|
16
13
|
|
14
|
+
var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
17
15
|
var warning = require("fbjs/lib/warning");
|
18
|
-
|
19
16
|
function useStaticFragmentNodeWarning(fragmentNode, warningContext) {
|
20
17
|
if (process.env.NODE_ENV !== "production") {
|
21
18
|
// This is calling `useRef` conditionally, but based on the environment
|
22
19
|
// __DEV__ setting which shouldn't change. This allows us to only pay the
|
23
20
|
// cost of `useRef` in development mode to produce the warning.
|
24
21
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
25
|
-
var initialPropRef =
|
22
|
+
var initialPropRef = useUnsafeRef_DEPRECATED(fragmentNode.name);
|
26
23
|
process.env.NODE_ENV !== "production" ? warning(initialPropRef.current === fragmentNode.name, 'Relay: The %s has to remain the same over the lifetime of a component. ' + 'Changing it is not supported and will result in unexpected behavior.', warningContext) : void 0;
|
27
24
|
}
|
28
25
|
}
|
29
|
-
|
30
26
|
module.exports = useStaticFragmentNodeWarning;
|
@@ -4,18 +4,18 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
|
11
|
+
|
12
12
|
'use strict';
|
13
13
|
|
14
14
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
15
|
-
|
16
15
|
var _require = require('react'),
|
17
|
-
|
18
|
-
|
16
|
+
useEffect = _require.useEffect,
|
17
|
+
useRef = _require.useRef;
|
18
|
+
|
19
19
|
/**
|
20
20
|
* This hook subscribes a callback to the invalidation state of the given data
|
21
21
|
* ids.
|
@@ -25,8 +25,6 @@ var _require = require('react'),
|
|
25
25
|
* re-established and the previous one will be disposed.
|
26
26
|
* The subscription will automatically be disposed on unmount
|
27
27
|
*/
|
28
|
-
|
29
|
-
|
30
28
|
function useSubscribeToInvalidationState(dataIDs, callback) {
|
31
29
|
var environment = useRelayEnvironment();
|
32
30
|
var disposableRef = useRef(null);
|
@@ -38,7 +36,9 @@ function useSubscribeToInvalidationState(dataIDs, callback) {
|
|
38
36
|
disposableRef.current = disposable;
|
39
37
|
return function () {
|
40
38
|
return disposable.dispose();
|
41
|
-
};
|
39
|
+
};
|
40
|
+
|
41
|
+
// Intentionally excluding dataIDs, since we're using stableDataIDs
|
42
42
|
// instead
|
43
43
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
44
44
|
}, [stableDataIDs, callback, environment]);
|
@@ -50,5 +50,4 @@ function useSubscribeToInvalidationState(dataIDs, callback) {
|
|
50
50
|
}
|
51
51
|
};
|
52
52
|
}
|
53
|
-
|
54
53
|
module.exports = useSubscribeToInvalidationState;
|
@@ -6,18 +6,16 @@
|
|
6
6
|
*
|
7
7
|
*
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
|
-
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
14
|
-
|
15
15
|
var _require = require('react'),
|
16
|
-
|
17
|
-
|
16
|
+
useEffect = _require.useEffect;
|
18
17
|
var _require2 = require('relay-runtime'),
|
19
|
-
|
20
|
-
|
18
|
+
requestSubscription = _require2.requestSubscription;
|
21
19
|
function useSubscription(config, requestSubscriptionFn) {
|
22
20
|
// N.B. this will re-subscribe every render if config or requestSubscriptionFn
|
23
21
|
// are not memoized.
|
@@ -27,11 +25,8 @@ function useSubscription(config, requestSubscriptionFn) {
|
|
27
25
|
useEffect(function () {
|
28
26
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
29
27
|
var _actualRequestSubscri = actualRequestSubscription(environment, config),
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
dispose = _actualRequestSubscri.dispose;
|
33
29
|
return dispose;
|
34
30
|
}, [environment, config, actualRequestSubscription]);
|
35
31
|
}
|
36
|
-
|
37
32
|
module.exports = useSubscription;
|
@@ -0,0 +1,29 @@
|
|
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 _require = require('react'),
|
15
|
+
useMemo = _require.useMemo;
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Like `useRef`, but does not warn when accessed during render. It's a bad
|
19
|
+
* pattern to read or write from a ref during render as it does not trigger
|
20
|
+
* a rerender and might result in bugs.
|
21
|
+
*/
|
22
|
+
function useUnsafeRef_DEPRECATED(init) {
|
23
|
+
return useMemo(function () {
|
24
|
+
return {
|
25
|
+
current: init
|
26
|
+
};
|
27
|
+
}, []);
|
28
|
+
}
|
29
|
+
module.exports = useUnsafeRef_DEPRECATED;
|
@@ -4,13 +4,11 @@
|
|
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
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
@@ -18,9 +16,9 @@ import type {
|
|
18
16
|
IActorEnvironment,
|
19
17
|
} from 'relay-runtime/multi-actor-environment';
|
20
18
|
|
19
|
+
const ReactRelayContext = require('./../ReactRelayContext');
|
21
20
|
const invariant = require('invariant');
|
22
21
|
const {useContext} = require('react');
|
23
|
-
const ReactRelayContext = require('react-relay/ReactRelayContext');
|
24
22
|
|
25
23
|
function useRelayActorEnvironment(
|
26
24
|
actorIdentifier: ActorIdentifier,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-relay",
|
3
3
|
"description": "A framework for building GraphQL-driven React applications.",
|
4
|
-
"version": "
|
4
|
+
"version": "15.0.0",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
"fbjs": "^3.0.2",
|
21
21
|
"invariant": "^2.2.4",
|
22
22
|
"nullthrows": "^1.1.1",
|
23
|
-
"relay-runtime": "
|
23
|
+
"relay-runtime": "15.0.0"
|
24
24
|
},
|
25
25
|
"peerDependencies": {
|
26
26
|
"react": "^16.9.0 || ^17 || ^18"
|