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,52 +4,38 @@
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 HooksImplementation = require('./HooksImplementation');
12
+ 'use strict';
15
13
 
16
14
  var _require = require('./loadQuery'),
17
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
18
-
15
+ useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
19
16
  var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
20
-
21
17
  var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
22
-
23
18
  var useRelayEnvironment = require('./useRelayEnvironment');
24
-
25
19
  var invariant = require('invariant');
26
-
27
20
  var _require2 = require('react'),
28
- useDebugValue = _require2.useDebugValue;
29
-
21
+ useDebugValue = _require2.useDebugValue;
30
22
  var _require3 = require('relay-runtime'),
31
- _require3$__internal = _require3.__internal,
32
- fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
33
- fetchQuery = _require3$__internal.fetchQuery;
34
-
35
- var warning = require("fbjs/lib/warning"); // This separate type export is only needed as long as we are injecting
36
- // a separate hooks implementation in ./HooksImplementation -- it can
37
- // be removed after we stop doing that.
38
-
39
-
40
- function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
23
+ _require3$__internal = _require3.__internal,
24
+ fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
25
+ fetchQuery = _require3$__internal.fetchQuery;
26
+ var warning = require("fbjs/lib/warning");
27
+ function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
41
28
  // We need to use this hook in order to be able to track if
42
29
  // loadQuery was called during render
43
30
  useTrackLoadQueryInRender();
44
31
  var environment = useRelayEnvironment();
45
32
  var fetchKey = preloadedQuery.fetchKey,
46
- fetchPolicy = preloadedQuery.fetchPolicy,
47
- source = preloadedQuery.source,
48
- variables = preloadedQuery.variables,
49
- networkCacheConfig = preloadedQuery.networkCacheConfig;
33
+ fetchPolicy = preloadedQuery.fetchPolicy,
34
+ source = preloadedQuery.source,
35
+ variables = preloadedQuery.variables,
36
+ networkCacheConfig = preloadedQuery.networkCacheConfig;
50
37
  var operation = useMemoOperationDescriptor(gqlQuery, variables, networkCacheConfig);
51
38
  var useLazyLoadQueryNodeParams;
52
-
53
39
  if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
54
40
  !(operation.request.node.params.name === preloadedQuery.name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'usePreloadedQuery(): Expected data to be prefetched for query `%s`, ' + 'got prefetch results for query `%s`.', operation.request.node.params.name, preloadedQuery.name) : invariant(false) : void 0;
55
41
  useLazyLoadQueryNodeParams = {
@@ -75,7 +61,6 @@ function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
75
61
  process.env.NODE_ENV !== "production" ? warning(preloadedQuery.isDisposed === false, 'usePreloadedQuery(): Expected preloadedQuery to not be disposed yet. ' + 'This is because disposing the query marks it for future garbage ' + 'collection, and as such query results may no longer be present in the Relay ' + 'store. In the future, this will become a hard error.') : void 0;
76
62
  var fallbackFetchObservable = fetchQuery(environment, operation);
77
63
  var fetchObservable;
78
-
79
64
  if (source != null && environment === preloadedQuery.environment) {
80
65
  // If the source observable exists and the environments match, reuse
81
66
  // the source observable.
@@ -97,7 +82,6 @@ function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
97
82
  // fall back and re-execute and de-dupe the query (at render time).
98
83
  fetchObservable = fallbackFetchObservable;
99
84
  }
100
-
101
85
  useLazyLoadQueryNodeParams = {
102
86
  componentDisplayName: 'usePreloadedQuery()',
103
87
  fetchObservable: fetchObservable,
@@ -107,9 +91,7 @@ function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
107
91
  renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
108
92
  };
109
93
  }
110
-
111
94
  var data = useLazyLoadQueryNode(useLazyLoadQueryNodeParams);
112
-
113
95
  if (process.env.NODE_ENV !== "production") {
114
96
  // eslint-disable-next-line react-hooks/rules-of-hooks
115
97
  useDebugValue({
@@ -121,19 +103,6 @@ function usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options) {
121
103
  renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
122
104
  });
123
105
  }
124
-
125
106
  return data;
126
107
  }
127
-
128
- function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
129
- var impl = HooksImplementation.get();
130
-
131
- if (impl) {
132
- return impl.usePreloadedQuery(gqlQuery, preloadedQuery, options);
133
- } else {
134
- // eslint-disable-next-line react-hooks/rules-of-hooks
135
- return usePreloadedQuery_LEGACY(gqlQuery, preloadedQuery, options);
136
- }
137
- }
138
-
139
108
  module.exports = usePreloadedQuery;
