react-relay 15.0.0 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayQueryFetcher.js.flow +1 -5
- package/ReactRelayQueryRenderer.js.flow +9 -36
- package/ReactRelayTypes.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +3 -1
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/ReactRelayContainerUtils.js +0 -11
- package/lib/ReactRelayContext.js +0 -11
- package/lib/ReactRelayFragmentContainer.js +6 -78
- package/lib/ReactRelayFragmentMockRenderer.js +0 -11
- package/lib/ReactRelayLocalQueryRenderer.js +0 -17
- package/lib/ReactRelayPaginationContainer.js +5 -208
- package/lib/ReactRelayQueryFetcher.js +2 -51
- package/lib/ReactRelayQueryRenderer.js +6 -94
- package/lib/ReactRelayQueryRendererContext.js +0 -11
- package/lib/ReactRelayRefetchContainer.js +5 -91
- package/lib/ReactRelayTestMocker.js +9 -85
- package/lib/ReactRelayTypes.js +0 -11
- package/lib/RelayContext.js +0 -21
- package/lib/assertFragmentMap.js +0 -15
- package/lib/buildReactRelayContainer.js +0 -19
- package/lib/getRootVariablesForFragments.js +0 -14
- package/lib/hooks.js +0 -15
- package/lib/index.js +0 -17
- package/lib/isRelayEnvironment.js +1 -18
- package/lib/jest-react/enqueueTask.js +0 -20
- package/lib/jest-react/internalAct.js +0 -38
- package/lib/legacy.js +0 -15
- package/lib/multi-actor/ActorChange.js +0 -11
- package/lib/multi-actor/index.js +0 -11
- package/lib/multi-actor/useRelayActorEnvironment.js +0 -11
- package/lib/relay-hooks/EntryPointContainer.react.js +0 -11
- package/lib/relay-hooks/EntryPointTypes.flow.js +1 -14
- package/lib/relay-hooks/FragmentResource.js +76 -132
- package/lib/relay-hooks/HooksImplementation.js +0 -11
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -22
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -18
- package/lib/relay-hooks/MatchContainer.js +0 -94
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -15
- package/lib/relay-hooks/QueryResource.js +2 -68
- package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -11
- package/lib/relay-hooks/SuspenseResource.js +0 -34
- package/lib/relay-hooks/loadEntryPoint.js +1 -24
- package/lib/relay-hooks/loadQuery.js +2 -106
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +2 -27
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -13
- package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +1 -36
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +3 -27
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +34 -99
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +0 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -16
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +1 -23
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -29
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +12 -96
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +0 -14
- package/lib/relay-hooks/useBlockingPaginationFragment.js +0 -42
- package/lib/relay-hooks/useClientQuery.js +0 -18
- package/lib/relay-hooks/useEntryPointLoader.js +0 -69
- package/lib/relay-hooks/useFetchTrackingRef.js +0 -26
- package/lib/relay-hooks/useFragment.js +0 -17
- package/lib/relay-hooks/useFragmentNode.js +2 -32
- package/lib/relay-hooks/useIsMountedRef.js +0 -11
- package/lib/relay-hooks/useIsOperationNodeActive.js +0 -11
- package/lib/relay-hooks/useIsParentQueryActive.js +0 -11
- package/lib/relay-hooks/useLazyLoadQuery.js +0 -18
- package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -35
- package/lib/relay-hooks/useLoadMoreFunction.js +9 -34
- package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -11
- package/lib/relay-hooks/useMemoVariables.js +0 -17
- package/lib/relay-hooks/useMutation.js +0 -11
- package/lib/relay-hooks/usePaginationFragment.js +1 -26
- package/lib/relay-hooks/usePreloadedQuery.js +0 -27
- package/lib/relay-hooks/useQueryLoader.js +0 -74
- package/lib/relay-hooks/useRefetchableFragment.js +0 -16
- package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -97
- package/lib/relay-hooks/useRelayEnvironment.js +0 -11
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -15
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -25
- package/lib/relay-hooks/useSubscription.js +0 -15
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +0 -17
- 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 +5 -0
- package/relay-hooks/EntryPointTypes.flow.js.flow +20 -19
- package/relay-hooks/FragmentResource.js.flow +114 -26
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -2
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +7 -5
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +5 -0
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +5 -0
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +2 -0
- package/relay-hooks/loadEntryPoint.js.flow +4 -2
- package/relay-hooks/loadQuery.js.flow +21 -1
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -2
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +2 -1
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +28 -10
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +3 -9
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +28 -57
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +19 -12
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +15 -31
- package/relay-hooks/useBlockingPaginationFragment.js.flow +2 -4
- package/relay-hooks/useClientQuery.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +15 -9
- package/relay-hooks/useMutation.js.flow +26 -9
- package/relay-hooks/usePaginationFragment.js.flow +2 -8
- package/relay-hooks/useQueryLoader.js.flow +2 -8
- package/relay-hooks/useRefetchableFragment.js.flow +3 -2
- package/relay-hooks/useRefetchableFragmentNode.js.flow +28 -13
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
@@ -36,26 +25,6 @@ function requestIsLiveQuery(preloadableRequest) {
|
|
|
36
25
|
return request.params.metadata.live !== undefined;
|
|
37
26
|
}
|
|
38
27
|
function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
39
|
-
/**
|
|
40
|
-
* We want to always call `queryReference.dispose()` for every call to
|
|
41
|
-
* `setQueryReference(loadQuery(...))` so that no leaks of data in Relay stores
|
|
42
|
-
* will occur.
|
|
43
|
-
*
|
|
44
|
-
* However, a call to `setState(newState)` is not always followed by a commit where
|
|
45
|
-
* this value is reflected in the state. Thus, we cannot reliably clean up each
|
|
46
|
-
* ref with `useEffect(() => () => queryReference.dispose(), [queryReference])`.
|
|
47
|
-
*
|
|
48
|
-
* Instead, we keep track of each call to `loadQuery` in a ref.
|
|
49
|
-
* Relying on the fact that if a state change commits, no state changes that were
|
|
50
|
-
* initiated prior to the currently committing state change will ever subsequently
|
|
51
|
-
* commit, we can safely dispose of all preloaded query references
|
|
52
|
-
* associated with state changes initiated prior to the currently committing state
|
|
53
|
-
* change.
|
|
54
|
-
*
|
|
55
|
-
* Finally, when the hook unmounts, we also dispose of all remaining uncommitted
|
|
56
|
-
* query references.
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
28
|
var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
|
|
60
29
|
var environment = useRelayEnvironment();
|
|
61
30
|
useTrackLoadQueryInRender();
|
|
@@ -72,11 +41,6 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
|
72
41
|
previousInitialQueryReference = _useState2[0],
|
|
73
42
|
setPreviousInitialQueryReference = _useState2[1];
|
|
74
43
|
if (initialQueryReferenceInternal !== previousInitialQueryReference) {
|
|
75
|
-
// Rendering the query reference makes it "managed" by this hook, so
|
|
76
|
-
// we start keeping track of it so we can dispose it when it is no longer
|
|
77
|
-
// necessary here
|
|
78
|
-
// TODO(T78446637): Handle disposal of managed query references in
|
|
79
|
-
// components that were never mounted after rendering
|
|
80
44
|
undisposedQueryReferencesRef.current.add(initialQueryReferenceInternal);
|
|
81
45
|
setPreviousInitialQueryReference(initialQueryReferenceInternal);
|
|
82
46
|
setQueryReference(initialQueryReferenceInternal);
|
|
@@ -103,27 +67,11 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
|
103
67
|
var maybeHiddenOrFastRefresh = useRef(false);
|
|
104
68
|
useEffect(function () {
|
|
105
69
|
return function () {
|
|
106
|
-
// Attempt to detect if the component was
|
|
107
|
-
// hidden (by Offscreen API), or fast refresh occured;
|
|
108
|
-
// Only in these situations would the effect cleanup
|
|
109
|
-
// for "unmounting" run multiple times, so if
|
|
110
|
-
// we are ever able to read this ref with a value
|
|
111
|
-
// of true, it means that one of these cases
|
|
112
|
-
// has happened.
|
|
113
70
|
maybeHiddenOrFastRefresh.current = true;
|
|
114
71
|
};
|
|
115
72
|
}, []);
|
|
116
73
|
useEffect(function () {
|
|
117
74
|
if (maybeHiddenOrFastRefresh.current === true) {
|
|
118
|
-
// This block only runs if the component has previously "unmounted"
|
|
119
|
-
// due to it being hidden by the Offscreen API, or during fast refresh.
|
|
120
|
-
// At this point, the current queryReference will have been disposed
|
|
121
|
-
// by the previous cleanup, so instead of attempting to
|
|
122
|
-
// do our regular commit setup, which would incorrectly leave our
|
|
123
|
-
// current queryReference disposed, we need to load the query again
|
|
124
|
-
// and force a re-render by calling queryLoaderCallback again,
|
|
125
|
-
// so that the queryReference is correctly re-retained, and
|
|
126
|
-
// potentially refetched if necessary.
|
|
127
75
|
maybeHiddenOrFastRefresh.current = false;
|
|
128
76
|
if (queryReference.kind !== 'NullQueryReference') {
|
|
129
77
|
queryLoaderCallback(queryReference.variables, {
|
|
@@ -133,26 +81,6 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
|
133
81
|
}
|
|
134
82
|
return;
|
|
135
83
|
}
|
|
136
|
-
|
|
137
|
-
// When a new queryReference is committed, we iterate over all
|
|
138
|
-
// query references in undisposedQueryReferences and dispose all of
|
|
139
|
-
// the refs that aren't the currently committed one. This ensures
|
|
140
|
-
// that we don't leave any dangling query references for the
|
|
141
|
-
// case that loadQuery is called multiple times before commit; when
|
|
142
|
-
// this happens, multiple state updates will be scheduled, but only one
|
|
143
|
-
// will commit, meaning that we need to keep track of and dispose any
|
|
144
|
-
// query references that don't end up committing.
|
|
145
|
-
// - We are relying on the fact that sets iterate in insertion order, and we
|
|
146
|
-
// can remove items from a set as we iterate over it (i.e. no iterator
|
|
147
|
-
// invalidation issues.) Thus, it is safe to loop through
|
|
148
|
-
// undisposedQueryReferences until we find queryReference, and
|
|
149
|
-
// remove and dispose all previous references.
|
|
150
|
-
// - We are guaranteed to find queryReference in the set, because if a
|
|
151
|
-
// state update results in a commit, no state updates initiated prior to that
|
|
152
|
-
// one will be committed, and we are disposing and removing references
|
|
153
|
-
// associated with updates that were scheduled prior to the currently
|
|
154
|
-
// committing state change. (A useEffect callback is called during the commit
|
|
155
|
-
// phase.)
|
|
156
84
|
var undisposedQueryReferences = undisposedQueryReferencesRef.current;
|
|
157
85
|
if (isMountedRef.current) {
|
|
158
86
|
var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferences),
|
|
@@ -181,8 +109,6 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
|
|
|
181
109
|
}, [queryReference, isMountedRef, queryLoaderCallback, preloadableRequest]);
|
|
182
110
|
useEffect(function () {
|
|
183
111
|
return function disposeAllRemainingQueryReferences() {
|
|
184
|
-
// undisposedQueryReferences.current is never reassigned
|
|
185
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
186
112
|
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferencesRef.current),
|
|
187
113
|
_step2;
|
|
188
114
|
try {
|
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var HooksImplementation = require('./HooksImplementation');
|
|
@@ -25,15 +14,11 @@ function useRefetchableFragment_LEGACY(fragmentInput, fragmentRef) {
|
|
|
25
14
|
fragmentData = _useRefetchableFragme.fragmentData,
|
|
26
15
|
refetch = _useRefetchableFragme.refetch;
|
|
27
16
|
if (process.env.NODE_ENV !== "production") {
|
|
28
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
29
17
|
useDebugValue({
|
|
30
18
|
fragment: fragmentNode.name,
|
|
31
19
|
data: fragmentData
|
|
32
20
|
});
|
|
33
21
|
}
|
|
34
|
-
|
|
35
|
-
// $FlowFixMe[incompatible-return]
|
|
36
|
-
// $FlowFixMe[prop-missing]
|
|
37
22
|
return [fragmentData, refetch];
|
|
38
23
|
}
|
|
39
24
|
function useRefetchableFragment(fragmentInput, parentFragmentRef) {
|
|
@@ -41,7 +26,6 @@ function useRefetchableFragment(fragmentInput, parentFragmentRef) {
|
|
|
41
26
|
if (impl) {
|
|
42
27
|
return impl.useRefetchableFragment(fragmentInput, parentFragmentRef);
|
|
43
28
|
} else {
|
|
44
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
45
29
|
return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
|
|
46
30
|
}
|
|
47
31
|
}
|
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
@@ -71,8 +60,7 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
|
71
60
|
var parentEnvironment = useRelayEnvironment();
|
|
72
61
|
var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
|
|
73
62
|
refetchableRequest = _getRefetchMetadata.refetchableRequest,
|
|
74
|
-
fragmentRefPathInResponse = _getRefetchMetadata.fragmentRefPathInResponse
|
|
75
|
-
identifierField = _getRefetchMetadata.identifierField;
|
|
63
|
+
fragmentRefPathInResponse = _getRefetchMetadata.fragmentRefPathInResponse;
|
|
76
64
|
var fragmentIdentifier = getFragmentIdentifier(fragmentNode, parentFragmentRef);
|
|
77
65
|
var _useReducer = useReducer(reducer, {
|
|
78
66
|
fetchPolicy: undefined,
|
|
@@ -102,6 +90,8 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
|
102
90
|
loadQuery = _useQueryLoader[1],
|
|
103
91
|
disposeQuery = _useQueryLoader[2];
|
|
104
92
|
var fragmentRef = parentFragmentRef;
|
|
93
|
+
var _getRefetchMetadata2 = getRefetchMetadata(fragmentNode, componentDisplayName),
|
|
94
|
+
identifierInfo = _getRefetchMetadata2.identifierInfo;
|
|
105
95
|
if (shouldReset) {
|
|
106
96
|
dispatch({
|
|
107
97
|
type: 'reset',
|
|
@@ -110,47 +100,18 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
|
110
100
|
});
|
|
111
101
|
disposeQuery();
|
|
112
102
|
} else if (refetchQuery != null && queryRef != null) {
|
|
113
|
-
// If refetch was called, we expect to have a refetchQuery and queryRef
|
|
114
|
-
// in state, since both state updates to set the refetchQuery and the
|
|
115
|
-
// queryRef occur simultaneously.
|
|
116
|
-
// In this case, we need to read the refetched query data (potentially
|
|
117
|
-
// suspending if it's in flight), and extract the new fragment ref
|
|
118
|
-
// from the query in order read the current @refetchable fragment
|
|
119
|
-
// with the updated fragment owner as the new refetchQuery.
|
|
120
|
-
|
|
121
|
-
// Before observing the refetch, record the current ID and typename
|
|
122
|
-
// so that, if we are refetching existing data on
|
|
123
|
-
// a field that implements Node, after refetching we
|
|
124
|
-
// can validate that the received data is consistent
|
|
125
103
|
var debugPreviousIDAndTypename;
|
|
126
104
|
if (process.env.NODE_ENV !== "production") {
|
|
127
|
-
debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(refetchQuery.request.variables, fragmentRefPathInResponse, environment);
|
|
105
|
+
debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(refetchQuery.request.variables, fragmentRefPathInResponse, identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierQueryVariableName, environment);
|
|
128
106
|
}
|
|
129
107
|
var handleQueryCompleted = function handleQueryCompleted(maybeError) {
|
|
130
108
|
onComplete && onComplete(maybeError !== null && maybeError !== void 0 ? maybeError : null);
|
|
131
109
|
};
|
|
132
|
-
|
|
133
|
-
// The queryRef.source obtained from useQueryLoader will be
|
|
134
|
-
// an observable we can consume /if/ a network request was
|
|
135
|
-
// started. Otherwise, given that QueryResource.prepare
|
|
136
|
-
// always expects an observable we fall back to a new network
|
|
137
|
-
// observable. Note however that if loadQuery did not make a network
|
|
138
|
-
// request, we don't expect to make one here, unless the state of
|
|
139
|
-
// the cache has changed between the call to refetch and this
|
|
140
|
-
// render.
|
|
141
110
|
var fetchObservable = queryRef.source != null ? queryRef.source : fetchQuery(environment, refetchQuery);
|
|
142
|
-
|
|
143
|
-
// Now wwe can we read the refetch query here using the
|
|
144
|
-
// queryRef provided from useQueryLoader. Note that the
|
|
145
|
-
// network request is started during the call to refetch,
|
|
146
|
-
// but if the refetch query is still in flight, we will suspend
|
|
147
|
-
// at this point:
|
|
148
111
|
var queryResult = profilerContext.wrapPrepareQueryResource(function () {
|
|
149
112
|
return QueryResource.prepare(refetchQuery, fetchObservable, fetchPolicy, renderPolicy, {
|
|
150
113
|
error: handleQueryCompleted,
|
|
151
114
|
complete: function complete() {
|
|
152
|
-
// Validate that the type of the object we got back matches the type
|
|
153
|
-
// of the object already in the store
|
|
154
115
|
if (process.env.NODE_ENV !== "production") {
|
|
155
116
|
debugFunctions.checkSameTypeAfterRefetch(debugPreviousIDAndTypename, environment, fragmentNode, componentDisplayName);
|
|
156
117
|
}
|
|
@@ -160,31 +121,17 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
|
160
121
|
});
|
|
161
122
|
var queryData = FragmentResource.read(queryResult.fragmentNode, queryResult.fragmentRef, componentDisplayName).data;
|
|
162
123
|
!(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
|
|
165
|
-
// refetch query response the new fragment ref we need to use to read
|
|
166
|
-
// the fragment. The new fragment ref will point to the refetch query
|
|
167
|
-
// as its fragment owner.
|
|
168
124
|
var refetchedFragmentRef = getValueAtPath(queryData, fragmentRefPathInResponse);
|
|
169
125
|
fragmentRef = refetchedFragmentRef;
|
|
170
126
|
if (process.env.NODE_ENV !== "production") {
|
|
171
|
-
// Validate that the id of the object we got back matches the id
|
|
172
|
-
// we queried for in the variables.
|
|
173
|
-
// We do this during render instead of onComplete to make sure we are
|
|
174
|
-
// only validating the most recent refetch.
|
|
175
127
|
debugFunctions.checkSameIDAfterRefetch(debugPreviousIDAndTypename, fragmentRef, fragmentNode, componentDisplayName);
|
|
176
128
|
}
|
|
177
129
|
}
|
|
178
|
-
|
|
179
|
-
// We read and subscribe to the fragment using useFragmentNode.
|
|
180
|
-
// If refetch was called, we read the fragment using the new computed
|
|
181
|
-
// fragment ref from the refetch query response; otherwise, we use the
|
|
182
|
-
// fragment ref passed by the caller as normal.
|
|
183
130
|
var _useFragmentNode = useFragmentNode(fragmentNode, fragmentRef, componentDisplayName),
|
|
184
131
|
fragmentData = _useFragmentNode.data,
|
|
185
132
|
disableStoreUpdates = _useFragmentNode.disableStoreUpdates,
|
|
186
133
|
enableStoreUpdates = _useFragmentNode.enableStoreUpdates;
|
|
187
|
-
var refetch = useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse,
|
|
134
|
+
var refetch = useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierInfo, loadQuery, parentFragmentRef, refetchableRequest);
|
|
188
135
|
return {
|
|
189
136
|
fragmentData: fragmentData,
|
|
190
137
|
fragmentRef: fragmentRef,
|
|
@@ -193,12 +140,10 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
|
|
|
193
140
|
enableStoreUpdates: enableStoreUpdates
|
|
194
141
|
};
|
|
195
142
|
}
|
|
196
|
-
function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse,
|
|
143
|
+
function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierInfo, loadQuery, parentFragmentRef, refetchableRequest) {
|
|
197
144
|
var isMountedRef = useIsMountedRef();
|
|
198
|
-
var identifierValue = identifierField != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierField] : null;
|
|
145
|
+
var identifierValue = (identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierField) != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierInfo.identifierField] : null;
|
|
199
146
|
return useCallback(function (providedRefetchVariables, options) {
|
|
200
|
-
// Bail out and warn if we're trying to refetch after the component
|
|
201
|
-
// has unmounted
|
|
202
147
|
if (isMountedRef.current !== true) {
|
|
203
148
|
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected call to `refetch` on unmounted component for fragment ' + '`%s` in `%s`. It looks like some instances of your component are ' + 'still trying to fetch data but they already unmounted. ' + 'Please make sure you clear all timers, intervals, ' + 'async calls, etc that may trigger a fetch.', fragmentNode.name, componentDisplayName) : void 0;
|
|
204
149
|
return {
|
|
@@ -226,35 +171,16 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
|
226
171
|
parentVariables = fragmentSelector.owner.variables;
|
|
227
172
|
fragmentVariables = fragmentSelector.variables;
|
|
228
173
|
}
|
|
229
|
-
|
|
230
|
-
// A user of `useRefetchableFragment()` may pass a subset of
|
|
231
|
-
// all variables required by the fragment when calling `refetch()`.
|
|
232
|
-
// We fill in any variables not passed by the call to `refetch()` with the
|
|
233
|
-
// variables from the original parent fragment owner.
|
|
234
174
|
var refetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables), providedRefetchVariables);
|
|
235
|
-
|
|
236
|
-
// If the query needs an identifier value ('id' or similar) and one
|
|
237
|
-
// was not explicitly provided, read it from the fragment data.
|
|
238
|
-
if (identifierField != null && !providedRefetchVariables.hasOwnProperty('id')) {
|
|
239
|
-
// @refetchable fragments are guaranteed to have an `id` selection
|
|
240
|
-
// if the type is Node, implements Node, or is @fetchable. Double-check
|
|
241
|
-
// that there actually is a value at runtime.
|
|
175
|
+
if (identifierInfo != null && !providedRefetchVariables.hasOwnProperty(identifierInfo.identifierQueryVariableName)) {
|
|
242
176
|
if (typeof identifierValue !== 'string') {
|
|
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;
|
|
177
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected result to have a string ' + '`%s` in order to refetch, got `%s`.', identifierInfo.identifierField, identifierValue) : void 0;
|
|
244
178
|
}
|
|
245
|
-
refetchVariables.
|
|
179
|
+
refetchVariables[identifierInfo.identifierQueryVariableName] = identifierValue;
|
|
246
180
|
}
|
|
247
181
|
var refetchQuery = createOperationDescriptor(refetchableRequest, refetchVariables, {
|
|
248
182
|
force: true
|
|
249
183
|
});
|
|
250
|
-
|
|
251
|
-
// We call loadQuery which will start a network request if necessary
|
|
252
|
-
// and update the querRef from useQueryLoader.
|
|
253
|
-
// Note the following:
|
|
254
|
-
// - loadQuery will dispose of any previously refetched queries.
|
|
255
|
-
// - We use the variables extracted off the OperationDescriptor
|
|
256
|
-
// so that they have been filtered out to include only the
|
|
257
|
-
// variables actually declared in the query.
|
|
258
184
|
loadQuery(refetchQuery.request.variables, {
|
|
259
185
|
fetchPolicy: fetchPolicy,
|
|
260
186
|
__environment: refetchEnvironment,
|
|
@@ -271,29 +197,21 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
|
|
|
271
197
|
return {
|
|
272
198
|
dispose: disposeQuery
|
|
273
199
|
};
|
|
274
|
-
},
|
|
275
|
-
// NOTE: We disable react-hooks-deps warning because:
|
|
276
|
-
// - We know fragmentRefPathInResponse is static, so it can be omitted from
|
|
277
|
-
// deps
|
|
278
|
-
// - We know fragmentNode is static, so it can be omitted from deps.
|
|
279
|
-
// - fragmentNode and parentFragmentRef are also captured by including
|
|
280
|
-
// fragmentIdentifier
|
|
281
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
282
|
-
[fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery]);
|
|
200
|
+
}, [fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery]);
|
|
283
201
|
}
|
|
284
202
|
var debugFunctions;
|
|
285
203
|
if (process.env.NODE_ENV !== "production") {
|
|
286
204
|
debugFunctions = {
|
|
287
|
-
getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, environment) {
|
|
205
|
+
getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, identifierQueryVariableName, environment) {
|
|
288
206
|
var _require5 = require('relay-runtime'),
|
|
289
207
|
Record = _require5.Record;
|
|
290
|
-
var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables
|
|
208
|
+
var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables[identifierQueryVariableName !== null && identifierQueryVariableName !== void 0 ? identifierQueryVariableName : 'id'];
|
|
291
209
|
if (fragmentRefPathInResponse.length !== 1 || fragmentRefPathInResponse[0] !== 'node' || id == null) {
|
|
292
210
|
return null;
|
|
293
211
|
}
|
|
294
212
|
var recordSource = environment.getStore().getSource();
|
|
295
213
|
var record = recordSource.get(id);
|
|
296
|
-
var typename = record
|
|
214
|
+
var typename = record == null ? null : Record.getType(record);
|
|
297
215
|
if (typename == null) {
|
|
298
216
|
return null;
|
|
299
217
|
}
|
|
@@ -321,7 +239,6 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
321
239
|
}
|
|
322
240
|
var _require7 = require('relay-runtime'),
|
|
323
241
|
ID_KEY = _require7.ID_KEY;
|
|
324
|
-
// $FlowExpectedError[incompatible-use]
|
|
325
242
|
var resultID = refetchedFragmentRef[ID_KEY];
|
|
326
243
|
if (resultID != null && resultID !== previousIDAndTypename.id) {
|
|
327
244
|
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;
|
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var ReactRelayContext = require('./../ReactRelayContext');
|
|
@@ -1,24 +1,9 @@
|
|
|
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
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
|
15
4
|
var warning = require("fbjs/lib/warning");
|
|
16
5
|
function useStaticFragmentNodeWarning(fragmentNode, warningContext) {
|
|
17
6
|
if (process.env.NODE_ENV !== "production") {
|
|
18
|
-
// This is calling `useRef` conditionally, but based on the environment
|
|
19
|
-
// __DEV__ setting which shouldn't change. This allows us to only pay the
|
|
20
|
-
// cost of `useRef` in development mode to produce the warning.
|
|
21
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
22
7
|
var initialPropRef = useUnsafeRef_DEPRECATED(fragmentNode.name);
|
|
23
8
|
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;
|
|
24
9
|
}
|
|
@@ -1,30 +1,9 @@
|
|
|
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
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
|
15
4
|
var _require = require('react'),
|
|
16
5
|
useEffect = _require.useEffect,
|
|
17
6
|
useRef = _require.useRef;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* This hook subscribes a callback to the invalidation state of the given data
|
|
21
|
-
* ids.
|
|
22
|
-
* Any time the invalidation state of the given data ids changes, the provided
|
|
23
|
-
* callback will be called.
|
|
24
|
-
* If new ids or a new callback are provided, the subscription will be
|
|
25
|
-
* re-established and the previous one will be disposed.
|
|
26
|
-
* The subscription will automatically be disposed on unmount
|
|
27
|
-
*/
|
|
28
7
|
function useSubscribeToInvalidationState(dataIDs, callback) {
|
|
29
8
|
var environment = useRelayEnvironment();
|
|
30
9
|
var disposableRef = useRef(null);
|
|
@@ -37,10 +16,6 @@ function useSubscribeToInvalidationState(dataIDs, callback) {
|
|
|
37
16
|
return function () {
|
|
38
17
|
return disposable.dispose();
|
|
39
18
|
};
|
|
40
|
-
|
|
41
|
-
// Intentionally excluding dataIDs, since we're using stableDataIDs
|
|
42
|
-
// instead
|
|
43
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
19
|
}, [stableDataIDs, callback, environment]);
|
|
45
20
|
return {
|
|
46
21
|
dispose: function dispose() {
|
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
|
@@ -17,13 +6,9 @@ var _require = require('react'),
|
|
|
17
6
|
var _require2 = require('relay-runtime'),
|
|
18
7
|
requestSubscription = _require2.requestSubscription;
|
|
19
8
|
function useSubscription(config, requestSubscriptionFn) {
|
|
20
|
-
// N.B. this will re-subscribe every render if config or requestSubscriptionFn
|
|
21
|
-
// are not memoized.
|
|
22
|
-
// Please do not pass an object defined in-line.
|
|
23
9
|
var actualRequestSubscription = requestSubscriptionFn !== null && requestSubscriptionFn !== void 0 ? requestSubscriptionFn : requestSubscription;
|
|
24
10
|
var environment = useRelayEnvironment();
|
|
25
11
|
useEffect(function () {
|
|
26
|
-
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
27
12
|
var _actualRequestSubscri = actualRequestSubscription(environment, config),
|
|
28
13
|
dispose = _actualRequestSubscri.dispose;
|
|
29
14
|
return dispose;
|
|
@@ -1,24 +1,7 @@
|
|
|
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
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var _require = require('react'),
|
|
15
4
|
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
5
|
function useUnsafeRef_DEPRECATED(init) {
|
|
23
6
|
return useMemo(function () {
|
|
24
7
|
return {
|
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": "16.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": "16.0.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "^16.9.0 || ^17 || ^18"
|