react-relay 15.0.0 → 16.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayQueryFetcher.js.flow +1 -5
  3. package/ReactRelayQueryRenderer.js.flow +9 -36
  4. package/ReactRelayTypes.js.flow +1 -0
  5. package/buildReactRelayContainer.js.flow +3 -1
  6. package/hooks.js +1 -1
  7. package/index.js +1 -1
  8. package/legacy.js +1 -1
  9. package/lib/ReactRelayContainerUtils.js +0 -11
  10. package/lib/ReactRelayContext.js +0 -11
  11. package/lib/ReactRelayFragmentContainer.js +6 -78
  12. package/lib/ReactRelayFragmentMockRenderer.js +0 -11
  13. package/lib/ReactRelayLocalQueryRenderer.js +0 -17
  14. package/lib/ReactRelayPaginationContainer.js +5 -208
  15. package/lib/ReactRelayQueryFetcher.js +2 -51
  16. package/lib/ReactRelayQueryRenderer.js +6 -94
  17. package/lib/ReactRelayQueryRendererContext.js +0 -11
  18. package/lib/ReactRelayRefetchContainer.js +5 -91
  19. package/lib/ReactRelayTestMocker.js +9 -85
  20. package/lib/ReactRelayTypes.js +0 -11
  21. package/lib/RelayContext.js +0 -21
  22. package/lib/assertFragmentMap.js +0 -15
  23. package/lib/buildReactRelayContainer.js +0 -19
  24. package/lib/getRootVariablesForFragments.js +0 -14
  25. package/lib/hooks.js +0 -15
  26. package/lib/index.js +0 -17
  27. package/lib/isRelayEnvironment.js +1 -18
  28. package/lib/jest-react/enqueueTask.js +0 -20
  29. package/lib/jest-react/internalAct.js +0 -38
  30. package/lib/legacy.js +0 -15
  31. package/lib/multi-actor/ActorChange.js +0 -11
  32. package/lib/multi-actor/index.js +0 -11
  33. package/lib/multi-actor/useRelayActorEnvironment.js +0 -11
  34. package/lib/relay-hooks/EntryPointContainer.react.js +0 -11
  35. package/lib/relay-hooks/EntryPointTypes.flow.js +1 -14
  36. package/lib/relay-hooks/FragmentResource.js +76 -132
  37. package/lib/relay-hooks/HooksImplementation.js +1 -12
  38. package/lib/relay-hooks/InternalLogger.js +0 -11
  39. package/lib/relay-hooks/LRUCache.js +0 -22
  40. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -18
  41. package/lib/relay-hooks/MatchContainer.js +0 -94
  42. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  43. package/lib/relay-hooks/ProfilerContext.js +0 -15
  44. package/lib/relay-hooks/QueryResource.js +2 -68
  45. package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -11
  46. package/lib/relay-hooks/SuspenseResource.js +0 -34
  47. package/lib/relay-hooks/{react-cache/readFragmentInternal_REACT_CACHE.js → experimental/readFragmentInternal_EXPERIMENTAL.js} +5 -29
  48. package/lib/relay-hooks/{react-cache/useFragmentInternal_REACT_CACHE.js → experimental/useFragmentInternal_EXPERIMENTAL.js} +35 -100
  49. package/lib/relay-hooks/{react-cache/useFragment_REACT_CACHE.js → experimental/useFragment_EXPERIMENTAL.js} +1 -16
  50. package/lib/relay-hooks/{react-cache/usePaginationFragment_REACT_CACHE.js → experimental/usePaginationFragment_EXPERIMENTAL.js} +2 -24
  51. package/lib/relay-hooks/{react-cache/useRefetchableFragmentInternal_REACT_CACHE.js → experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js} +14 -98
  52. package/lib/relay-hooks/{react-cache/useRefetchableFragment_REACT_CACHE.js → experimental/useRefetchableFragment_EXPERIMENTAL.js} +1 -15
  53. package/lib/relay-hooks/loadEntryPoint.js +1 -24
  54. package/lib/relay-hooks/loadQuery.js +2 -106
  55. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +2 -27
  56. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -13
  57. package/lib/relay-hooks/useBlockingPaginationFragment.js +0 -42
  58. package/lib/relay-hooks/useClientQuery.js +0 -18
  59. package/lib/relay-hooks/useEntryPointLoader.js +0 -69
  60. package/lib/relay-hooks/useFetchTrackingRef.js +0 -26
  61. package/lib/relay-hooks/useFragment.js +0 -17
  62. package/lib/relay-hooks/useFragmentNode.js +2 -32
  63. package/lib/relay-hooks/useIsMountedRef.js +0 -11
  64. package/lib/relay-hooks/useIsOperationNodeActive.js +0 -11
  65. package/lib/relay-hooks/useIsParentQueryActive.js +0 -11
  66. package/lib/relay-hooks/useLazyLoadQuery.js +0 -18
  67. package/lib/relay-hooks/useLazyLoadQueryNode.js +12 -37
  68. package/lib/relay-hooks/useLoadMoreFunction.js +9 -34
  69. package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -11
  70. package/lib/relay-hooks/useMemoVariables.js +0 -17
  71. package/lib/relay-hooks/useMutation.js +0 -11
  72. package/lib/relay-hooks/usePaginationFragment.js +1 -26
  73. package/lib/relay-hooks/usePreloadedQuery.js +0 -27
  74. package/lib/relay-hooks/useQueryLoader.js +0 -74
  75. package/lib/relay-hooks/useRefetchableFragment.js +0 -16
  76. package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -97
  77. package/lib/relay-hooks/useRelayEnvironment.js +0 -11
  78. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -15
  79. package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -25
  80. package/lib/relay-hooks/useSubscription.js +0 -15
  81. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +0 -17
  82. package/package.json +2 -2
  83. package/react-relay-hooks.js +2 -2
  84. package/react-relay-hooks.min.js +2 -2
  85. package/react-relay-legacy.js +2 -2
  86. package/react-relay-legacy.min.js +2 -2
  87. package/react-relay.js +2 -2
  88. package/react-relay.min.js +2 -2
  89. package/relay-hooks/EntryPointContainer.react.js.flow +5 -0
  90. package/relay-hooks/EntryPointTypes.flow.js.flow +34 -35
  91. package/relay-hooks/FragmentResource.js.flow +114 -26
  92. package/relay-hooks/HooksImplementation.js.flow +3 -1
  93. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -2
  94. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  95. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +7 -5
  96. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +5 -0
  97. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +5 -0
  98. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +2 -0
  99. package/relay-hooks/{react-cache/readFragmentInternal_REACT_CACHE.js.flow → experimental/readFragmentInternal_EXPERIMENTAL.js.flow} +4 -3
  100. package/relay-hooks/{react-cache/useFragmentInternal_REACT_CACHE.js.flow → experimental/useFragmentInternal_EXPERIMENTAL.js.flow} +32 -14
  101. package/relay-hooks/{react-cache/useFragment_REACT_CACHE.js.flow → experimental/useFragment_EXPERIMENTAL.js.flow} +4 -10
  102. package/relay-hooks/{react-cache/usePaginationFragment_REACT_CACHE.js.flow → experimental/usePaginationFragment_EXPERIMENTAL.js.flow} +30 -59
  103. package/relay-hooks/{react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow → experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow} +30 -23
  104. package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +49 -0
  105. package/relay-hooks/loadEntryPoint.js.flow +4 -2
  106. package/relay-hooks/loadQuery.js.flow +21 -1
  107. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -2
  108. package/relay-hooks/useBlockingPaginationFragment.js.flow +10 -17
  109. package/relay-hooks/useClientQuery.js.flow +2 -2
  110. package/relay-hooks/useFragmentNode.js.flow +2 -2
  111. package/relay-hooks/useLazyLoadQueryNode.js.flow +17 -1
  112. package/relay-hooks/useLoadMoreFunction.js.flow +15 -9
  113. package/relay-hooks/useMutation.js.flow +26 -9
  114. package/relay-hooks/usePaginationFragment.js.flow +7 -15
  115. package/relay-hooks/useQueryLoader.js.flow +2 -8
  116. package/relay-hooks/useRefetchableFragment.js.flow +14 -16
  117. package/relay-hooks/useRefetchableFragmentNode.js.flow +33 -20
  118. package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -32
  119. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +0 -290
  120. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -49
  121. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -110
  122. package/relay-hooks/react-cache/RelayReactCache.js.flow +0 -40
  123. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +0 -430
  124. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +0 -70
  125. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +0 -150
  126. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +0 -65
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var HooksImplementation = require('./HooksImplementation');
@@ -21,15 +10,12 @@ var _require2 = require('react'),
21
10
  var _require3 = require('relay-runtime'),
