react-relay 11.0.2 → 13.0.0-rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. package/README.md +47 -0
  2. package/ReactRelayContainerUtils.js.flow +1 -1
  3. package/ReactRelayContext.js +1 -1
  4. package/ReactRelayContext.js.flow +3 -4
  5. package/ReactRelayFragmentContainer.js.flow +25 -25
  6. package/ReactRelayFragmentMockRenderer.js.flow +2 -2
  7. package/ReactRelayLocalQueryRenderer.js.flow +7 -8
  8. package/ReactRelayPaginationContainer.js.flow +112 -59
  9. package/ReactRelayQueryFetcher.js.flow +10 -11
  10. package/ReactRelayQueryRenderer.js.flow +116 -82
  11. package/ReactRelayQueryRendererContext.js.flow +1 -1
  12. package/ReactRelayRefetchContainer.js.flow +42 -39
  13. package/ReactRelayTestMocker.js.flow +17 -15
  14. package/ReactRelayTypes.js.flow +11 -11
  15. package/RelayContext.js.flow +4 -4
  16. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
  17. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +12 -8
  18. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +11 -7
  19. package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
  20. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
  21. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
  22. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
  23. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
  25. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
  27. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
  29. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
  30. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
  31. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
  32. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
  33. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
  34. package/assertFragmentMap.js.flow +3 -3
  35. package/buildReactRelayContainer.js.flow +12 -11
  36. package/getRootVariablesForFragments.js.flow +3 -5
  37. package/hooks.js +1 -1
  38. package/hooks.js.flow +6 -7
  39. package/index.js +1 -1
  40. package/index.js.flow +7 -8
  41. package/isRelayEnvironment.js.flow +1 -1
  42. package/jest-react/enqueueTask.js.flow +56 -0
  43. package/jest-react/index.js.flow +12 -0
  44. package/jest-react/internalAct.js.flow +138 -0
  45. package/legacy.js +1 -1
  46. package/legacy.js.flow +1 -1
  47. package/lib/ReactRelayContainerUtils.js +1 -1
  48. package/lib/ReactRelayContext.js +1 -1
  49. package/lib/ReactRelayFragmentContainer.js +22 -16
  50. package/lib/ReactRelayFragmentMockRenderer.js +3 -3
  51. package/lib/ReactRelayLocalQueryRenderer.js +8 -9
  52. package/lib/ReactRelayPaginationContainer.js +97 -39
  53. package/lib/ReactRelayQueryFetcher.js +3 -3
  54. package/lib/ReactRelayQueryRenderer.js +87 -54
  55. package/lib/ReactRelayQueryRendererContext.js +1 -1
  56. package/lib/ReactRelayRefetchContainer.js +39 -26
  57. package/lib/ReactRelayTestMocker.js +8 -9
  58. package/lib/ReactRelayTypes.js +1 -1
  59. package/lib/RelayContext.js +4 -3
  60. package/lib/assertFragmentMap.js +3 -2
  61. package/lib/buildReactRelayContainer.js +8 -8
  62. package/lib/getRootVariablesForFragments.js +2 -3
  63. package/lib/hooks.js +6 -6
  64. package/lib/index.js +8 -8
  65. package/lib/isRelayEnvironment.js +1 -1
  66. package/lib/jest-react/enqueueTask.js +53 -0
  67. package/lib/jest-react/index.js +13 -0
  68. package/lib/jest-react/internalAct.js +115 -0
  69. package/lib/legacy.js +1 -1
  70. package/lib/multi-actor/ActorChange.js +30 -0
  71. package/lib/multi-actor/index.js +11 -0
  72. package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
  73. package/lib/readContext.js +1 -1
  74. package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
  75. package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
  76. package/lib/relay-hooks/FragmentResource.js +342 -89
  77. package/lib/relay-hooks/InternalLogger.js +1 -1
  78. package/lib/relay-hooks/LRUCache.js +1 -1
  79. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
  80. package/lib/relay-hooks/MatchContainer.js +2 -2
  81. package/lib/relay-hooks/ProfilerContext.js +1 -1
  82. package/lib/relay-hooks/QueryResource.js +172 -29
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +6 -4
  84. package/lib/relay-hooks/SuspenseResource.js +130 -0
  85. package/lib/relay-hooks/loadEntryPoint.js +1 -1
  86. package/lib/relay-hooks/loadQuery.js +42 -20
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -16
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
  89. package/lib/relay-hooks/useBlockingPaginationFragment.js +5 -6
  90. package/lib/relay-hooks/useEntryPointLoader.js +3 -3
  91. package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
  92. package/lib/relay-hooks/useFragment.js +7 -7
  93. package/lib/relay-hooks/useFragmentNode.js +5 -5
  94. package/lib/relay-hooks/useIsMountedRef.js +1 -1
  95. package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
  96. package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
  97. package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
  98. package/lib/relay-hooks/useLazyLoadQueryNode.js +11 -5
  99. package/lib/relay-hooks/useLoadMoreFunction.js +9 -13
  100. package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
  101. package/lib/relay-hooks/useMemoVariables.js +3 -3
  102. package/lib/relay-hooks/useMutation.js +18 -7
  103. package/lib/relay-hooks/usePaginationFragment.js +3 -4
  104. package/lib/relay-hooks/usePreloadedQuery.js +6 -6
  105. package/lib/relay-hooks/useQueryLoader.js +31 -11
  106. package/lib/relay-hooks/useRefetchableFragment.js +1 -1
  107. package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -18
  108. package/lib/relay-hooks/useRelayEnvironment.js +3 -3
  109. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
  110. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
  111. package/lib/relay-hooks/useSubscription.js +11 -8
  112. package/multi-actor/ActorChange.js.flow +58 -0
  113. package/multi-actor/index.js.flow +14 -0
  114. package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
  115. package/package.json +3 -3
  116. package/react-relay-hooks.js +2 -2
  117. package/react-relay-hooks.min.js +2 -2
  118. package/react-relay-legacy.js +2 -2
  119. package/react-relay-legacy.min.js +2 -2
  120. package/react-relay.js +2 -2
  121. package/react-relay.min.js +2 -2
  122. package/readContext.js.flow +1 -1
  123. package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
  124. package/relay-hooks/EntryPointTypes.flow.js.flow +25 -26
  125. package/relay-hooks/FragmentResource.js.flow +359 -93
  126. package/relay-hooks/InternalLogger.js.flow +1 -1
  127. package/relay-hooks/LRUCache.js.flow +1 -1
  128. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
  129. package/relay-hooks/MatchContainer.js.flow +4 -3
  130. package/relay-hooks/ProfilerContext.js.flow +1 -1
  131. package/relay-hooks/QueryResource.js.flow +217 -26
  132. package/relay-hooks/RelayEnvironmentProvider.js.flow +15 -5
  133. package/relay-hooks/SuspenseResource.js.flow +115 -0
  134. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
  135. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  136. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
  137. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
  138. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
  139. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
  140. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
  141. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
  142. package/relay-hooks/__flowtests__/utils.js.flow +21 -32
  143. package/relay-hooks/loadEntryPoint.js.flow +7 -13
  144. package/relay-hooks/loadQuery.js.flow +50 -32
  145. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +31 -22
  146. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
  147. package/relay-hooks/useBlockingPaginationFragment.js.flow +14 -12
  148. package/relay-hooks/useEntryPointLoader.js.flow +8 -11
  149. package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
  150. package/relay-hooks/useFragment.js.flow +31 -62
  151. package/relay-hooks/useFragmentNode.js.flow +6 -8
  152. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  153. package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
  154. package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
  155. package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
  156. package/relay-hooks/useLazyLoadQueryNode.js.flow +20 -14
  157. package/relay-hooks/useLoadMoreFunction.js.flow +21 -30
  158. package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
  159. package/relay-hooks/useMemoVariables.js.flow +7 -7
  160. package/relay-hooks/useMutation.js.flow +27 -27
  161. package/relay-hooks/usePaginationFragment.js.flow +39 -45
  162. package/relay-hooks/usePreloadedQuery.js.flow +14 -20
  163. package/relay-hooks/useQueryLoader.js.flow +42 -23
  164. package/relay-hooks/useRefetchableFragment.js.flow +8 -9
  165. package/relay-hooks/useRefetchableFragmentNode.js.flow +25 -33
  166. package/relay-hooks/useRelayEnvironment.js.flow +3 -5
  167. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
  168. package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
  169. package/relay-hooks/useSubscription.js.flow +21 -11
  170. package/lib/relay-hooks/getPaginationMetadata.js +0 -41
  171. package/lib/relay-hooks/getPaginationVariables.js +0 -67
  172. package/lib/relay-hooks/getRefetchMetadata.js +0 -36
  173. package/lib/relay-hooks/getValueAtPath.js +0 -51
  174. package/relay-hooks/getPaginationMetadata.js.flow +0 -74
  175. package/relay-hooks/getPaginationVariables.js.flow +0 -110
  176. package/relay-hooks/getRefetchMetadata.js.flow +0 -80
  177. package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -13,34 +13,32 @@
