react-relay 14.1.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -0
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -0
  4. package/ReactRelayFragmentContainer.js.flow +6 -2
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -0
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -3
  7. package/ReactRelayPaginationContainer.js.flow +21 -12
  8. package/ReactRelayQueryFetcher.js.flow +20 -10
  9. package/ReactRelayQueryRenderer.js.flow +15 -11
  10. package/ReactRelayQueryRendererContext.js.flow +1 -0
  11. package/ReactRelayRefetchContainer.js.flow +9 -5
  12. package/ReactRelayTestMocker.js.flow +3 -1
  13. package/ReactRelayTypes.js.flow +2 -0
  14. package/RelayContext.js.flow +1 -0
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
  18. package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -0
  34. package/buildReactRelayContainer.js.flow +10 -6
  35. package/getRootVariablesForFragments.js.flow +1 -1
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -0
  38. package/index.js +1 -1
  39. package/index.js.flow +4 -0
  40. package/isRelayEnvironment.js.flow +1 -0
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -0
  46. package/lib/ReactRelayContainerUtils.js +0 -11
  47. package/lib/ReactRelayContext.js +1 -12
  48. package/lib/ReactRelayFragmentContainer.js +23 -122
  49. package/lib/ReactRelayFragmentMockRenderer.js +0 -12
  50. package/lib/ReactRelayLocalQueryRenderer.js +12 -41
  51. package/lib/ReactRelayPaginationContainer.js +45 -341
  52. package/lib/ReactRelayQueryFetcher.js +36 -111
  53. package/lib/ReactRelayQueryRenderer.js +29 -137
  54. package/lib/ReactRelayQueryRendererContext.js +0 -10
  55. package/lib/ReactRelayRefetchContainer.js +33 -166
  56. package/lib/ReactRelayTestMocker.js +18 -128
  57. package/lib/ReactRelayTypes.js +0 -9
  58. package/lib/RelayContext.js +0 -23
  59. package/lib/assertFragmentMap.js +0 -16
  60. package/lib/buildReactRelayContainer.js +7 -41
  61. package/lib/getRootVariablesForFragments.js +2 -19
  62. package/lib/hooks.js +3 -30
  63. package/lib/index.js +3 -39
  64. package/lib/isRelayEnvironment.js +1 -16
  65. package/lib/jest-react/enqueueTask.js +1 -25
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +2 -51
  68. package/lib/legacy.js +0 -20
  69. package/lib/multi-actor/ActorChange.js +0 -14
  70. package/lib/multi-actor/index.js +0 -10
  71. package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
  72. package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
  74. package/lib/relay-hooks/FragmentResource.js +130 -280
  75. package/lib/relay-hooks/HooksImplementation.js +0 -14
  76. package/lib/relay-hooks/InternalLogger.js +0 -11
  77. package/lib/relay-hooks/LRUCache.js +0 -39
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
  79. package/lib/relay-hooks/MatchContainer.js +9 -111
  80. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  81. package/lib/relay-hooks/ProfilerContext.js +0 -14
  82. package/lib/relay-hooks/QueryResource.js +14 -149
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
  84. package/lib/relay-hooks/SuspenseResource.js +2 -59
  85. package/lib/relay-hooks/loadEntryPoint.js +10 -45
  86. package/lib/relay-hooks/loadQuery.js +29 -169
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
  89. package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
  90. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
  91. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
  92. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
  93. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
  94. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
  95. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
  96. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
  97. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
  98. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
  99. package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
  100. package/lib/relay-hooks/useClientQuery.js +0 -21
  101. package/lib/relay-hooks/useEntryPointLoader.js +12 -100
  102. package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
  103. package/lib/relay-hooks/useFragment.js +5 -32
  104. package/lib/relay-hooks/useFragmentNode.js +14 -55
  105. package/lib/relay-hooks/useIsMountedRef.js +2 -14
  106. package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
  107. package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
  108. package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
  109. package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
  110. package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
  111. package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
  112. package/lib/relay-hooks/useMemoVariables.js +8 -43
  113. package/lib/relay-hooks/useMutation.js +6 -34
  114. package/lib/relay-hooks/usePaginationFragment.js +49 -89
  115. package/lib/relay-hooks/usePreloadedQuery.js +10 -54
  116. package/lib/relay-hooks/useQueryLoader.js +18 -116
  117. package/lib/relay-hooks/useRefetchableFragment.js +4 -30
  118. package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
  119. package/lib/relay-hooks/useRelayEnvironment.js +2 -16
  120. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
  121. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
  122. package/lib/relay-hooks/useSubscription.js +3 -22
  123. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
  124. package/multi-actor/ActorChange.js.flow +1 -1
  125. package/multi-actor/index.js.flow +1 -1
  126. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  127. package/package.json +2 -2
  128. package/react-relay-hooks.js +2 -2
  129. package/react-relay-hooks.min.js +2 -2
  130. package/react-relay-legacy.js +2 -2
  131. package/react-relay-legacy.min.js +2 -2
  132. package/react-relay.js +2 -2
  133. package/react-relay.min.js +2 -2
  134. package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
  135. package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
  136. package/relay-hooks/FragmentResource.js.flow +148 -34
  137. package/relay-hooks/HooksImplementation.js.flow +1 -1
  138. package/relay-hooks/InternalLogger.js.flow +1 -1
  139. package/relay-hooks/LRUCache.js.flow +1 -1
  140. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
  141. package/relay-hooks/MatchContainer.js.flow +1 -1
  142. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  143. package/relay-hooks/ProfilerContext.js.flow +1 -1
  144. package/relay-hooks/QueryResource.js.flow +25 -5
  145. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  146. package/relay-hooks/SuspenseResource.js.flow +1 -1
  147. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
  149. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  150. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  151. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
  152. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  153. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
  154. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
  155. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  156. package/relay-hooks/loadEntryPoint.js.flow +15 -8
  157. package/relay-hooks/loadQuery.js.flow +32 -8
  158. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  159. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
  160. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  161. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
  163. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
  164. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
  165. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  166. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
  167. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  168. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
  169. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
  170. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
  171. package/relay-hooks/useClientQuery.js.flow +3 -3
  172. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  173. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  174. package/relay-hooks/useFragment.js.flow +2 -2
  175. package/relay-hooks/useFragmentNode.js.flow +7 -6
  176. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  177. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  178. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  179. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  180. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  181. package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
  182. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  183. package/relay-hooks/useMemoVariables.js.flow +13 -29
  184. package/relay-hooks/useMutation.js.flow +30 -13
  185. package/relay-hooks/usePaginationFragment.js.flow +55 -54
  186. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  187. package/relay-hooks/useQueryLoader.js.flow +78 -21
  188. package/relay-hooks/useRefetchableFragment.js.flow +65 -33
  189. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
  190. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  191. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  192. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  193. package/relay-hooks/useSubscription.js.flow +1 -1
  194. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  195. package/lib/readContext.js +0 -27
  196. package/readContext.js.flow +0 -29
