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,16 +4,16 @@
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 _require = require('react'),
14
- useEffect = _require.useEffect,
15
- useRef = _require.useRef;
16
-
15
+ useEffect = _require.useEffect,
16
+ useRef = _require.useRef;
17
17
  function useIsMountedRef() {
18
18
  var isMountedRef = useRef(true);
19
19
  useEffect(function () {
@@ -24,5 +24,4 @@ function useIsMountedRef() {
24
24
  }, []);
25
25
  return isMountedRef;
26
26
  }
27
-
28
27
  module.exports = useIsMountedRef;
@@ -4,58 +4,47 @@
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 invariant = require('invariant');
16
-
17
16
  var React = require('react');
18
-
19
17
  var _require = require('relay-runtime'),
20
- getObservableForActiveRequest = _require.__internal.getObservableForActiveRequest,
21
- getSelector = _require.getSelector;
22
-
18
+ getObservableForActiveRequest = _require.__internal.getObservableForActiveRequest,
19
+ getSelector = _require.getSelector;
23
20
  var useEffect = React.useEffect,
24
- useState = React.useState,
25
- useMemo = React.useMemo;
26
-
21
+ useState = React.useState,
22
+ useMemo = React.useMemo;
27
23
  function useIsOperationNodeActive(fragmentNode, fragmentRef) {
28
24
  var environment = useRelayEnvironment();
29
25
  var observable = useMemo(function () {
30
26
  var selector = getSelector(fragmentNode, fragmentRef);
31
-
32
27
  if (selector == null) {
33
28
  return null;
34
29
  }
35
-
36
30
  !(selector.kind === 'SingularReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'useIsOperationNodeActive: Plural fragments are not supported.') : invariant(false) : void 0;
37
31
  return getObservableForActiveRequest(environment, selector.owner);
38
32
  }, [environment, fragmentNode, fragmentRef]);
39
-
40
33
  var _useState = useState(observable != null),
41
- isActive = _useState[0],
42
- setIsActive = _useState[1];
43
-
34
+ isActive = _useState[0],
35
+ setIsActive = _useState[1];
44
36
  useEffect(function () {
45
37
  var subscription;
46
38
  setIsActive(observable != null);
47
-
48
39
  if (observable != null) {
49
40
  var onCompleteOrError = function onCompleteOrError() {
50
41
  setIsActive(false);
51
42
  };
52
-
53
43
  subscription = observable.subscribe({
54
44
  complete: onCompleteOrError,
55
45
  error: onCompleteOrError
56
46
  });
57
47
  }
58
-
59
48
  return function () {
60
49
  if (subscription) {
61
50
  subscription.unsubscribe();
@@ -64,5 +53,4 @@ function useIsOperationNodeActive(fragmentNode, fragmentRef) {
64
53
  }, [observable]);
65
54
  return isActive;
66
55
  }
67
-
68
56
  module.exports = useIsOperationNodeActive;
@@ -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
 
13
14
  var useIsOperationNodeActive = require('./useIsOperationNodeActive');
14
-
15
15
  var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
16
-
17
16
  var _require = require('relay-runtime'),
18
- getFragment = _require.getFragment;
19
-
17
+ getFragment = _require.getFragment;
20
18
  function useIsParentQueryActive(fragmentInput, fragmentRef) {
21
19
  var fragmentNode = getFragment(fragmentInput);
22
20
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useIsParentQueryActive()');
23
21
  return useIsOperationNodeActive(fragmentNode, fragmentRef);
24
22
  }
25
-
26
23
  module.exports = useIsParentQueryActive;
@@ -4,27 +4,25 @@
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 _require = require('./loadQuery'),
14
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
15
-
15
+ useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
16
16
  var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
17
-
18
17
  var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
19
-
20
18
  var useRelayEnvironment = require('./useRelayEnvironment');
21
-
22
19
  var _require2 = require('relay-runtime'),
23
- fetchQuery = _require2.__internal.fetchQuery; // This separate type export is only needed as long as we are injecting
20
+ fetchQuery = _require2.__internal.fetchQuery;
21
+
22
+ // This separate type export is only needed as long as we are injecting
24
23
  // a separate hooks implementation in ./HooksImplementation -- it can
25
24
  // be removed after we stop doing that.
26
25
 
27
-
28
26
  function useLazyLoadQuery(gqlQuery, variables, options) {
29
27
  // We need to use this hook in order to be able to track if
30
28
  // loadQuery was called during render
@@ -43,5 +41,4 @@ function useLazyLoadQuery(gqlQuery, variables, options) {
43
41
  });
44
42
  return data;
45
43
  }
46
-
47
44
  module.exports = useLazyLoadQuery;
@@ -4,50 +4,41 @@
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 ProfilerContext = require('./ProfilerContext');
14
-
15
15
  var _require = require('./QueryResource'),
16
- getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
17
- getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
18
-
16
+ getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
17
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
19
18
  var useFetchTrackingRef = require('./useFetchTrackingRef');
20
-
21
19
  var useFragmentNode = require('./useFragmentNode');
22
-
23
20
  var useRelayEnvironment = require('./useRelayEnvironment');
24
-
25
21
  var React = require('react');
26
-
27
22
  var useContext = React.useContext,
28
- useEffect = React.useEffect,
29
- useState = React.useState,
30
- useRef = React.useRef;
31
-
23
+ useEffect = React.useEffect,
24
+ useState = React.useState,
25
+ useRef = React.useRef;
32
26
  function useLazyLoadQueryNode(_ref) {
33
27
  var query = _ref.query,
34
- componentDisplayName = _ref.componentDisplayName,
35
- fetchObservable = _ref.fetchObservable,
36
- fetchPolicy = _ref.fetchPolicy,
37
- fetchKey = _ref.fetchKey,
38
- renderPolicy = _ref.renderPolicy;
28
+ componentDisplayName = _ref.componentDisplayName,
29
+ fetchObservable = _ref.fetchObservable,
30
+ fetchPolicy = _ref.fetchPolicy,
31
+ fetchKey = _ref.fetchKey,
32
+ renderPolicy = _ref.renderPolicy;
39
33
  var environment = useRelayEnvironment();
40
34
  var profilerContext = useContext(ProfilerContext);
41
35
  var QueryResource = getQueryResourceForEnvironment(environment);
42
-
43
36
  var _useState = useState(0),
44
- forceUpdateKey = _useState[0],
45
- forceUpdate = _useState[1];
46
-
37
+ forceUpdateKey = _useState[0],
38
+ forceUpdate = _useState[1];
47
39
  var _useFetchTrackingRef = useFetchTrackingRef(),
48
- startFetch = _useFetchTrackingRef.startFetch,
49
- completeFetch = _useFetchTrackingRef.completeFetch;
50
-
40
+ startFetch = _useFetchTrackingRef.startFetch,
41
+ completeFetch = _useFetchTrackingRef.completeFetch;
51
42
  var cacheBreaker = "".concat(forceUpdateKey, "-").concat(fetchKey !== null && fetchKey !== void 0 ? fetchKey : '');
52
43
  var cacheIdentifier = getQueryCacheIdentifier(environment, query, fetchPolicy, renderPolicy, cacheBreaker);
53
44
  var preparedQueryResult = profilerContext.wrapPrepareQueryResource(function () {
@@ -86,11 +77,11 @@ function useLazyLoadQueryNode(_ref) {
86
77
  });
87
78
  return;
88
79
  }
89
-
90
80
  var disposable = QueryResource.retain(preparedQueryResult, profilerContext);
91
81
  return function () {
92
82
  disposable.dispose();
93
- }; // NOTE: We disable react-hooks-deps warning because the `environment`
83
+ };
84
+ // NOTE: We disable react-hooks-deps warning because the `environment`
94
85
  // and `cacheIdentifier` identities are capturing all information about whether
95
86
  // the effect should be re-executed and the query re-retained.
96
87
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -99,15 +90,14 @@ function useLazyLoadQueryNode(_ref) {
99
90
  // Release any temporary retain that's not released. At this point, if the
100
91
  // cacheIdentifier doesn't change, the query is still permanently retained,
101
92
  // and the temporary retain is redundant.
102
- QueryResource.releaseTemporaryRetain(preparedQueryResult); // This effect is intended to run on every commit, thus no dependency
93
+ QueryResource.releaseTemporaryRetain(preparedQueryResult);
94
+ // This effect is intended to run on every commit, thus no dependency
103
95
  });
104
- var fragmentNode = preparedQueryResult.fragmentNode,
105
- fragmentRef = preparedQueryResult.fragmentRef;
106
96
 
97
+ var fragmentNode = preparedQueryResult.fragmentNode,
98
+ fragmentRef = preparedQueryResult.fragmentRef;
107
99
  var _useFragmentNode = useFragmentNode(fragmentNode, fragmentRef, componentDisplayName),
108
- data = _useFragmentNode.data;
109
-
100
+ data = _useFragmentNode.data;
110
101
  return data;
111
102
  }
112
-
113
103
  module.exports = useLazyLoadQueryNode;
@@ -4,88 +4,72 @@
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 useFetchTrackingRef = require('./useFetchTrackingRef');
18
-
19
17
  var useIsMountedRef = require('./useIsMountedRef');
20
-
21
18
  var useIsOperationNodeActive = require('./useIsOperationNodeActive');
22
-
23
19
  var useRelayEnvironment = require('./useRelayEnvironment');
24
-
25
20
  var invariant = require('invariant');
26
-
27
21
  var _require = require('react'),
28
- useCallback = _require.useCallback,
29
- useEffect = _require.useEffect,
30
- useState = _require.useState;
31
-
22
+ useCallback = _require.useCallback,
23
+ useEffect = _require.useEffect,
24
+ useState = _require.useState;
32
25
  var _require2 = require('relay-runtime'),
33
- ConnectionInterface = _require2.ConnectionInterface,
34
- fetchQuery = _require2.__internal.fetchQuery,
35
- createOperationDescriptor = _require2.createOperationDescriptor,
36
- getPaginationVariables = _require2.getPaginationVariables,
37
- getSelector = _require2.getSelector,
38
- getValueAtPath = _require2.getValueAtPath;
39
-
26
+ fetchQuery = _require2.__internal.fetchQuery,
27
+ ConnectionInterface = _require2.ConnectionInterface,
28
+ createOperationDescriptor = _require2.createOperationDescriptor,
29
+ getPaginationVariables = _require2.getPaginationVariables,
30
+ getSelector = _require2.getSelector,
31
+ getValueAtPath = _require2.getValueAtPath;
40
32
  var warning = require("fbjs/lib/warning");
41
-
42
33
  function useLoadMoreFunction(args) {
43
34
  var direction = args.direction,
44
- fragmentNode = args.fragmentNode,
45
- fragmentRef = args.fragmentRef,
46
- fragmentIdentifier = args.fragmentIdentifier,
47
- fragmentData = args.fragmentData,
48
- connectionPathInFragmentData = args.connectionPathInFragmentData,
49
- paginationRequest = args.paginationRequest,
50
- paginationMetadata = args.paginationMetadata,
51
- componentDisplayName = args.componentDisplayName,
52
- observer = args.observer,
53
- onReset = args.onReset,
54
- identifierField = args.identifierField;
35
+ fragmentNode = args.fragmentNode,
36
+ fragmentRef = args.fragmentRef,
37
+ fragmentIdentifier = args.fragmentIdentifier,
38
+ fragmentData = args.fragmentData,
39
+ connectionPathInFragmentData = args.connectionPathInFragmentData,
40
+ paginationRequest = args.paginationRequest,
41
+ paginationMetadata = args.paginationMetadata,
42
+ componentDisplayName = args.componentDisplayName,
43
+ observer = args.observer,
44
+ onReset = args.onReset,
45
+ identifierField = args.identifierField;
55
46
  var environment = useRelayEnvironment();
56
-
57
47
  var _useFetchTrackingRef = useFetchTrackingRef(),
58
- isFetchingRef = _useFetchTrackingRef.isFetchingRef,
59
- startFetch = _useFetchTrackingRef.startFetch,
60
- disposeFetch = _useFetchTrackingRef.disposeFetch,
61
- completeFetch = _useFetchTrackingRef.completeFetch;
62
-
48
+ isFetchingRef = _useFetchTrackingRef.isFetchingRef,
49
+ startFetch = _useFetchTrackingRef.startFetch,
50
+ disposeFetch = _useFetchTrackingRef.disposeFetch,
51
+ completeFetch = _useFetchTrackingRef.completeFetch;
63
52
  var identifierValue = identifierField != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierField] : null;
64
53
  var isMountedRef = useIsMountedRef();
65
-
66
54
  var _useState = useState(environment),
67
- mirroredEnvironment = _useState[0],
68
- setMirroredEnvironment = _useState[1];
69
-
55
+ mirroredEnvironment = _useState[0],
56
+ setMirroredEnvironment = _useState[1];
70
57
  var _useState2 = useState(fragmentIdentifier),
71
- mirroredFragmentIdentifier = _useState2[0],
72
- setMirroredFragmentIdentifier = _useState2[1];
73
-
58
+ mirroredFragmentIdentifier = _useState2[0],
59
+ setMirroredFragmentIdentifier = _useState2[1];
74
60
  var isParentQueryActive = useIsOperationNodeActive(fragmentNode, fragmentRef);
75
61
  var shouldReset = environment !== mirroredEnvironment || fragmentIdentifier !== mirroredFragmentIdentifier;
76
-
77
62
  if (shouldReset) {
78
63
  disposeFetch();
79
64
  onReset();
80
65
  setMirroredEnvironment(environment);
81
66
  setMirroredFragmentIdentifier(fragmentIdentifier);
82
67
  }
83
-
84
68
  var _getConnectionState = getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData),
85
- cursor = _getConnectionState.cursor,
86
- hasMore = _getConnectionState.hasMore; // Dispose of pagination requests in flight when unmounting
87
-
69
+ cursor = _getConnectionState.cursor,
70
+ hasMore = _getConnectionState.hasMore;
88
71
 
72
+ // Dispose of pagination requests in flight when unmounting
89
73
  useEffect(function () {
90
74
  return function () {
91
75
  disposeFetch();
@@ -93,8 +77,8 @@ function useLoadMoreFunction(args) {
93
77
  }, [disposeFetch]);
94
78
  var loadMore = useCallback(function (count, options) {
95
79
  // TODO(T41131846): Fetch/Caching policies for loadMore
96
- var onComplete = options === null || options === void 0 ? void 0 : options.onComplete;
97
80
 
81
+ var onComplete = options === null || options === void 0 ? void 0 : options.onComplete;
98
82
  if (isMountedRef.current !== true) {
99
83
  // Bail out and warn if we're trying to paginate after the component
100
84
  // has unmounted
@@ -103,31 +87,27 @@ function useLoadMoreFunction(args) {
103
87
  dispose: function dispose() {}
104
88
  };
105
89
  }
106
-
107
90
  var fragmentSelector = getSelector(fragmentNode, fragmentRef);
108
-
109
91
  if (isFetchingRef.current === true || fragmentData == null || isParentQueryActive) {
110
92
  if (fragmentSelector == null) {
111
93
  process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected fetch while using a null fragment ref ' + 'for fragment `%s` in `%s`. When fetching more items, we expect ' + "initial fragment data to be non-null. Please make sure you're " + 'passing a valid fragment ref to `%s` before paginating.', fragmentNode.name, componentDisplayName, componentDisplayName) : void 0;
112
94
  }
113
-
114
95
  if (onComplete) {
115
96
  onComplete(null);
116
97
  }
117
-
118
98
  return {
119
99
  dispose: function dispose() {}
120
100
  };
121
101
  }
122
-
123
102
  !(fragmentSelector != null && fragmentSelector.kind !== 'PluralReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to be able to find a non-plural fragment owner for ' + "fragment `%s` when using `%s`. If you're seeing this, " + 'this is likely a bug in Relay.', fragmentNode.name, componentDisplayName) : invariant(false) : void 0;
124
103
  var parentVariables = fragmentSelector.owner.variables;
125
104
  var fragmentVariables = fragmentSelector.variables;
126
105
  var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
127
106
  var baseVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables);
128
- var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata); // If the query needs an identifier value ('id' or similar) and one
129
- // was not explicitly provided, read it from the fragment data.
107
+ var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata);
130
108
 
109
+ // If the query needs an identifier value ('id' or similar) and one
110
+ // was not explicitly provided, read it from the fragment data.
131
111
  if (identifierField != null) {
132
112
  // @refetchable fragments are guaranteed to have an `id` selection
133
113
  // if the type is Node, implements Node, or is @fetchable. Double-check
@@ -135,10 +115,8 @@ function useLoadMoreFunction(args) {
135
115
  if (typeof identifierValue !== 'string') {
136
116
  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;
137
117
  }
138
-
139
118
  paginationVariables.id = identifierValue;
140
119
  }
141
-
142
120
  var paginationQuery = createOperationDescriptor(paginationRequest, paginationVariables, {
143
121
  force: true
144
122
  });
@@ -161,60 +139,51 @@ function useLoadMoreFunction(args) {
161
139
  return {
162
140
  dispose: disposeFetch
163
141
  };
164
- }, // NOTE: We disable react-hooks-deps warning because all values
142
+ },
143
+ // NOTE: We disable react-hooks-deps warning because all values
165
144
  // inside paginationMetadata are static
166
145
  // eslint-disable-next-line react-hooks/exhaustive-deps
167
146
  [environment, identifierValue, direction, cursor, startFetch, disposeFetch, completeFetch, isFetchingRef, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
168
147
  return [loadMore, hasMore, disposeFetch];
169
148
  }
170
-
171
149
  function getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData) {
172
150
  var _pageInfo$END_CURSOR, _pageInfo$START_CURSO;
173
-
174
151
  var _ConnectionInterface$ = ConnectionInterface.get(),
175
- EDGES = _ConnectionInterface$.EDGES,
176
- PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
177
- HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
178
- HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
179
- END_CURSOR = _ConnectionInterface$.END_CURSOR,
180
- START_CURSOR = _ConnectionInterface$.START_CURSOR;
181
-
152
+ EDGES = _ConnectionInterface$.EDGES,
153
+ PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
154
+ HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
155
+ HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
156
+ END_CURSOR = _ConnectionInterface$.END_CURSOR,
157
+ START_CURSOR = _ConnectionInterface$.START_CURSOR;
182
158
  var connection = getValueAtPath(fragmentData, connectionPathInFragmentData);
183
-
184
159
  if (connection == null) {
185
160
  return {
186
161
  cursor: null,
187
162
  hasMore: false
188
163
  };
189
164
  }
190
-
191
165
  !(typeof connection === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have been `null`, or ' + 'a plain object with %s and %s properties. Instead got `%s`.', fragmentNode.name, EDGES, PAGE_INFO, connection) : invariant(false) : void 0;
192
166
  var edges = connection[EDGES];
193
167
  var pageInfo = connection[PAGE_INFO];
194
-
195
168
  if (edges == null || pageInfo == null) {
196
169
  return {
197
170
  cursor: null,
198
171
  hasMore: false
199
172
  };
200
173
  }
201
-
202
174
  !Array.isArray(edges) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have a plural `%s` field. ' + 'Instead got `%s`.', fragmentNode.name, EDGES, edges) : invariant(false) : void 0;
203
175
  !(typeof pageInfo === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have a `%s` field. ' + 'Instead got `%s`.', fragmentNode.name, PAGE_INFO, pageInfo) : invariant(false) : void 0;
204
176
  var cursor = direction === 'forward' ? (_pageInfo$END_CURSOR = pageInfo[END_CURSOR]) !== null && _pageInfo$END_CURSOR !== void 0 ? _pageInfo$END_CURSOR : null : (_pageInfo$START_CURSO = pageInfo[START_CURSOR]) !== null && _pageInfo$START_CURSO !== void 0 ? _pageInfo$START_CURSO : null;
205
177
  !(cursor === null || typeof cursor === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected page info for connection in fragment `%s` to have a ' + 'valid `%s`. Instead got `%s`.', fragmentNode.name, START_CURSOR, cursor) : invariant(false) : void 0;
206
178
  var hasMore;
207
-
208
179
  if (direction === 'forward') {
209
180
  hasMore = cursor != null && pageInfo[HAS_NEXT_PAGE] === true;
210
181
  } else {
211
182
  hasMore = cursor != null && pageInfo[HAS_PREV_PAGE] === true;
212
183
  }
213
-
214
184
  return {
215
185
  cursor: cursor,
216
186
  hasMore: hasMore
217
187
  };
218
188
  }
219
-
220
189
  module.exports = useLoadMoreFunction;
@@ -4,32 +4,24 @@
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 useMemoVariables = require('./useMemoVariables');
14
-
15
15
  var React = require('react');
16
-
17
16
  var _require = require('relay-runtime'),
18
- createOperationDescriptor = _require.createOperationDescriptor,
19
- getRequest = _require.getRequest;
20
-
17
+ createOperationDescriptor = _require.createOperationDescriptor,
18
+ getRequest = _require.getRequest;
21
19
  var useMemo = React.useMemo;
22
-
23
20
  function useMemoOperationDescriptor(gqlQuery, variables, cacheConfig) {
24
- var _useMemoVariables = useMemoVariables(variables),
25
- memoVariables = _useMemoVariables[0];
26
-
27
- var _useMemoVariables2 = useMemoVariables(cacheConfig || {}),
28
- memoCacheConfig = _useMemoVariables2[0];
29
-
21
+ var memoVariables = useMemoVariables(variables);
22
+ var memoCacheConfig = useMemoVariables(cacheConfig || {});
30
23
  return useMemo(function () {
31
24
  return createOperationDescriptor(getRequest(gqlQuery), memoVariables, memoCacheConfig);
32
25
  }, [gqlQuery, memoVariables, memoCacheConfig]);
33
26
  }
34
-
35
27
  module.exports = useMemoOperationDescriptor;
@@ -4,49 +4,31 @@
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 areEqual = require("fbjs/lib/areEqual");
15
+ var _require = require('react'),
16
+ useState = _require.useState;
14
17
 
15
- var React = require('react');
16
-
17
- var useMemo = React.useMemo,
18
- useRef = React.useRef,
19
- useState = React.useState;
20
-
18
+ /**
19
+ * Memoizes the passed in `variables` object based on `areEqual` equality.
20
+ * This is useful when a `variables` object is used as a value in a depencency
21
+ * array as it might often be constructed during render.
22
+ */
21
23
  function useMemoVariables(variables) {
22
- var _variablesChangedGene2;
23
-
24
- // The value of this ref is a counter that should be incremented when
25
- // variables change. This allows us to use the counter as a
26
- // memoization value to indicate if the computation for useMemo
27
- // should be re-executed.
28
- var variablesChangedGenerationRef = useRef(0); // We mirror the variables to check if they have changed between renders
29
-
30
24
  var _useState = useState(variables),
31
- mirroredVariables = _useState[0],
32
- setMirroredVariables = _useState[1];
33
-
34
- var variablesChanged = !areEqual(variables, mirroredVariables);
35
-
36
- if (variablesChanged) {
37
- var _variablesChangedGene;
38
-
39
- variablesChangedGenerationRef.current = ((_variablesChangedGene = variablesChangedGenerationRef.current) !== null && _variablesChangedGene !== void 0 ? _variablesChangedGene : 0) + 1;
25
+ mirroredVariables = _useState[0],
26
+ setMirroredVariables = _useState[1];
27
+ if (areEqual(variables, mirroredVariables)) {
28
+ return mirroredVariables;
29
+ } else {
40
30
  setMirroredVariables(variables);
41
- } // NOTE: We disable react-hooks-deps warning because we explicitly
42
- // don't want to memoize on object identity
43
- // eslint-disable-next-line react-hooks/exhaustive-deps
44
-
45
-
46
- var memoVariables = useMemo(function () {
47
31
  return variables;
48
- }, [variablesChangedGenerationRef.current]);
49
- return [memoVariables, (_variablesChangedGene2 = variablesChangedGenerationRef.current) !== null && _variablesChangedGene2 !== void 0 ? _variablesChangedGene2 : 0];
32
+ }
50
33
  }
51
-
52
34
  module.exports = useMemoVariables;