@@ -4,47 +4,37 @@
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 _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
17
-
18
16
  var _require = require('./loadQuery'),
19
- loadQuery = _require.loadQuery,
20
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
21
-
17
+ loadQuery = _require.loadQuery,
18
+ useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
22
19
  var useIsMountedRef = require('./useIsMountedRef');
23
-
24
20
  var useRelayEnvironment = require('./useRelayEnvironment');
25
-
26
21
  var _require2 = require('react'),
27
- useCallback = _require2.useCallback,
28
- useEffect = _require2.useEffect,
29
- useRef = _require2.useRef,
30
- useState = _require2.useState;
31
-
22
+ useCallback = _require2.useCallback,
23
+ useEffect = _require2.useEffect,
24
+ useRef = _require2.useRef,
25
+ useState = _require2.useState;
32
26
  var _require3 = require('relay-runtime'),
33
- getRequest = _require3.getRequest;
34
-
27
+ getRequest = _require3.getRequest;
35
28
  var initialNullQueryReferenceState = {
36
29
  kind: 'NullQueryReference'
37
30
  };
38
-
39
31
  function requestIsLiveQuery(preloadableRequest) {
40
32
  if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
41
33
  return preloadableRequest.params.metadata.live !== undefined;
42
34
  }
43
-
44
35
  var request = getRequest(preloadableRequest);
45
36
  return request.params.metadata.live !== undefined;
46
37
  }
47
-
48
38
  function useQueryLoader(preloadableRequest, initialQueryReference) {
49
39
  /**
50
40
  * We want to always call `queryReference.dispose()` for every call to
@@ -65,24 +55,22 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
65
55
  * Finally, when the hook unmounts, we also dispose of all remaining uncommitted
66
56
  * query references.
67
57
  */
58
+
68
59
  var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
69
60
  var environment = useRelayEnvironment();
70
61
  useTrackLoadQueryInRender();
71
62
  var isMountedRef = useIsMountedRef();
72
63
  var undisposedQueryReferencesRef = useRef(new Set([initialQueryReferenceInternal]));
73
-
74
64
  var _useState = useState(function () {
75
- return initialQueryReferenceInternal;
76
- }),
77
- queryReference = _useState[0],
78
- setQueryReference = _useState[1];
79
-
65
+ return initialQueryReferenceInternal;
66
+ }),
67
+ queryReference = _useState[0],
68
+ setQueryReference = _useState[1];
80
69
  var _useState2 = useState(function () {
81
- return initialQueryReferenceInternal;
82
- }),
83
- previousInitialQueryReference = _useState2[0],
84
- setPreviousInitialQueryReference = _useState2[1];
85
-
70
+ return initialQueryReferenceInternal;
71
+ }),
72
+ previousInitialQueryReference = _useState2[0],
73
+ setPreviousInitialQueryReference = _useState2[1];
86
74
  if (initialQueryReferenceInternal !== previousInitialQueryReference) {
87
75
  // Rendering the query reference makes it "managed" by this hook, so
88
76
  // we start keeping track of it so we can dispose it when it is no longer
@@ -93,7 +81,6 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
93
81
  setPreviousInitialQueryReference(initialQueryReferenceInternal);
94
82
  setQueryReference(initialQueryReferenceInternal);
95
83
  }