13
13
 
14
14
  'use strict';
15
15
 
16
+ import type {
17
+ CacheConfig,
18
+ FetchPolicy,
19
+ Query,
20
+ RenderPolicy,
21
+ Variables,
22
+ } from 'relay-runtime';
23
+
24
+ const {useTrackLoadQueryInRender} = require('./loadQuery');
16
25
  const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
17
26
  const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
18
27
  const useRelayEnvironment = require('./useRelayEnvironment');
19
-
20
- const {useTrackLoadQueryInRender} = require('./loadQuery');
21
28
  const {
22
29
  __internal: {fetchQuery},
23
30
  } = require('relay-runtime');
24
31
 
25
- import type {
26
- CacheConfig,
27
- FetchPolicy,
28
- GraphQLTaggedNode,
29
- OperationType,
30
- RenderPolicy,
31
- VariablesOf,
32
- } from 'relay-runtime';
33
-
34
- function useLazyLoadQuery<TQuery: OperationType>(
35
- gqlQuery: GraphQLTaggedNode,
36
- variables: VariablesOf<TQuery>,
32
+ function useLazyLoadQuery<TVariables: Variables, TData>(
33
+ gqlQuery: Query<TVariables, TData>,
34
+ variables: TVariables,
37
35
  options?: {|
38
36
  fetchKey?: string | number,
39
37
  fetchPolicy?: FetchPolicy,
40
38
  networkCacheConfig?: CacheConfig,
41
39
  UNSTABLE_renderPolicy?: RenderPolicy,
42
40
  |},
43
- ): $ElementType<TQuery, 'response'> {
41
+ ): TData {
44
42
  // We need to use this hook in order to be able to track if
45
43
  // loadQuery was called during render
46
44
  useTrackLoadQueryInRender();
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -13,18 +13,6 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const ProfilerContext = require('./ProfilerContext');
17
- const React = require('react');
18
-
19
- const useFetchTrackingRef = require('./useFetchTrackingRef');
20
- const useFragmentNode = require('./useFragmentNode');
21
- const useRelayEnvironment = require('./useRelayEnvironment');
22
-
23
- const {
24
- getQueryResourceForEnvironment,
25
- getQueryCacheIdentifier,
26
- } = require('./QueryResource');
27
-
28
16
  import type {
29
17
  FetchPolicy,
30
18
  GraphQLResponse,
@@ -34,6 +22,16 @@ import type {
34
22
  RenderPolicy,
35
23
  } from 'relay-runtime';
36
24
 
25
+ const ProfilerContext = require('./ProfilerContext');
26
+ const {
27
+ getQueryCacheIdentifier,
28
+ getQueryResourceForEnvironment,
29
+ } = require('./QueryResource');
30
+ const useFetchTrackingRef = require('./useFetchTrackingRef');
31
+ const useFragmentNode = require('./useFragmentNode');
32
+ const useRelayEnvironment = require('./useRelayEnvironment');
33
+ const React = require('react');
34
+
37
35
  const {useContext, useEffect, useState, useRef} = React;
38
36
 
39
37
  function useLazyLoadQueryNode<TQuery: OperationType>({
@@ -50,7 +48,7 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
50
48
  fetchPolicy?: ?FetchPolicy,
51
49
  fetchKey?: ?string | ?number,
52
50
  renderPolicy?: ?RenderPolicy,
53
- |}): $ElementType<TQuery, 'response'> {
51
+ |}): TQuery['response'] {
54
52
  const environment = useRelayEnvironment();
55
53
  const profilerContext = useContext(ProfilerContext);
56
54
  const QueryResource = getQueryResourceForEnvironment(environment);
@@ -120,6 +118,14 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
120
118
  // eslint-disable-next-line react-hooks/exhaustive-deps
121
119
  }, [environment, cacheIdentifier]);
122
120
 
121
+ useEffect(() => {
122
+ // Release any temporary retain that's not released. At this point, if the
123
+ // cacheIdentifier doesn't change, the query is still permanently retained,
124
+ // and the temporary retain is redundant.
125
+ QueryResource.releaseTemporaryRetain(preparedQueryResult);
126
+ // This effect is intended to run on every commit, thus no dependency
127
+ });
128
+
123
129
  const {fragmentNode, fragmentRef} = preparedQueryResult;
124
130
  const {data} = useFragmentNode(
125
131
  fragmentNode,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -13,25 +13,9 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const getPaginationVariables = require('./getPaginationVariables');
17
- const getValueAtPath = require('./getValueAtPath');
18
- const invariant = require('invariant');
19
- const useFetchTrackingRef = require('./useFetchTrackingRef');
20
- const useIsMountedRef = require('./useIsMountedRef');
21
- const useIsOperationNodeActive = require('./useIsOperationNodeActive');
22
- const useRelayEnvironment = require('./useRelayEnvironment');
23
- const warning = require('warning');
24
-
25
- const {useCallback, useEffect, useState} = require('react');
26
- const {
27
- ConnectionInterface,
28
- __internal: {fetchQuery},
29
- createOperationDescriptor,
30
- getSelector,
31
- } = require('relay-runtime');
32
-
33
16
  import type {
34
17
  ConcreteRequest,
18
+ Direction,
35
19
  Disposable,
36
20
  GraphQLResponse,
37
21
  Observer,
@@ -41,7 +25,21 @@ import type {
41
25
  VariablesOf,
42
26
  } from 'relay-runtime';
43
27
 
44
- export type Direction = 'forward' | 'backward';
28
+ const useFetchTrackingRef = require('./useFetchTrackingRef');
29
+ const useIsMountedRef = require('./useIsMountedRef');
30
+ const useIsOperationNodeActive = require('./useIsOperationNodeActive');
31
+ const useRelayEnvironment = require('./useRelayEnvironment');
32
+ const invariant = require('invariant');
33
+ const {useCallback, useEffect, useState} = require('react');
34
+ const {
35
+ ConnectionInterface,
36
+ __internal: {fetchQuery},
37
+ createOperationDescriptor,
38
+ getPaginationVariables,
39
+ getSelector,
40
+ getValueAtPath,
41
+ } = require('relay-runtime');
42
+ const warning = require('warning');
45
43
 
46
44
  export type LoadMoreFn<TQuery: OperationType> = (
47
45
  count: number,
@@ -84,12 +82,8 @@ function useLoadMoreFunction<TQuery: OperationType>(
84
82
  identifierField,
85
83
  } = args;
86
84
  const environment = useRelayEnvironment();
87
- const {
88
- isFetchingRef,
89
- startFetch,
90
- disposeFetch,
91
- completeFetch,
92
- } = useFetchTrackingRef();
85
+ const {isFetchingRef, startFetch, disposeFetch, completeFetch} =
86
+ useFetchTrackingRef();
93
87
  const identifierValue =
94
88
  identifierField != null &&
95
89
  fragmentData != null &&
@@ -98,9 +92,8 @@ function useLoadMoreFunction<TQuery: OperationType>(
98
92
  : null;
99
93
  const isMountedRef = useIsMountedRef();
100
94
  const [mirroredEnvironment, setMirroredEnvironment] = useState(environment);
101
- const [mirroredFragmentIdentifier, setMirroredFragmentIdentifier] = useState(
102
- fragmentIdentifier,
103
- );
95
+ const [mirroredFragmentIdentifier, setMirroredFragmentIdentifier] =
96
+ useState(fragmentIdentifier);
104
97
 
105
98
  const isParentQueryActive = useIsOperationNodeActive(
106
99
  fragmentNode,
@@ -190,7 +183,6 @@ function useLoadMoreFunction<TQuery: OperationType>(
190
183
  const parentVariables = fragmentSelector.owner.variables;
191
184
  const fragmentVariables = fragmentSelector.variables;
192
185
  const extraVariables = options?.UNSTABLE_extraVariables;
193
- // $FlowFixMe[cannot-spread-interface]
194
186
  const baseVariables = {
195
187
  ...parentVariables,
196
188
  ...fragmentVariables,
@@ -200,7 +192,6 @@ function useLoadMoreFunction<TQuery: OperationType>(
200
192
  count,
201
193
  cursor,
202
194
  baseVariables,
203
- // $FlowFixMe[cannot-spread-interface]
204
195
  {...extraVariables},
205
196
  paginationMetadata,
206
197
  );
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -13,19 +13,17 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const React = require('react');
17
-
18
- const useMemoVariables = require('./useMemoVariables');
19
-
20
- const {createOperationDescriptor, getRequest} = require('relay-runtime');
21
-
22
16
  import type {
17
+ CacheConfig,
23
18
  GraphQLTaggedNode,
24
19
  OperationDescriptor,
25
20
  Variables,
26
- CacheConfig,
27
21
  } from 'relay-runtime';
28
22
 
23
+ const useMemoVariables = require('./useMemoVariables');
24
+ const React = require('react');
25
+ const {createOperationDescriptor, getRequest} = require('relay-runtime');
26
+
29
27
  const {useMemo} = React;
30
28
 
31
29
  function useMemoOperationDescriptor(
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -13,11 +13,10 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const React = require('react');
16
+ import type {Variables} from 'relay-runtime';
17
17
 
18
18
  const areEqual = require('areEqual');
19
-
20
- import type {Variables} from 'relay-runtime';
19
+ const React = require('react');
21
20
 
22
21
  const {useMemo, useRef, useState} = React;
23
22
 
@@ -45,9 +44,10 @@ function useMemoVariables<TVariables: Variables | null>(
45
44
  // NOTE: We disable react-hooks-deps warning because we explicitly
46
45
  // don't want to memoize on object identity
47
46
  // eslint-disable-next-line react-hooks/exhaustive-deps
48
- const memoVariables = useMemo(() => variables, [
49
- variablesChangedGenerationRef.current,
50
- ]);
47
+ const memoVariables = useMemo(
48
+ () => variables,
49
+ [variablesChangedGenerationRef.current],
50
+ );
51
51
  return [memoVariables, variablesChangedGenerationRef.current ?? 0];
52
52
  }
53
53
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -13,46 +13,43 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const React = require('react');
17
-
18
- const useRelayEnvironment = require('./useRelayEnvironment');
19
-
20
- const {commitMutation: defaultCommitMutation} = require('relay-runtime');
21
- const {useState, useEffect, useRef, useCallback} = React;
22
- const useIsMountedRef = require('./useIsMountedRef');
23
-
24
16
  import type {
25
- GraphQLTaggedNode,
17
+ DeclarativeMutationConfig,
26
18
  Disposable,
19
+ GraphQLTaggedNode,
20
+ IEnvironment,
27
21
  MutationConfig,
28
22
  MutationParameters,
29
- IEnvironment,
30
23
  PayloadError,
31
- DeclarativeMutationConfig,
32
24
  SelectorStoreUpdater,
33
25
  UploadableMap,
34
26
  } from 'relay-runtime';
35
27
 
28
+ const useIsMountedRef = require('./useIsMountedRef');
29
+ const useRelayEnvironment = require('./useRelayEnvironment');
30
+ const React = require('react');
31
+ const {commitMutation: defaultCommitMutation} = require('relay-runtime');
32
+
33
+ const {useState, useEffect, useRef, useCallback} = React;
34
+
36
35
  export type UseMutationConfig<TMutation: MutationParameters> = {|
37
36
  configs?: Array<DeclarativeMutationConfig>,
38
37
  onError?: ?(error: Error) => void,
39
38
  onCompleted?: ?(
40
- response: $ElementType<TMutation, 'response'>,
39
+ response: TMutation['response'],
41
40
  errors: ?Array<PayloadError>,
42
41
  ) => void,
42
+ onNext?: ?() => void,
43
43
  onUnsubscribe?: ?() => void,
44
- optimisticResponse?: $ElementType<
45
- {
46
- +rawResponse?: {...},
47
- ...TMutation,
48
- ...
49
- },
50
- 'rawResponse',
51
- >,
52
- optimisticUpdater?: ?SelectorStoreUpdater,
53
- updater?: ?SelectorStoreUpdater,
44
+ optimisticResponse?: {
45
+ +rawResponse?: {...},
46
+ ...TMutation,
47
+ ...
48
+ }['rawResponse'],
49
+ optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
50
+ updater?: ?SelectorStoreUpdater<TMutation['response']>,
54
51
  uploadables?: UploadableMap,
55
- variables: $ElementType<TMutation, 'variables'>,
52
+ variables: TMutation['variables'],
56
53
  |};
57
54
 
58
55
  function useMutation<TMutation: MutationParameters>(
@@ -105,15 +102,18 @@ function useMutation<TMutation: MutationParameters>(
105
102
  mutation,
106
103
  onCompleted: (response, errors) => {
107
104
  cleanup(disposable);
108
- config.onCompleted && config.onCompleted(response, errors);
105
+ config.onCompleted?.(response, errors);
109
106
  },
110
107
  onError: error => {
111
108
  cleanup(disposable);
112
- config.onError && config.onError(error);
109
+ config.onError?.(error);
113
110
  },
114
111
  onUnsubscribe: () => {
115
112
  cleanup(disposable);
116
- config.onUnsubscribe && config.onUnsubscribe();
113
+ config.onUnsubscribe?.();
114
+ },
115
+ onNext: () => {
116
+ config.onNext?.();
117
117
  },
118
118
  });
119
119
  inFlightMutationsRef.current.add(disposable);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -13,24 +13,26 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const getPaginationMetadata = require('./getPaginationMetadata');
17
- const useLoadMoreFunction = require('./useLoadMoreFunction');
18
- const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
19
- const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
20
-
21
- const {useCallback, useDebugValue, useState} = require('react');
22
- const {getFragment, getFragmentIdentifier} = require('relay-runtime');
23
-
24
16
  import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
25
17
  import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
26
18
  import type {
19
+ FragmentType,
27
20
  GraphQLResponse,
28
21
  GraphQLTaggedNode,
29
22
  Observer,
30
23
  OperationType,
31
- FragmentReference,
32
24
  } from 'relay-runtime';
33
25
 
26
+ const useLoadMoreFunction = require('./useLoadMoreFunction');
27
+ const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
28
+ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
29
+ const {useCallback, useDebugValue, useState} = require('react');
30
+ const {
31
+ getFragment,
32
+ getFragmentIdentifier,
33
+ getPaginationMetadata,
34
+ } = require('relay-runtime');
35
+
34
36
  export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
35
37
  data: TFragmentData,
36
38
  loadNext: LoadMoreFn<TQuery>,
@@ -44,7 +46,7 @@ export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
44
46
 
45
47
  function usePaginationFragment<
46
48
  TQuery: OperationType,
47
- TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
49
+ TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
48
50
  >(
49
51
  fragmentInput: GraphQLTaggedNode,
50
52
  parentFragmentRef: TKey,
@@ -82,42 +84,34 @@ function usePaginationFragment<
82
84
  const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
83
85
 
84
86
  // Backward pagination
85
- const [
86
- loadPrevious,
87
- hasPrevious,
88
- isLoadingPrevious,
89
- disposeFetchPrevious,
90
- ] = useLoadMore<TQuery>({
91
- componentDisplayName,
92
- connectionPathInFragmentData,
93
- direction: 'backward',
94
- fragmentData,
95
- fragmentIdentifier,
96
- fragmentNode,
97
- fragmentRef,
98
- identifierField,
99
- paginationMetadata,
100
- paginationRequest,
101
- });
87
+ const [loadPrevious, hasPrevious, isLoadingPrevious, disposeFetchPrevious] =
88
+ useLoadMore<TQuery>({
89
+ componentDisplayName,
90
+ connectionPathInFragmentData,
91
+ direction: 'backward',
92
+ fragmentData,
93
+ fragmentIdentifier,
94
+ fragmentNode,
95
+ fragmentRef,
96
+ identifierField,
97
+ paginationMetadata,
98
+ paginationRequest,
99
+ });
102
100
 
103
101
  // Forward pagination
104
- const [
105
- loadNext,
106
- hasNext,
107
- isLoadingNext,
108
- disposeFetchNext,
109
- ] = useLoadMore<TQuery>({
110
- componentDisplayName,
111
- connectionPathInFragmentData,
112
- direction: 'forward',
113
- fragmentData,
114
- fragmentIdentifier,
115
- fragmentNode,
116
- fragmentRef,
117
- identifierField,
118
- paginationMetadata,
119
- paginationRequest,
120
- });
102
+ const [loadNext, hasNext, isLoadingNext, disposeFetchNext] =
103
+ useLoadMore<TQuery>({
104
+ componentDisplayName,
105
+ connectionPathInFragmentData,
106
+ direction: 'forward',
107
+ fragmentData,
108
+ fragmentIdentifier,
109
+ fragmentNode,
110
+ fragmentRef,
111
+ identifierField,
112
+ paginationMetadata,
113
+ paginationRequest,
114
+ });
121
115
 
122
116
  const refetchPagination: RefetchFnDynamic<TQuery, TKey> = useCallback(
123
117
  (variables, options) => {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -13,24 +13,23 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const invariant = require('invariant');
16
+ import type {PreloadedQuery} from './EntryPointTypes.flow';
17
+ import type {
18
+ GraphQLTaggedNode,
19
+ OperationType,
20
+ RenderPolicy,
21
+ } from 'relay-runtime';
22
+
23
+ const {useTrackLoadQueryInRender} = require('./loadQuery');
17
24
  const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
18
25
  const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
19
26
  const useRelayEnvironment = require('./useRelayEnvironment');
20
- const warning = require('warning');
21
-
22
- const {useTrackLoadQueryInRender} = require('./loadQuery');
27
+ const invariant = require('invariant');
23
28
  const {useDebugValue} = require('react');
24
29
  const {
25
30
  __internal: {fetchQueryDeduped, fetchQuery},
26
31
  } = require('relay-runtime');
27
-
28
- import type {PreloadedQuery} from './EntryPointTypes.flow';
29
- import type {
30
- GraphQLTaggedNode,
31
- OperationType,
32
- RenderPolicy,
33
- } from 'relay-runtime';
32
+ const warning = require('warning');
34
33
 
35
34
  function usePreloadedQuery<TQuery: OperationType>(
36
35
  gqlQuery: GraphQLTaggedNode,
@@ -38,19 +37,14 @@ function usePreloadedQuery<TQuery: OperationType>(
38
37
  options?: {|
39
38
  UNSTABLE_renderPolicy?: RenderPolicy,
40
39
  |},
41
- ): $ElementType<TQuery, 'response'> {
40
+ ): TQuery['response'] {
42
41
  // We need to use this hook in order to be able to track if
43
42
  // loadQuery was called during render
44
43
  useTrackLoadQueryInRender();
45
44
 
46
45
  const environment = useRelayEnvironment();
47
- const {
48
- fetchKey,
49
- fetchPolicy,
50
- source,
51
- variables,
52
- networkCacheConfig,
53
- } = preloadedQuery;
46
+ const {fetchKey, fetchPolicy, source, variables, networkCacheConfig} =
47
+ preloadedQuery;
54
48
  const operation = useMemoOperationDescriptor(
55
49
  gqlQuery,
56
50
  variables,