react-relay 14.1.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) 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 +20 -10
  9. package/ReactRelayQueryRenderer.js.flow +15 -11
  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 +2 -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 +10 -6
  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 +0 -11
  47. package/lib/ReactRelayContext.js +1 -12
  48. package/lib/ReactRelayFragmentContainer.js +23 -122
  49. package/lib/ReactRelayFragmentMockRenderer.js +0 -12
  50. package/lib/ReactRelayLocalQueryRenderer.js +12 -41
  51. package/lib/ReactRelayPaginationContainer.js +45 -341
  52. package/lib/ReactRelayQueryFetcher.js +36 -111
  53. package/lib/ReactRelayQueryRenderer.js +29 -137
  54. package/lib/ReactRelayQueryRendererContext.js +0 -10
  55. package/lib/ReactRelayRefetchContainer.js +33 -166
  56. package/lib/ReactRelayTestMocker.js +18 -128
  57. package/lib/ReactRelayTypes.js +0 -9
  58. package/lib/RelayContext.js +0 -23
  59. package/lib/assertFragmentMap.js +0 -16
  60. package/lib/buildReactRelayContainer.js +7 -41
  61. package/lib/getRootVariablesForFragments.js +2 -19
  62. package/lib/hooks.js +3 -30
  63. package/lib/index.js +3 -39
  64. package/lib/isRelayEnvironment.js +1 -16
  65. package/lib/jest-react/enqueueTask.js +1 -25
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +2 -51
  68. package/lib/legacy.js +0 -20
  69. package/lib/multi-actor/ActorChange.js +0 -14
  70. package/lib/multi-actor/index.js +0 -10
  71. package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
  72. package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
  74. package/lib/relay-hooks/FragmentResource.js +130 -280
  75. package/lib/relay-hooks/HooksImplementation.js +0 -14
  76. package/lib/relay-hooks/InternalLogger.js +0 -11
  77. package/lib/relay-hooks/LRUCache.js +0 -39
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
  79. package/lib/relay-hooks/MatchContainer.js +9 -111
  80. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  81. package/lib/relay-hooks/ProfilerContext.js +0 -14
  82. package/lib/relay-hooks/QueryResource.js +14 -149
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
  84. package/lib/relay-hooks/SuspenseResource.js +2 -59
  85. package/lib/relay-hooks/loadEntryPoint.js +10 -45
  86. package/lib/relay-hooks/loadQuery.js +29 -169
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
  89. package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
  90. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
  91. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
  92. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
  93. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
  94. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
  95. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
  96. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
  97. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
  98. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
  99. package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
  100. package/lib/relay-hooks/useClientQuery.js +0 -21
  101. package/lib/relay-hooks/useEntryPointLoader.js +12 -100
  102. package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
  103. package/lib/relay-hooks/useFragment.js +5 -32
  104. package/lib/relay-hooks/useFragmentNode.js +14 -55
  105. package/lib/relay-hooks/useIsMountedRef.js +2 -14
  106. package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
  107. package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
  108. package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
  109. package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
  110. package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
  111. package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
  112. package/lib/relay-hooks/useMemoVariables.js +8 -43
  113. package/lib/relay-hooks/useMutation.js +6 -34
  114. package/lib/relay-hooks/usePaginationFragment.js +49 -89
  115. package/lib/relay-hooks/usePreloadedQuery.js +10 -54
  116. package/lib/relay-hooks/useQueryLoader.js +18 -116
  117. package/lib/relay-hooks/useRefetchableFragment.js +4 -30
  118. package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
  119. package/lib/relay-hooks/useRelayEnvironment.js +2 -16
  120. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
  121. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
  122. package/lib/relay-hooks/useSubscription.js +3 -22
  123. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
  124. package/multi-actor/ActorChange.js.flow +1 -1
  125. package/multi-actor/index.js.flow +1 -1
  126. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  127. package/package.json +2 -2
  128. package/react-relay-hooks.js +2 -2
  129. package/react-relay-hooks.min.js +2 -2
  130. package/react-relay-legacy.js +2 -2
  131. package/react-relay-legacy.min.js +2 -2
  132. package/react-relay.js +2 -2
  133. package/react-relay.min.js +2 -2
  134. package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
  135. package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
  136. package/relay-hooks/FragmentResource.js.flow +148 -34
  137. package/relay-hooks/HooksImplementation.js.flow +1 -1
  138. package/relay-hooks/InternalLogger.js.flow +1 -1
  139. package/relay-hooks/LRUCache.js.flow +1 -1
  140. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
  141. package/relay-hooks/MatchContainer.js.flow +1 -1
  142. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  143. package/relay-hooks/ProfilerContext.js.flow +1 -1
  144. package/relay-hooks/QueryResource.js.flow +25 -5
  145. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  146. package/relay-hooks/SuspenseResource.js.flow +1 -1
  147. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
  149. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  150. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  151. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
  152. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  153. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
  154. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
  155. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  156. package/relay-hooks/loadEntryPoint.js.flow +15 -8
  157. package/relay-hooks/loadQuery.js.flow +32 -8
  158. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  159. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
  160. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  161. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
  163. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
  164. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
  165. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  166. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
  167. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  168. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
  169. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
  170. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
  171. package/relay-hooks/useClientQuery.js.flow +3 -3
  172. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  173. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  174. package/relay-hooks/useFragment.js.flow +2 -2
  175. package/relay-hooks/useFragmentNode.js.flow +7 -6
  176. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  177. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  178. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  179. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  180. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  181. package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
  182. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  183. package/relay-hooks/useMemoVariables.js.flow +13 -29
  184. package/relay-hooks/useMutation.js.flow +30 -13
  185. package/relay-hooks/usePaginationFragment.js.flow +55 -54
  186. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  187. package/relay-hooks/useQueryLoader.js.flow +78 -21
  188. package/relay-hooks/useRefetchableFragment.js.flow +65 -33
  189. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
  190. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  191. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  192. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  193. package/relay-hooks/useSubscription.js.flow +1 -1
  194. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  195. package/lib/readContext.js +0 -27
  196. package/readContext.js.flow +0 -29
