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