@@ -1,57 +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
1
  'use strict';
12
2
 
13
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
5
  var ProfilerContext = require('../ProfilerContext');
18
-
19
6
  var _require = require('../QueryResource'),
20
- getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
21
-
7
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
22
8
  var useIsMountedRef = require('../useIsMountedRef');
23
-
24
9
  var useQueryLoader = require('../useQueryLoader');
25
-
26
10
  var useRelayEnvironment = require('../useRelayEnvironment');
27
-
28
11
  var readFragmentInternal = require('./readFragmentInternal_REACT_CACHE');
29
-
30
12
  var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
31
-
32
13
  var invariant = require('invariant');
33
-
34
14
  var _require2 = require('react'),
35
- useCallback = _require2.useCallback,
36
- useContext = _require2.useContext,
37
- useReducer = _require2.useReducer;
38
-
15
+ useCallback = _require2.useCallback,
16
+ useContext = _require2.useContext,
17
+ useReducer = _require2.useReducer;
39
18
  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
-
19
+ fetchQuery = _require3.__internal.fetchQuery,
20
+ createOperationDescriptor = _require3.createOperationDescriptor,
21
+ getFragmentIdentifier = _require3.getFragmentIdentifier,
22
+ getRefetchMetadata = _require3.getRefetchMetadata,
23
+ getSelector = _require3.getSelector,
24
+ getValueAtPath = _require3.getValueAtPath;
47
25
  var warning = require("fbjs/lib/warning");
