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