@@ -1,103 +1,62 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _require = require('./FragmentResource'),
14
- getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
15
-
4
+ getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
16
5
  var useRelayEnvironment = require('./useRelayEnvironment');
17
-
6
+ var useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
18
7
  var _require2 = require('react'),
19
- useEffect = _require2.useEffect,
20
- useRef = _require2.useRef,
21
- useState = _require2.useState;
22
-
8
+ useEffect = _require2.useEffect,
9
+ useState = _require2.useState;
23
10
  var _require3 = require('relay-runtime'),
24
- getFragmentIdentifier = _require3.getFragmentIdentifier;
25
-
11
+ RelayFeatureFlags = _require3.RelayFeatureFlags,
12
+ getFragmentIdentifier = _require3.getFragmentIdentifier;
26
13
  var warning = require("fbjs/lib/warning");
27
-
28
14
  function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
29
15
  var environment = useRelayEnvironment();
30
16
  var FragmentResource = getFragmentResourceForEnvironment(environment);
31
- var isMountedRef = useRef(false);
32
-
17
+ var isMountedRef = useUnsafeRef_DEPRECATED(false);
33
18
  var _useState = useState(0),
34
- forceUpdate = _useState[1];
35
-
36
- var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef); // Read fragment data; this might suspend.
37
-
19
+ forceUpdate = _useState[1];
20
+ var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
38
21
  var fragmentResult = FragmentResource.readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName);
39
- var isListeningForUpdatesRef = useRef(true);
40
-
22
+ var isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
41
23
  function enableStoreUpdates() {
42
24
  isListeningForUpdatesRef.current = true;
43
25
  var didMissUpdates = FragmentResource.checkMissedUpdates(fragmentResult)[0];
44
-
45
26
  if (didMissUpdates) {
46
27
  handleDataUpdate();
47
28
  }
48
29
  }
49
-
50
30
  function disableStoreUpdates() {
51
31
  isListeningForUpdatesRef.current = false;
52
32
  }
53
-
54
33
  function handleDataUpdate() {
55
34
  if (isMountedRef.current === false || isListeningForUpdatesRef.current === false) {
56
35
  return;
57
- } // React bails out on noop state updates as an optimization.
58
- // If we want to force an update via setState, we need to pass an value.
59
- // The actual value can be arbitrary though, e.g. an incremented number.
60
-
61
-
36
+ }
62
37
  forceUpdate(function (count) {
63
38
  return count + 1;
64
39
  });