48
-
49
26
  function reducer(state, action) {
50
27
  switch (action.type) {
51
28
  case 'refetch':
52
29
  {
53
30
  var _action$refetchEnviro;
54
-
55
31
  return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
56
32
  fetchPolicy: action.fetchPolicy,
57
33
  mirroredEnvironment: (_action$refetchEnviro = action.refetchEnvironment) !== null && _action$refetchEnviro !== void 0 ? _action$refetchEnviro : state.mirroredEnvironment,
@@ -61,7 +37,6 @@ function reducer(state, action) {
61
37
  renderPolicy: action.renderPolicy
62
38
  });
63
39
  }
64
-
65
40
  case 'reset':
66
41
  {
67
42
  return {
@@ -73,7 +48,6 @@ function reducer(state, action) {
73
48
  renderPolicy: undefined
74
49
  };
75
50
  }
76
-
77
51
  default:
78
52
  {
79
53
  action.type;
@@ -81,48 +55,40 @@ function reducer(state, action) {
81
55
  }
82
56
  }
83
57
  }
84
-
85
58
  function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName) {
86
59
  var parentEnvironment = useRelayEnvironment();
87
-
88
60
  var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
89
- refetchableRequest = _getRefetchMetadata.refetchableRequest,
90
- fragmentRefPathInResponse = _getRefetchMetadata.fragmentRefPathInResponse,
91
- identifierField = _getRefetchMetadata.identifierField;
92
-
61
+ refetchableRequest = _getRefetchMetadata.refetchableRequest,
62
+ fragmentRefPathInResponse = _getRefetchMetadata.fragmentRefPathInResponse,
63
+ identifierInfo = _getRefetchMetadata.identifierInfo;
93
64
  var fragmentIdentifier = getFragmentIdentifier(fragmentNode, parentFragmentRef);
94
-
95
65
  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
-
66
+ fetchPolicy: undefined,
67
+ mirroredEnvironment: parentEnvironment,
68
+ mirroredFragmentIdentifier: fragmentIdentifier,
69
+ onComplete: undefined,
70
+ refetchEnvironment: null,
71
+ refetchQuery: null,
72
+ renderPolicy: undefined
73
+ }),
74
+ refetchState = _useReducer[0],
75
+ dispatch = _useReducer[1];
107
76
  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;
77
+ mirroredEnvironment = refetchState.mirroredEnvironment,
78
+ mirroredFragmentIdentifier = refetchState.mirroredFragmentIdentifier,
79
+ onComplete = refetchState.onComplete,
80
+ refetchEnvironment = refetchState.refetchEnvironment,
81
+ refetchQuery = refetchState.refetchQuery,
82
+ renderPolicy = refetchState.renderPolicy;
114
83
  var environment = refetchEnvironment !== null && refetchEnvironment !== void 0 ? refetchEnvironment : parentEnvironment;
115
84
  var QueryResource = getQueryResourceForEnvironment(environment);
116
85
  var profilerContext = useContext(ProfilerContext);
117
86
  var shouldReset = environment !== mirroredEnvironment || fragmentIdentifier !== mirroredFragmentIdentifier;
118
-
119
87
  var _useQueryLoader = useQueryLoader(refetchableRequest),
120
- queryRef = _useQueryLoader[0],
121
- loadQuery = _useQueryLoader[1],
122
- disposeQuery = _useQueryLoader[2];
123
-
88
+ queryRef = _useQueryLoader[0],
89
+ loadQuery = _useQueryLoader[1],
90
+ disposeQuery = _useQueryLoader[2];
124
91
  var fragmentRef = parentFragmentRef;
125
-
126
92
  if (shouldReset) {
127
93
  dispatch({
128
94
  type: 'reset',
@@ -131,103 +97,54 @@ function useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDi
131
97
  });
132
98
  disposeQuery();
133
99
  } 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
100
  var debugPreviousIDAndTypename;
146
-
147
101
  if (process.env.NODE_ENV !== "production") {
148
- debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(refetchQuery.request.variables, fragmentRefPathInResponse, environment);
102
+ debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(refetchQuery.request.variables, fragmentRefPathInResponse, identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierQueryVariableName, environment);
149
103
  }
