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