65
- } // Establish Relay store subscriptions in the commit phase, only if
66
- // rendering for the first time, or if we need to subscribe to new data
67
- // If the fragment identifier changes, it means that the variables on the
68
- // fragment owner changed, or the fragment ref points to different records.
69
- // In this case, we need to resubscribe to the Relay store.
70
-
71
-
40
+ }
72
41
  useEffect(function () {
73
42
  isMountedRef.current = true;
74
43
  var disposable = FragmentResource.subscribe(fragmentResult, handleDataUpdate);
75
44
  return function () {
76
- // When unmounting or resubscribing to new data, clean up current
77
- // subscription. This will also make sure fragment data is no longer
78
- // cached so that next time it its read, it will be freshly read from
79
- // the Relay store
80
45
  isMountedRef.current = false;
81
46
  disposable.dispose();
82
- }; // NOTE: We disable react-hooks-deps warning because environment and fragmentIdentifier
83
- // is capturing all information about whether the effect should be re-ran.
84
- // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ };
85
48
  }, [environment, fragmentIdentifier]);
86
-
87
- if (process.env.NODE_ENV !== "production") {
49
+ if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
88
50
  if (fragmentRef != null && (fragmentResult.data === undefined || Array.isArray(fragmentResult.data) && fragmentResult.data.length > 0 && fragmentResult.data.every(function (data) {
89
51
  return data === undefined;
90
52
  }))) {
91
53
  process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected to have been able to read non-null data for ' + 'fragment `%s` declared in ' + '`%s`, since fragment reference was non-null. ' + "Make sure that that `%s`'s parent isn't " + 'holding on to and/or passing a fragment reference for data that ' + 'has been deleted.', fragmentNode.name, componentDisplayName, componentDisplayName) : void 0;
92
54
  }
93
55
  }
94
-
95
56
  return {
96
- // $FlowFixMe[incompatible-return]
97
57
  data: fragmentResult.data,
98
58
  disableStoreUpdates: disableStoreUpdates,
99
59
  enableStoreUpdates: enableStoreUpdates
100
60
  };
101
61
  }
102
-
103
62
  module.exports = useFragmentNode;