150
-
151
104
  var handleQueryCompleted = function handleQueryCompleted(maybeError) {
152
105
  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
-
106
+ };
107
+ var fetchObservable = queryRef.source != null ? queryRef.source : fetchQuery(environment, refetchQuery);
169
108
  var queryResult = profilerContext.wrapPrepareQueryResource(function () {
170
109
  return QueryResource.prepare(refetchQuery, fetchObservable, fetchPolicy, renderPolicy, {
171
110
  error: handleQueryCompleted,
172
111
  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
112
  if (process.env.NODE_ENV !== "production") {
176
113
  debugFunctions.checkSameTypeAfterRefetch(debugPreviousIDAndTypename, environment, fragmentNode, componentDisplayName);
177
114
  }
178
-
179
115
  handleQueryCompleted();
180
116
  }
181
117
  }, queryRef.fetchKey, profilerContext);
182
118
  });
183
119
  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
-
120
+ !(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;
189
121
  var refetchedFragmentRef = getValueAtPath(queryData, fragmentRefPathInResponse);
190
122
  fragmentRef = refetchedFragmentRef;
191
-
192
123
  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
124
  debugFunctions.checkSameIDAfterRefetch(debugPreviousIDAndTypename, fragmentRef, fragmentNode, componentDisplayName);
198
125
  }
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
-
126
+ }
205
127
  var fragmentData = useFragmentInternal(fragmentNode, fragmentRef, componentDisplayName);
206
- var refetch = useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierField, loadQuery, parentFragmentRef, refetchableRequest);
128
+ var refetch = useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierInfo, loadQuery, parentFragmentRef, refetchableRequest);
207
129
  return {
208
130
  fragmentData: fragmentData,
209
131
  fragmentRef: fragmentRef,
210
132
  refetch: refetch
211
133
  };
212
134
  }
213
-
214
- function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierField, loadQuery, parentFragmentRef, refetchableRequest) {
135
+ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragmentData, fragmentIdentifier, fragmentNode, fragmentRefPathInResponse, identifierInfo, loadQuery, parentFragmentRef, refetchableRequest) {
215
136
  var isMountedRef = useIsMountedRef();
216
- var identifierValue = identifierField != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierField] : null;
137
+ var identifierValue = (identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierField) != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierInfo.identifierField] : null;
217
138
  return useCallback(function (providedRefetchVariables, options) {
218
- // Bail out and warn if we're trying to refetch after the component
219
- // has unmounted
220
139
  if (isMountedRef.current !== true) {
221
140
  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
141
  return {
223
142
  dispose: function dispose() {}
224
143
  };
225
144
  }
226
-
227
145
  if (parentFragmentRef == null) {
228
146
  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
147
  }
230
-
231
148
  var refetchEnvironment = options === null || options === void 0 ? void 0 : options.__environment;
232
149
  var fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy;
233
150
  var renderPolicy = options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy;
@@ -235,48 +152,27 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
235
152
  var fragmentSelector = getSelector(fragmentNode, parentFragmentRef);
236
153
  var parentVariables;
237
154
  var fragmentVariables;
238
-
239
155
  if (fragmentSelector == null) {
240
156
  parentVariables = {};
241
157
  fragmentVariables = {};
242
158
  } else if (fragmentSelector.kind === 'PluralReaderSelector') {
243
159
  var _fragmentSelector$sel, _fragmentSelector$sel2, _fragmentSelector$sel3, _fragmentSelector$sel4;
244
-
245
160
  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
161
  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
162
  } else {
248
163
  parentVariables = fragmentSelector.owner.variables;
249
164
  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.
165
+ }
166
+ var refetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables), providedRefetchVariables);
167
+ if (identifierInfo != null && !providedRefetchVariables.hasOwnProperty(identifierInfo.identifierQueryVariableName)) {
263
168
  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;
169
+ 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;
265
170
  }
266
-
267
- refetchVariables.id = identifierValue;
171
+ refetchVariables[identifierInfo.identifierQueryVariableName] = identifierValue;
268
172
  }
269
-
270
173
  var refetchQuery = createOperationDescriptor(refetchableRequest, refetchVariables, {
271
174
  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
-
175
+ });
280
176
  loadQuery(refetchQuery.request.variables, {
281
177
  fetchPolicy: fetchPolicy,
282
178
  __environment: refetchEnvironment,
@@ -293,38 +189,24 @@ function useRefetchFunction(componentDisplayName, dispatch, disposeQuery, fragme
293
189
  return {
294
190
  dispose: disposeQuery
295
191
  };
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]);
192
+ }, [fragmentIdentifier, dispatch, disposeQuery, identifierValue, loadQuery]);
304
193
  }