22
11
  getFragment = _require3.getFragment;
23
12
  function useFragment_LEGACY(fragment, key) {
24
- // We need to use this hook in order to be able to track if
25
- // loadQuery was called during render
26
13
  useTrackLoadQueryInRender();
27
14
  var fragmentNode = getFragment(fragment);
28
15
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
29
16
  var _useFragmentNode = useFragmentNode(fragmentNode, key, 'useFragment()'),
30
17
  data = _useFragmentNode.data;
31
18
  if (process.env.NODE_ENV !== "production") {
32
- // eslint-disable-next-line react-hooks/rules-of-hooks
33
19
  useDebugValue({
34
20
  fragment: fragmentNode.name,
35
21
  data: data
@@ -40,11 +26,8 @@ function useFragment_LEGACY(fragment, key) {
40
26
  function useFragment(fragment, key) {
41
27
  var impl = HooksImplementation.get();
42
28
  if (impl) {
43
- // $FlowFixMe This is safe because impl.useFragment has the type of useFragment...
44
29
  return impl.useFragment(fragment, key);
45
- // (i.e. type declared above, but not the supertype used in this function definition)
46
30
  } else {
47
- // eslint-disable-next-line react-hooks/rules-of-hooks
48
31
  return useFragment_LEGACY(fragment, key);
49
32
  }
50
33
  }
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _require = require('./FragmentResource'),
@@ -19,6 +8,7 @@ var _require2 = require('react'),
19
8
  useEffect = _require2.useEffect,
20
9
  useState = _require2.useState;
21
10
  var _require3 = require('relay-runtime'),
11
+ RelayFeatureFlags = _require3.RelayFeatureFlags,
22
12
  getFragmentIdentifier = _require3.getFragmentIdentifier;
23
13
  var warning = require("fbjs/lib/warning");
24
14
  function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
@@ -28,8 +18,6 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
28
18
  var _useState = useState(0),
29
19
  forceUpdate = _useState[1];
30
20
  var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
31
-
32
- // Read fragment data; this might suspend.
33
21
  var fragmentResult = FragmentResource.readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName);
34
22
  var isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
35
23
  function enableStoreUpdates() {
@@ -46,36 +34,19 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
46
34
  if (isMountedRef.current === false || isListeningForUpdatesRef.current === false) {
47
35
  return;
48
36
  }
49
-
50
- // React bails out on noop state updates as an optimization.
51
- // If we want to force an update via setState, we need to pass an value.
52
- // The actual value can be arbitrary though, e.g. an incremented number.
53
37
  forceUpdate(function (count) {
54
38
  return count + 1;
55
39
  });
56
40
  }
57
-
58
- // Establish Relay store subscriptions in the commit phase, only if
59
- // rendering for the first time, or if we need to subscribe to new data
60
- // If the fragment identifier changes, it means that the variables on the
61
- // fragment owner changed, or the fragment ref points to different records.
62
- // In this case, we need to resubscribe to the Relay store.
63
41
  useEffect(function () {
64
42
  isMountedRef.current = true;
65
43
  var disposable = FragmentResource.subscribe(fragmentResult, handleDataUpdate);
66
44
  return function () {
67
- // When unmounting or resubscribing to new data, clean up current
68
- // subscription. This will also make sure fragment data is no longer
69
- // cached so that next time it its read, it will be freshly read from
70
- // the Relay store
71
45
  isMountedRef.current = false;
72
46
  disposable.dispose();
73
47
  };
74
- // NOTE: We disable react-hooks-deps warning because environment and fragmentIdentifier
75
- // is capturing all information about whether the effect should be re-ran.
76
- // eslint-disable-next-line react-hooks/exhaustive-deps
77
48
  }, [environment, fragmentIdentifier]);
78
- if (process.env.NODE_ENV !== "production") {
49
+ if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
79
50
  if (fragmentRef != null && (fragmentResult.data === undefined || Array.isArray(fragmentResult.data) && fragmentResult.data.length > 0 && fragmentResult.data.every(function (data) {
80
51
  return data === undefined;
81
52
  }))) {
@@ -83,7 +54,6 @@ function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
83
54
  }
84
55
  }
85
56
  return {
86
- // $FlowFixMe[incompatible-return]
87
57
  data: fragmentResult.data,
88
58
  disableStoreUpdates: disableStoreUpdates,
89
59
  enableStoreUpdates: enableStoreUpdates
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _require = require('react'),
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var useRelayEnvironment = require('./useRelayEnvironment');
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var useIsOperationNodeActive = require('./useIsOperationNodeActive');
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _require = require('./loadQuery'),
@@ -18,14 +7,7 @@ var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
18
7
  var useRelayEnvironment = require('./useRelayEnvironment');
19
8
  var _require2 = require('relay-runtime'),
20
9
  fetchQuery = _require2.__internal.fetchQuery;
21
-
22
- // This separate type export is only needed as long as we are injecting
23
- // a separate hooks implementation in ./HooksImplementation -- it can
24
- // be removed after we stop doing that.
25
-
26
10
  function useLazyLoadQuery(gqlQuery, variables, options) {
27
- // We need to use this hook in order to be able to track if
28
- // loadQuery was called during render
29
11
  useTrackLoadQueryInRender();
30
12
  var environment = useRelayEnvironment();
31
13
  var query = useMemoOperationDescriptor(gqlQuery, variables, options && options.networkCacheConfig ? options.networkCacheConfig : {
@@ -1,16 +1,6 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
3
+ var HooksImplementation = require('./HooksImplementation');
14
4
  var ProfilerContext = require('./ProfilerContext');
15
5
  var _require = require('./QueryResource'),
16
6
  getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
@@ -51,26 +41,11 @@ function useLazyLoadQueryNode(_ref) {
51
41
  var maybeHiddenOrFastRefresh = useRef(false);
52
42
  useEffect(function () {
53
43
  return function () {
54
- // Attempt to detect if the component was
55
- // hidden (by Offscreen API), or fast refresh occured;
56
- // Only in these situations would the effect cleanup
57
- // for "unmounting" run multiple times, so if
58
- // we are ever able to read this ref with a value
59
- // of true, it means that one of these cases
60
- // has happened.
61
44
  maybeHiddenOrFastRefresh.current = true;
62
45
  };
63
46
  }, []);
64
47
  useEffect(function () {
65
48
  if (maybeHiddenOrFastRefresh.current === true) {
66
- // This block only runs if the component has previously "unmounted"
67
- // due to it being hidden by the Offscreen API, or during fast refresh.
68
- // At this point, the current cached resource will have been disposed
69
- // by the previous cleanup, so instead of attempting to
70
- // do our regular commit setup, which would incorrectly attempt to
71
- // retain a cached query resource that was disposed, we need to force
72
- // a re-render so that the cache entry for this query is re-intiliazed and
73
- // and re-evaluated (and potentially cause a refetch).
74
49
  maybeHiddenOrFastRefresh.current = false;
75
50
  forceUpdate(function (n) {
76
51
  return n + 1;
@@ -81,23 +56,23 @@ function useLazyLoadQueryNode(_ref) {
81
56
  return function () {
82
57
  disposable.dispose();
83
58
  };
84
- // NOTE: We disable react-hooks-deps warning because the `environment`
85
- // and `cacheIdentifier` identities are capturing all information about whether
86
- // the effect should be re-executed and the query re-retained.
87
- // eslint-disable-next-line react-hooks/exhaustive-deps
88
59
  }, [environment, cacheIdentifier]);
89
60
  useEffect(function () {
90
- // Release any temporary retain that's not released. At this point, if the
91
- // cacheIdentifier doesn't change, the query is still permanently retained,
92
- // and the temporary retain is redundant.
93
61
  QueryResource.releaseTemporaryRetain(preparedQueryResult);
94
- // This effect is intended to run on every commit, thus no dependency
95
62
  });
96
-
97
63
  var fragmentNode = preparedQueryResult.fragmentNode,
98
64
  fragmentRef = preparedQueryResult.fragmentRef;
99
- var _useFragmentNode = useFragmentNode(fragmentNode, fragmentRef, componentDisplayName),
100
- data = _useFragmentNode.data;
65
+ var data = useFragmentNodeImpl(fragmentNode, fragmentRef, componentDisplayName);
101
66
  return data;
102
67
  }
68
+ function useFragmentNodeImpl(fragment, key, componentDisplayName) {
69
+ var impl = HooksImplementation.get();
70
+ if (impl && impl.useFragment__internal) {
71
+ return impl.useFragment__internal(fragment, key, componentDisplayName);
72
+ } else {
73
+ var _useFragmentNode = useFragmentNode(fragment, key, componentDisplayName),
74
+ data = _useFragmentNode.data;
75
+ return data;
76
+ }
77
+ }
103
78
  module.exports = useLazyLoadQueryNode;
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -27,6 +16,7 @@ var _require2 = require('relay-runtime'),
27
16
  ConnectionInterface = _require2.ConnectionInterface,
28
17
  createOperationDescriptor = _require2.createOperationDescriptor,
29
18
  getPaginationVariables = _require2.getPaginationVariables,
19
+ getRefetchMetadata = _require2.getRefetchMetadata,
30
20
  getSelector = _require2.getSelector,
31
21
  getValueAtPath = _require2.getValueAtPath;
32
22
  var warning = require("fbjs/lib/warning");
@@ -41,15 +31,16 @@ function useLoadMoreFunction(args) {
41
31
  paginationMetadata = args.paginationMetadata,
42
32
  componentDisplayName = args.componentDisplayName,
43
33
  observer = args.observer,
44
- onReset = args.onReset,
45
- identifierField = args.identifierField;
34
+ onReset = args.onReset;
46
35
  var environment = useRelayEnvironment();
47
36
  var _useFetchTrackingRef = useFetchTrackingRef(),
48
37
  isFetchingRef = _useFetchTrackingRef.isFetchingRef,
49
38
  startFetch = _useFetchTrackingRef.startFetch,
50
39
  disposeFetch = _useFetchTrackingRef.disposeFetch,
51
40
  completeFetch = _useFetchTrackingRef.completeFetch;
52
- var identifierValue = identifierField != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierField] : null;
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;
53
44
  var isMountedRef = useIsMountedRef();
54
45
  var _useState = useState(environment),
55
46
  mirroredEnvironment = _useState[0],
@@ -68,20 +59,14 @@ function useLoadMoreFunction(args) {
68
59
  var _getConnectionState = getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData),
69
60
  cursor = _getConnectionState.cursor,
70
61
  hasMore = _getConnectionState.hasMore;
71
-
72
- // Dispose of pagination requests in flight when unmounting
73
62
  useEffect(function () {
74
63
  return function () {
75
64
  disposeFetch();
76
65
  };
77
66
  }, [disposeFetch]);
78
67
  var loadMore = useCallback(function (count, options) {
79
- // TODO(T41131846): Fetch/Caching policies for loadMore
80
-
81
68
  var onComplete = options === null || options === void 0 ? void 0 : options.onComplete;
82
69
  if (isMountedRef.current !== true) {
83
- // Bail out and warn if we're trying to paginate after the component
84
- // has unmounted
85
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;
86
71
  return {
87
72
  dispose: function dispose() {}
@@ -105,17 +90,11 @@ function useLoadMoreFunction(args) {
105
90
  var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
106
91
  var baseVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables);
107
92
  var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata);
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.
111
- if (identifierField != null) {
112
- // @refetchable fragments are guaranteed to have an `id` selection
113
- // if the type is Node, implements Node, or is @fetchable. Double-check
114
- // that there actually is a value at runtime.
93
+ if (identifierInfo != null) {
115
94
  if (typeof identifierValue !== 'string') {
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;
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;
117
96
  }
118
- paginationVariables.id = identifierValue;
97
+ paginationVariables[identifierInfo.identifierQueryVariableName] = identifierValue;
119
98
  }
120
99
  var paginationQuery = createOperationDescriptor(paginationRequest, paginationVariables, {
121
100
  force: true
@@ -139,11 +118,7 @@ function useLoadMoreFunction(args) {
139
118
  return {
140
119
  dispose: disposeFetch
141
120
  };
142
- },
143
- // NOTE: We disable react-hooks-deps warning because all values
144
- // inside paginationMetadata are static
145
- // eslint-disable-next-line react-hooks/exhaustive-deps
146
- [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]);
147
122
  return [loadMore, hasMore, disposeFetch];
148
123
  }
149
124
  function getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData) {
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var useMemoVariables = require('./useMemoVariables');
@@ -1,25 +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
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var areEqual = require("fbjs/lib/areEqual");
15
4
  var _require = require('react'),
16
5
  useState = _require.useState;
17
-
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
- */
23
6
  function useMemoVariables(variables) {
24
7
  var _useState = useState(variables),
25
8
  mirroredVariables = _useState[0],
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -25,11 +14,6 @@ var _require2 = require('relay-runtime'),
25
14
  getFragment = _require2.getFragment,
26
15
  getFragmentIdentifier = _require2.getFragmentIdentifier,
27
16
  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.
32
-
33
17
  function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
34
18
  var fragmentNode = getFragment(fragmentInput);
35
19
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePaginationFragment()');
@@ -37,15 +21,12 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
37
21
  var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
38
22
  connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
39
23
  paginationRequest = _getPaginationMetadat.paginationRequest,
40
- paginationMetadata = _getPaginationMetadat.paginationMetadata,
41
- identifierField = _getPaginationMetadat.identifierField;
24
+ paginationMetadata = _getPaginationMetadat.paginationMetadata;
42
25
  var _useRefetchableFragme = useRefetchableFragmentNode(fragmentNode, parentFragmentRef, componentDisplayName),
43
26
  fragmentData = _useRefetchableFragme.fragmentData,
44
27
  fragmentRef = _useRefetchableFragme.fragmentRef,
45
28
  refetch = _useRefetchableFragme.refetch;
46
29
  var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
47
-
48
- // Backward pagination
49
30
  var _useLoadMore = useLoadMore({
50
31
  componentDisplayName: componentDisplayName,
51
32
  connectionPathInFragmentData: connectionPathInFragmentData,
@@ -54,7 +35,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
54
35
  fragmentIdentifier: fragmentIdentifier,
55
36
  fragmentNode: fragmentNode,
56
37
  fragmentRef: fragmentRef,
57
- identifierField: identifierField,
58
38
  paginationMetadata: paginationMetadata,
59
39
  paginationRequest: paginationRequest
60
40
  }),
@@ -62,8 +42,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
62
42
  hasPrevious = _useLoadMore[1],
63
43
  isLoadingPrevious = _useLoadMore[2],
64
44
  disposeFetchPrevious = _useLoadMore[3];
65
-
66
- // Forward pagination
67
45
  var _useLoadMore2 = useLoadMore({
68
46
  componentDisplayName: componentDisplayName,
69
47
  connectionPathInFragmentData: connectionPathInFragmentData,
@@ -72,7 +50,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
72
50
  fragmentIdentifier: fragmentIdentifier,
73
51
  fragmentNode: fragmentNode,
74
52
  fragmentRef: fragmentRef,
75
- identifierField: identifierField,
76
53
  paginationMetadata: paginationMetadata,
77
54
  paginationRequest: paginationRequest
78
55
  }),
@@ -88,7 +65,6 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
88
65
  }));
89
66
  }, [disposeFetchNext, disposeFetchPrevious, refetch]);
90
67
  if (process.env.NODE_ENV !== "production") {
91
- // eslint-disable-next-line react-hooks/rules-of-hooks
92
68
  useDebugValue({
93
69
  fragment: fragmentNode.name,
94
70
  data: fragmentData,
@@ -141,7 +117,6 @@ function usePaginationFragment(fragmentInput, parentFragmentRef) {
141
117
  if (impl) {
142
118
  return impl.usePaginationFragment(fragmentInput, parentFragmentRef);
143
119
  } else {
144
- // eslint-disable-next-line react-hooks/rules-of-hooks
145
120
  return usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef);
146
121
  }
147
122
  }
@@ -1,14 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _require = require('./loadQuery'),
@@ -25,8 +14,6 @@ var _require3 = require('relay-runtime'),
25
14
  fetchQuery = _require3$__internal.fetchQuery;
26
15
  var warning = require("fbjs/lib/warning");
27
16
  function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
28
- // We need to use this hook in order to be able to track if
29
- // loadQuery was called during render
30
17
  useTrackLoadQueryInRender();
31
18
  var environment = useRelayEnvironment();
32
19
  var fetchKey = preloadedQuery.fetchKey,
@@ -62,24 +49,11 @@ function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
62
49
  var fallbackFetchObservable = fetchQuery(environment, operation);
63
50
  var fetchObservable;
64
51
  if (source != null && environment === preloadedQuery.environment) {
65
- // If the source observable exists and the environments match, reuse
66
- // the source observable.
67
- // If the source observable happens to be empty, we need to fall back
68
- // and re-execute and de-dupe the query (at render time).
69
52
  fetchObservable = source.ifEmpty(fallbackFetchObservable);
70
53
  } else if (environment !== preloadedQuery.environment) {
71
- // If a call to loadQuery is made with a particular environment, and that
72
- // preloaded query is passed to usePreloadedQuery in a different environment
73
- // context, we cannot re-use the existing preloaded query.
74
- // Instead, we need to fall back and re-execute and de-dupe the query with
75
- // the new environment (at render time).
76
- // TODO T68036756 track occurences of this warning and turn it into a hard error
77
54
  process.env.NODE_ENV !== "production" ? warning(false, 'usePreloadedQuery(): usePreloadedQuery was passed a preloaded query ' + 'that was created with a different environment than the one that is currently ' + 'in context. In the future, this will become a hard error.') : void 0;
78
55
  fetchObservable = fallbackFetchObservable;
79
56
  } else {
80
- // if (source == null)
81
- // If the source observable does not exist, we need to
82
- // fall back and re-execute and de-dupe the query (at render time).
83
57
  fetchObservable = fallbackFetchObservable;
84
58
  }
85
59
  useLazyLoadQueryNodeParams = {
@@ -93,7 +67,6 @@ function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
93
67
  }
94
68
  var data = useLazyLoadQueryNode(useLazyLoadQueryNodeParams);
95
69
  if (process.env.NODE_ENV !== "production") {
96
- // eslint-disable-next-line react-hooks/rules-of-hooks
97
70
  useDebugValue({
98
71
  query: preloadedQuery.name,
99
72
  variables: preloadedQuery.variables,