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