305
-
306
194
  var debugFunctions;
307
-
308
195
  if (process.env.NODE_ENV !== "production") {
309
196
  debugFunctions = {
310
- getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, environment) {
197
+ getInitialIDAndType: function getInitialIDAndType(memoRefetchVariables, fragmentRefPathInResponse, identifierQueryVariableName, environment) {
311
198
  var _require4 = require('relay-runtime'),
312
- Record = _require4.Record;
313
-
314
- var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables.id;
315
-
199
+ Record = _require4.Record;
200
+ var id = memoRefetchVariables === null || memoRefetchVariables === void 0 ? void 0 : memoRefetchVariables[identifierQueryVariableName !== null && identifierQueryVariableName !== void 0 ? identifierQueryVariableName : 'id'];
316
201
  if (fragmentRefPathInResponse.length !== 1 || fragmentRefPathInResponse[0] !== 'node' || id == null) {
317
202
  return null;
318
203
  }
319
-
320
204
  var recordSource = environment.getStore().getSource();
321
205
  var record = recordSource.get(id);
322
- var typename = record && Record.getType(record);
323
-
206
+ var typename = record == null ? null : Record.getType(record);
324
207
  if (typename == null) {
325
208
  return null;
326
209
  }
327
-
328
210
  return {
329
211
  id: id,
330
212
  typename: typename
@@ -332,16 +214,13 @@ if (process.env.NODE_ENV !== "production") {
332
214
  },
333
215
  checkSameTypeAfterRefetch: function checkSameTypeAfterRefetch(previousIDAndType, environment, fragmentNode, componentDisplayName) {
334
216
  var _require5 = require('relay-runtime'),
335
- Record = _require5.Record;
336
-
217
+ Record = _require5.Record;
337
218
  if (!previousIDAndType) {
338
219
  return;
339
220
  }
340
-
341
221
  var recordSource = environment.getStore().getSource();
342
222
  var record = recordSource.get(previousIDAndType.id);
343
223
  var typename = record && Record.getType(record);
344
-
345
224
  if (typename !== previousIDAndType.typename) {
346
225
  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
226
  }
@@ -350,18 +229,13 @@ if (process.env.NODE_ENV !== "production") {
350
229
  if (previousIDAndTypename == null) {
351
230
  return;
352
231
  }
353
-
354
232
  var _require6 = require('relay-runtime'),
355
- ID_KEY = _require6.ID_KEY; // $FlowExpectedError[incompatible-use]
356
-
357
-
233
+ ID_KEY = _require6.ID_KEY;
358
234
  var resultID = refetchedFragmentRef[ID_KEY];
359
-
360
235
  if (resultID != null && resultID !== previousIDAndTypename.id) {
361
236
  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
237
  }
363
238
  }
364
239
  };
365
240
  }
366
-
367
241
  module.exports = useRefetchableFragmentNode;
@@ -1,45 +1,23 @@
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
1
  'use strict';
12
2
 
13
- var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
14
-
15
3
  var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
16
-
4
+ var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_REACT_CACHE');
17
5
  var _require = require('react'),
18
- useDebugValue = _require.useDebugValue;
19
-
6
+ useDebugValue = _require.useDebugValue;
20
7
  var _require2 = require('relay-runtime'),
21
- getFragment = _require2.getFragment;
22
-
8
+ getFragment = _require2.getFragment;
23
9
  function useRefetchableFragment(fragmentInput, fragmentRef) {
24
10
  var fragmentNode = getFragment(fragmentInput);
25
11
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
26
-
27
12
  var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
28
- fragmentData = _useRefetchableFragme.fragmentData,
29
- refetch = _useRefetchableFragme.refetch;
30
-
13
+ fragmentData = _useRefetchableFragme.fragmentData,
14
+ refetch = _useRefetchableFragme.refetch;
31
15
  if (process.env.NODE_ENV !== "production") {
32
- // eslint-disable-next-line react-hooks/rules-of-hooks
33
16
  useDebugValue({
34
17
  fragment: fragmentNode.name,
35
18
  data: fragmentData
36
19
  });
37
20
  }
38
- /* $FlowExpectedError[prop-missing] : Exposed options is a subset of internal
39
- * options */
40
-
41
-
42
21
  return [fragmentData, refetch];
43
22
  }
44
-
45
23
  module.exports = useRefetchableFragment;