react-relay 14.0.0 → 15.0.0

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