react-relay 14.0.0 → 14.1.0

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