@@ -1,19 +1,8 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _require = require('react'),
14
- useEffect = _require.useEffect,
15
- useRef = _require.useRef;
16
-
4
+ useEffect = _require.useEffect,
5
+ useRef = _require.useRef;
17
6
  function useIsMountedRef() {
18
7
  var isMountedRef = useRef(true);
19
8
  useEffect(function () {
@@ -24,5 +13,4 @@ function useIsMountedRef() {
24
13
  }, []);
25
14
  return isMountedRef;
26
15
  }
27
-
28
16
  module.exports = useIsMountedRef;
@@ -1,61 +1,39 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var useRelayEnvironment = require('./useRelayEnvironment');
14
-
15
4
  var invariant = require('invariant');
16
-
17
5
  var React = require('react');
18
-
19
6
  var _require = require('relay-runtime'),
20
- getObservableForActiveRequest = _require.__internal.getObservableForActiveRequest,
21
- getSelector = _require.getSelector;
22
-
7
+ getObservableForActiveRequest = _require.__internal.getObservableForActiveRequest,
8
+ getSelector = _require.getSelector;
23
9
  var useEffect = React.useEffect,
24
- useState = React.useState,
25
- useMemo = React.useMemo;
26
-
10
+ useState = React.useState,
11
+ useMemo = React.useMemo;
27
12
  function useIsOperationNodeActive(fragmentNode, fragmentRef) {
28
13
  var environment = useRelayEnvironment();
29
14
  var observable = useMemo(function () {
30
15
  var selector = getSelector(fragmentNode, fragmentRef);
31
-
32
16
  if (selector == null) {
33
17
  return null;
34
18
  }
35
-
36
19
  !(selector.kind === 'SingularReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'useIsOperationNodeActive: Plural fragments are not supported.') : invariant(false) : void 0;
37
20
  return getObservableForActiveRequest(environment, selector.owner);
38
21
  }, [environment, fragmentNode, fragmentRef]);
39
-
40
22
  var _useState = useState(observable != null),
41
- isActive = _useState[0],
42
- setIsActive = _useState[1];
43
-
23
+ isActive = _useState[0],
24
+ setIsActive = _useState[1];
44
25
  useEffect(function () {
45
26
  var subscription;
46
27
  setIsActive(observable != null);
47
-
48
28
  if (observable != null) {
49
29
  var onCompleteOrError = function onCompleteOrError() {
50
30
  setIsActive(false);
51
31
  };
52
-
53
32
  subscription = observable.subscribe({
54
33
  complete: onCompleteOrError,
55
34
  error: onCompleteOrError
56
35
  });
57
36
  }
58
-
59
37
  return function () {
60
38
  if (subscription) {
61
39
  subscription.unsubscribe();
@@ -64,5 +42,4 @@ function useIsOperationNodeActive(fragmentNode, fragmentRef) {
64
42
  }, [observable]);
65
43
  return isActive;
66
44
  }
67
-
68
45
  module.exports = useIsOperationNodeActive;
@@ -1,26 +1,12 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var useIsOperationNodeActive = require('./useIsOperationNodeActive');
14
-
15
4
  var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
16
-
17
5
  var _require = require('relay-runtime'),
18
- getFragment = _require.getFragment;
19
-
6
+ getFragment = _require.getFragment;
20
7
  function useIsParentQueryActive(fragmentInput, fragmentRef) {
21
8
  var fragmentNode = getFragment(fragmentInput);
22
9
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useIsParentQueryActive()');
23
10
  return useIsOperationNodeActive(fragmentNode, fragmentRef);
24
11
  }
25
-
26
12
  module.exports = useIsParentQueryActive;
@@ -1,33 +1,13 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _require = require('./loadQuery'),
14
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
15
-
4
+ useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
16
5
  var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
17
-
18
6
  var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
19
-
20
7
  var useRelayEnvironment = require('./useRelayEnvironment');
21
-
22
8
  var _require2 = require('relay-runtime'),
23
- fetchQuery = _require2.__internal.fetchQuery; // This separate type export is only needed as long as we are injecting
24
- // a separate hooks implementation in ./HooksImplementation -- it can
25
- // be removed after we stop doing that.
26
-
27
-
9
+ fetchQuery = _require2.__internal.fetchQuery;
28
10
  function useLazyLoadQuery(gqlQuery, variables, options) {
29
- // We need to use this hook in order to be able to track if
30
- // loadQuery was called during render
31
11
  useTrackLoadQueryInRender();
32
12
  var environment = useRelayEnvironment();
33
13
  var query = useMemoOperationDescriptor(gqlQuery, variables, options && options.networkCacheConfig ? options.networkCacheConfig : {
@@ -43,5 +23,4 @@ function useLazyLoadQuery(gqlQuery, variables, options) {
43
23
  });
44
24
  return data;
45
25
  }
46
-
47
26
  module.exports = useLazyLoadQuery;
@@ -1,53 +1,33 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var ProfilerContext = require('./ProfilerContext');
14
-
15
4
  var _require = require('./QueryResource'),
16
- getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
17
- getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
18
-
5
+ getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
6
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
19
7
  var useFetchTrackingRef = require('./useFetchTrackingRef');
20
-
21
8
  var useFragmentNode = require('./useFragmentNode');
22
-
23
9
  var useRelayEnvironment = require('./useRelayEnvironment');
24
-
25
10
  var React = require('react');
26
-
27
11
  var useContext = React.useContext,
28
- useEffect = React.useEffect,
29
- useState = React.useState,
30
- useRef = React.useRef;
31
-
12
+ useEffect = React.useEffect,
13
+ useState = React.useState,
14
+ useRef = React.useRef;
32
15
  function useLazyLoadQueryNode(_ref) {
33
16
  var query = _ref.query,
34
- componentDisplayName = _ref.componentDisplayName,
35
- fetchObservable = _ref.fetchObservable,
36
- fetchPolicy = _ref.fetchPolicy,
37
- fetchKey = _ref.fetchKey,
38
- renderPolicy = _ref.renderPolicy;
17
+ componentDisplayName = _ref.componentDisplayName,
18
+ fetchObservable = _ref.fetchObservable,
19
+ fetchPolicy = _ref.fetchPolicy,
20
+ fetchKey = _ref.fetchKey,
21
+ renderPolicy = _ref.renderPolicy;
39
22
  var environment = useRelayEnvironment();
40
23
  var profilerContext = useContext(ProfilerContext);
41
24
  var QueryResource = getQueryResourceForEnvironment(environment);
42
-
43
25
  var _useState = useState(0),
44
- forceUpdateKey = _useState[0],
45
- forceUpdate = _useState[1];
46
-
26
+ forceUpdateKey = _useState[0],
27
+ forceUpdate = _useState[1];
47
28
  var _useFetchTrackingRef = useFetchTrackingRef(),
48
- startFetch = _useFetchTrackingRef.startFetch,
49
- completeFetch = _useFetchTrackingRef.completeFetch;
50
-
29
+ startFetch = _useFetchTrackingRef.startFetch,
30
+ completeFetch = _useFetchTrackingRef.completeFetch;
51
31
  var cacheBreaker = "".concat(forceUpdateKey, "-").concat(fetchKey !== null && fetchKey !== void 0 ? fetchKey : '');
52
32
  var cacheIdentifier = getQueryCacheIdentifier(environment, query, fetchPolicy, renderPolicy, cacheBreaker);
53
33
  var preparedQueryResult = profilerContext.wrapPrepareQueryResource(function () {
@@ -60,54 +40,29 @@ function useLazyLoadQueryNode(_ref) {
60
40
  var maybeHiddenOrFastRefresh = useRef(false);
61
41
  useEffect(function () {
62
42
  return function () {
63
- // Attempt to detect if the component was
64
- // hidden (by Offscreen API), or fast refresh occured;
65
- // Only in these situations would the effect cleanup
66
- // for "unmounting" run multiple times, so if
67
- // we are ever able to read this ref with a value
68
- // of true, it means that one of these cases
69
- // has happened.
70
43
  maybeHiddenOrFastRefresh.current = true;
71
44
  };
72
45
  }, []);
73
46
  useEffect(function () {
74
47
  if (maybeHiddenOrFastRefresh.current === true) {
75
- // This block only runs if the component has previously "unmounted"
76
- // due to it being hidden by the Offscreen API, or during fast refresh.
77
- // At this point, the current cached resource will have been disposed
78
- // by the previous cleanup, so instead of attempting to
79
- // do our regular commit setup, which would incorrectly attempt to
80
- // retain a cached query resource that was disposed, we need to force
81
- // a re-render so that the cache entry for this query is re-intiliazed and
82
- // and re-evaluated (and potentially cause a refetch).
83
48
  maybeHiddenOrFastRefresh.current = false;
84
49
  forceUpdate(function (n) {
85
50
  return n + 1;
86
51
  });
87
52
  return;
88
53
  }
89
-
90
54
  var disposable = QueryResource.retain(preparedQueryResult, profilerContext);
91
55
  return function () {
92
56
  disposable.dispose();
93
- }; // NOTE: We disable react-hooks-deps warning because the `environment`
94
- // and `cacheIdentifier` identities are capturing all information about whether
95
- // the effect should be re-executed and the query re-retained.
96
- // eslint-disable-next-line react-hooks/exhaustive-deps
57
+ };
97
58
  }, [environment, cacheIdentifier]);
98
59
  useEffect(function () {
99
- // Release any temporary retain that's not released. At this point, if the
100
- // cacheIdentifier doesn't change, the query is still permanently retained,
101
- // and the temporary retain is redundant.
102
- QueryResource.releaseTemporaryRetain(preparedQueryResult); // This effect is intended to run on every commit, thus no dependency
60
+ QueryResource.releaseTemporaryRetain(preparedQueryResult);
103
61
  });
104
62
  var fragmentNode = preparedQueryResult.fragmentNode,
105
- fragmentRef = preparedQueryResult.fragmentRef;
106
-
63
+ fragmentRef = preparedQueryResult.fragmentRef;
107
64
  var _useFragmentNode = useFragmentNode(fragmentNode, fragmentRef, componentDisplayName),
108
- data = _useFragmentNode.data;
109
-
65
+ data = _useFragmentNode.data;
110
66
  return data;
111
67
  }
112
-
113
68
  module.exports = useLazyLoadQueryNode;
@@ -1,144 +1,101 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
5
  var useFetchTrackingRef = require('./useFetchTrackingRef');
18
-
19
6
  var useIsMountedRef = require('./useIsMountedRef');
20
-
21
7
  var useIsOperationNodeActive = require('./useIsOperationNodeActive');
22
-
23
8
  var useRelayEnvironment = require('./useRelayEnvironment');
24
-
25
9
  var invariant = require('invariant');
26
-
27
10
  var _require = require('react'),
28
- useCallback = _require.useCallback,
29
- useEffect = _require.useEffect,
30
- useState = _require.useState;
31
-
11
+ useCallback = _require.useCallback,
12
+ useEffect = _require.useEffect,
13
+ useState = _require.useState;
32
14
  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
-
15
+ fetchQuery = _require2.__internal.fetchQuery,
16
+ ConnectionInterface = _require2.ConnectionInterface,
17
+ createOperationDescriptor = _require2.createOperationDescriptor,
18
+ getPaginationVariables = _require2.getPaginationVariables,
19
+ getRefetchMetadata = _require2.getRefetchMetadata,
20
+ getSelector = _require2.getSelector,
21
+ getValueAtPath = _require2.getValueAtPath;
40
22
  var warning = require("fbjs/lib/warning");
41
-
42
23
  function useLoadMoreFunction(args) {
43
24
  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;
25
+ fragmentNode = args.fragmentNode,
26
+ fragmentRef = args.fragmentRef,
27
+ fragmentIdentifier = args.fragmentIdentifier,
28
+ fragmentData = args.fragmentData,
29
+ connectionPathInFragmentData = args.connectionPathInFragmentData,
30
+ paginationRequest = args.paginationRequest,
31
+ paginationMetadata = args.paginationMetadata,
32
+ componentDisplayName = args.componentDisplayName,
33
+ observer = args.observer,
34
+ onReset = args.onReset;
55
35
  var environment = useRelayEnvironment();
56
-
57
36
  var _useFetchTrackingRef = useFetchTrackingRef(),
58
- isFetchingRef = _useFetchTrackingRef.isFetchingRef,
59
- startFetch = _useFetchTrackingRef.startFetch,
60
- disposeFetch = _useFetchTrackingRef.disposeFetch,
61
- completeFetch = _useFetchTrackingRef.completeFetch;
62
-
63
- var identifierValue = identifierField != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierField] : null;
37
+ isFetchingRef = _useFetchTrackingRef.isFetchingRef,
38
+ startFetch = _useFetchTrackingRef.startFetch,
39
+ disposeFetch = _useFetchTrackingRef.disposeFetch,
40
+ completeFetch = _useFetchTrackingRef.completeFetch;
41
+ var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
42
+ identifierInfo = _getRefetchMetadata.identifierInfo;
43
+ var identifierValue = (identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierField) != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierInfo.identifierField] : null;
64
44
  var isMountedRef = useIsMountedRef();
65
-
66
45
  var _useState = useState(environment),
67
- mirroredEnvironment = _useState[0],
68
- setMirroredEnvironment = _useState[1];
69
-
46
+ mirroredEnvironment = _useState[0],
47
+ setMirroredEnvironment = _useState[1];
70
48
  var _useState2 = useState(fragmentIdentifier),
71
- mirroredFragmentIdentifier = _useState2[0],
72
- setMirroredFragmentIdentifier = _useState2[1];
73
-
49
+ mirroredFragmentIdentifier = _useState2[0],
50
+ setMirroredFragmentIdentifier = _useState2[1];
74
51
  var isParentQueryActive = useIsOperationNodeActive(fragmentNode, fragmentRef);
75
52
  var shouldReset = environment !== mirroredEnvironment || fragmentIdentifier !== mirroredFragmentIdentifier;
76
-
77
53
  if (shouldReset) {
78
54
  disposeFetch();
79
55
  onReset();
80
56
  setMirroredEnvironment(environment);
81
57
  setMirroredFragmentIdentifier(fragmentIdentifier);
82
58
  }
83
-
84
59
  var _getConnectionState = getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData),
85
- cursor = _getConnectionState.cursor,
86
- hasMore = _getConnectionState.hasMore; // Dispose of pagination requests in flight when unmounting
87
-
88
-
60
+ cursor = _getConnectionState.cursor,
61
+ hasMore = _getConnectionState.hasMore;
89
62
  useEffect(function () {
90
63
  return function () {
91
64
  disposeFetch();
92
65
  };
93
66
  }, [disposeFetch]);
94
67
  var loadMore = useCallback(function (count, options) {
95
- // TODO(T41131846): Fetch/Caching policies for loadMore
96
68
  var onComplete = options === null || options === void 0 ? void 0 : options.onComplete;
97
-
98
69
  if (isMountedRef.current !== true) {
99
- // Bail out and warn if we're trying to paginate after the component
100
- // has unmounted
101
70
  process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected fetch on unmounted component for fragment ' + '`%s` in `%s`. It looks like some instances of your component are ' + 'still trying to fetch data but they already unmounted. ' + 'Please make sure you clear all timers, intervals, ' + 'async calls, etc that may trigger a fetch.', fragmentNode.name, componentDisplayName) : void 0;
102
71
  return {
103
72
  dispose: function dispose() {}
104
73
  };
105
74
  }
106
-
107
75
  var fragmentSelector = getSelector(fragmentNode, fragmentRef);
108
-
109
76
  if (isFetchingRef.current === true || fragmentData == null || isParentQueryActive) {
110
77
  if (fragmentSelector == null) {
111
78
  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
79
  }
113
-
114
80
  if (onComplete) {
115
81
  onComplete(null);
116
82
  }
117
-
118
83
  return {
119
84
  dispose: function dispose() {}
120
85
  };
121
86
  }
122
-
123
87
  !(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
88
  var parentVariables = fragmentSelector.owner.variables;
125
89
  var fragmentVariables = fragmentSelector.variables;
126
90
  var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
127
91
  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.
130
-
131
- if (identifierField != null) {
132
- // @refetchable fragments are guaranteed to have an `id` selection
133
- // if the type is Node, implements Node, or is @fetchable. Double-check
134
- // that there actually is a value at runtime.
92
+ var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata);
93
+ if (identifierInfo != null) {
135
94
  if (typeof identifierValue !== 'string') {
136
- 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;
95
+ process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected result to have a string ' + '`%s` in order to refetch, got `%s`.', identifierInfo.identifierField, identifierValue) : void 0;
137
96
  }
138
-
139
- paginationVariables.id = identifierValue;
97
+ paginationVariables[identifierInfo.identifierQueryVariableName] = identifierValue;
140
98
  }
141
-
142
99
  var paginationQuery = createOperationDescriptor(paginationRequest, paginationVariables, {
143
100
  force: true
144
101
  });
@@ -161,60 +118,47 @@ function useLoadMoreFunction(args) {
161
118
  return {
162
119
  dispose: disposeFetch
163
120
  };
164
- }, // NOTE: We disable react-hooks-deps warning because all values
165
- // inside paginationMetadata are static
166
- // eslint-disable-next-line react-hooks/exhaustive-deps
167
- [environment, identifierValue, direction, cursor, startFetch, disposeFetch, completeFetch, isFetchingRef, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
121
+ }, [environment, identifierValue, direction, cursor, startFetch, disposeFetch, completeFetch, isFetchingRef, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
168
122
  return [loadMore, hasMore, disposeFetch];
169
123
  }
170
-
171
124
  function getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData) {
172
125
  var _pageInfo$END_CURSOR, _pageInfo$START_CURSO;
173
-
174
126
  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
-
127
+ EDGES = _ConnectionInterface$.EDGES,
128
+ PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
129
+ HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
130
+ HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
131
+ END_CURSOR = _ConnectionInterface$.END_CURSOR,
132
+ START_CURSOR = _ConnectionInterface$.START_CURSOR;
182
133
  var connection = getValueAtPath(fragmentData, connectionPathInFragmentData);
183
-
184
134
  if (connection == null) {
185
135
  return {
186
136
  cursor: null,
187
137
  hasMore: false
188
138
  };
189
139
  }
190
-
191
140
  !(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
141
  var edges = connection[EDGES];
193
142
  var pageInfo = connection[PAGE_INFO];
194
-
195
143
  if (edges == null || pageInfo == null) {
196
144
  return {
197
145
  cursor: null,
198
146
  hasMore: false
199
147
  };
200
148
  }
201
-
202
149
  !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
150
  !(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
151
  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
152
  !(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
153
  var hasMore;
207
-
208
154
  if (direction === 'forward') {
209
155
  hasMore = cursor != null && pageInfo[HAS_NEXT_PAGE] === true;
210
156
  } else {
211
157
  hasMore = cursor != null && pageInfo[HAS_PREV_PAGE] === true;
212
158
  }
213
-
214
159
  return {
215
160
  cursor: cursor,
216
161
  hasMore: hasMore
217
162
  };
218
163
  }
219
-
220
164
  module.exports = useLoadMoreFunction;