96
-
97
84
  var disposeQuery = useCallback(function () {
98
85
  if (isMountedRef.current) {
99
86
  undisposedQueryReferencesRef.current.add(initialNullQueryReferenceState);
@@ -106,10 +93,8 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
106
93
  networkCacheConfig: options.networkCacheConfig,
107
94
  __nameForWarning: options.__nameForWarning
108
95
  } : options;
109
-
110
96
  if (isMountedRef.current) {
111
97
  var _options$__environmen;
112
-
113
98
  var updatedQueryReference = loadQuery((_options$__environmen = options === null || options === void 0 ? void 0 : options.__environment) !== null && _options$__environmen !== void 0 ? _options$__environmen : environment, preloadableRequest, variables, mergedOptions);
114
99
  undisposedQueryReferencesRef.current.add(updatedQueryReference);
115
100
  setQueryReference(updatedQueryReference);
@@ -140,16 +125,16 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
140
125
  // so that the queryReference is correctly re-retained, and
141
126
  // potentially refetched if necessary.
142
127
  maybeHiddenOrFastRefresh.current = false;
143
-
144
128
  if (queryReference.kind !== 'NullQueryReference') {
145
129
  queryLoaderCallback(queryReference.variables, {
146
130
  fetchPolicy: queryReference.fetchPolicy,
147
131
  networkCacheConfig: queryReference.networkCacheConfig
148
132
  });
149
133
  }
150
-
151
134
  return;
152
- } // When a new queryReference is committed, we iterate over all
135
+ }
136
+
137
+ // When a new queryReference is committed, we iterate over all
153
138
  // query references in undisposedQueryReferences and dispose all of
154
139
  // the refs that aren't the currently committed one. This ensures
155
140
  // that we don't leave any dangling query references for the
@@ -168,24 +153,17 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
168
153
  // associated with updates that were scheduled prior to the currently
169
154
  // committing state change. (A useEffect callback is called during the commit
170
155
  // phase.)
171
-
172
-
173
156
  var undisposedQueryReferences = undisposedQueryReferencesRef.current;
174
-
175
157
  if (isMountedRef.current) {
176
158
  var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferences),
177
- _step;
178
-
159
+ _step;
179
160
  try {
180
161
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
181
162
  var undisposedQueryReference = _step.value;
182
-
183
163
  if (undisposedQueryReference === queryReference) {
184
164
  break;
185
165
  }
186
-
187
166
  undisposedQueryReferences["delete"](undisposedQueryReference);
188
-
189
167
  if (undisposedQueryReference.kind !== 'NullQueryReference') {
190
168
  if (requestIsLiveQuery(preloadableRequest)) {
191
169
  undisposedQueryReference.dispose && undisposedQueryReference.dispose();
@@ -206,12 +184,10 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
206
184
  // undisposedQueryReferences.current is never reassigned
207
185
  // eslint-disable-next-line react-hooks/exhaustive-deps
208
186
  var _iterator2 = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferencesRef.current),
209
- _step2;
210
-
187
+ _step2;
211
188
  try {
212
189
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
213
190
  var undisposedQueryReference = _step2.value;
214
-
215
191
  if (undisposedQueryReference.kind !== 'NullQueryReference') {
216
192
  if (requestIsLiveQuery(preloadableRequest)) {
217
193
  undisposedQueryReference.dispose && undisposedQueryReference.dispose();
@@ -229,5 +205,4 @@ function useQueryLoader(preloadableRequest, initialQueryReference) {
229
205
  }, [preloadableRequest]);
230
206
  return [queryReference.kind === 'NullQueryReference' ? null : queryReference, queryLoaderCallback, disposeQuery];
231
207
  }
232
-
233
208
  module.exports = useQueryLoader;
@@ -4,31 +4,26 @@
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 HooksImplementation = require('./HooksImplementation');
14
15
  var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
15
-
16
16
  var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
17
-
18
17
  var _require = require('react'),
19
- useDebugValue = _require.useDebugValue;
20
-
18
+ useDebugValue = _require.useDebugValue;
21
19
  var _require2 = require('relay-runtime'),
22
- getFragment = _require2.getFragment;
23
-
24
- function useRefetchableFragment(fragmentInput, fragmentRef) {
20
+ getFragment = _require2.getFragment;
21
+ function useRefetchableFragment_LEGACY(fragmentInput, fragmentRef) {
25
22
  var fragmentNode = getFragment(fragmentInput);
26
23
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
27
-
28
24
  var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
29
- fragmentData = _useRefetchableFragme.fragmentData,
30
- refetch = _useRefetchableFragme.refetch;
31
-
25
+ fragmentData = _useRefetchableFragme.fragmentData,
26
+ refetch = _useRefetchableFragme.refetch;
32
27
  if (process.env.NODE_ENV !== "production") {
33
28
  // eslint-disable-next-line react-hooks/rules-of-hooks
34
29
  useDebugValue({
@@ -36,11 +31,18 @@ function useRefetchableFragment(fragmentInput, fragmentRef) {
36
31
  data: fragmentData
37
32
  });
38
33
  }
39
- /* $FlowExpectedError[prop-missing] : Exposed options is a subset of internal
40
- * options */
41
-
42
34
 
35
+ // $FlowFixMe[incompatible-return]
36
+ // $FlowFixMe[prop-missing]
43
37
  return [fragmentData, refetch];
44
38
  }
45
-
39
+ function useRefetchableFragment(fragmentInput, parentFragmentRef) {
40
+ var impl = HooksImplementation.get();
41
+ if (impl) {
42
+ return impl.useRefetchableFragment(fragmentInput, parentFragmentRef);
43
+ } else {
44
+ // eslint-disable-next-line react-hooks/rules-of-hooks
45
+ return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
46
+ }
47
+ }
46
48
  module.exports = useRefetchableFragment;