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
@@ -4,18 +4,19 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
14
+ import type {Options} from './useRefetchableFragmentNode';
15
15
  import type {
16
+ Disposable,
16
17
  FragmentType,
17
- GraphQLTaggedNode,
18
- OperationType,
18
+ RefetchableFragment,
19
+ Variables,
19
20
  } from 'relay-runtime';
20
21
 
21
22
  const HooksImplementation = require('./HooksImplementation');
@@ -24,66 +25,97 @@ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
24
25
  const {useDebugValue} = require('react');
25
26
  const {getFragment} = require('relay-runtime');
26
27
 
27
- type ReturnType<TQuery: OperationType, TKey: ?{+$data?: mixed, ...}> = [
28
+ type RefetchVariables<TVariables, TKey> =
29
+ // NOTE: This $Call ensures that the type of the returned variables is either:
30
+ // - nullable if the provided ref type is nullable
31
+ // - non-nullable if the provided ref type is non-nullable
32
+ // prettier-ignore
33
+ $Call<
34
+ & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => Partial<TVariables>)
35
+ & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
36
+ TKey,
37
+ >;
38
+
39
+ type RefetchFnBase<TVars, TOptions> = (
40
+ vars: TVars,
41
+ options?: TOptions,
42
+ ) => Disposable;
43
+
44
+ export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
45
+ RefetchVariables<TVariables, TKey>,
46
+ TOptions,
47
+ >;
48
+
49
+ export type ReturnType<TVariables, TData, TKey> = [
28
50
  // NOTE: This $Call ensures that the type of the returned data is either:
29
51
  // - nullable if the provided ref type is nullable
30
52
  // - non-nullable if the provided ref type is non-nullable
31
53
  // prettier-ignore
32
54
  $Call<
33
- & (<TFragmentData>( { +$data?: TFragmentData, ... }) => TFragmentData)
34
- & (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
55
+ & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
56
+ & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
35
57
  TKey,
36
58
  >,
37
- RefetchFnDynamic<TQuery, TKey>,
59
+ RefetchFn<TVariables, TKey>,
38
60
  ];
39
61
 
40
- // This separate type export is only needed as long as we are injecting
41
- // a separate hooks implementation in ./HooksImplementation -- it can
42
- // be removed after we stop doing that.
43
62
  export type UseRefetchableFragmentType = <
44
- TQuery: OperationType,
45
- TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
63
+ TFragmentType: FragmentType,
64
+ TVariables: Variables,
65
+ TData,
66
+ TKey: ?{+$fragmentSpreads: TFragmentType, ...},
46
67
  >(
47
- fragmentInput: GraphQLTaggedNode,
48
- fragmentRef: TKey,
49
- ) => ReturnType<TQuery, TKey>;
68
+ fragment: RefetchableFragment<TFragmentType, TData, TVariables>,
69
+ key: TKey,
70
+ ) => ReturnType<TVariables, TData, TKey>;
50
71
 
51
72
  function useRefetchableFragment_LEGACY<
52
- TQuery: OperationType,
53
- TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
73
+ TFragmentType: FragmentType,
74
+ TVariables: Variables,
75
+ TData,
76
+ TKey: ?{+$fragmentSpreads: TFragmentType, ...},
54
77
  >(
55
- fragmentInput: GraphQLTaggedNode,
78
+ fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
56
79
  fragmentRef: TKey,
57
- ): ReturnType<TQuery, TKey> {
80
+ ): ReturnType<TVariables, TData, TKey> {
58
81
  const fragmentNode = getFragment(fragmentInput);
59
82
  useStaticFragmentNodeWarning(
60
83
  fragmentNode,
61
84
  'first argument of useRefetchableFragment()',
62
85
  );
63
- const {fragmentData, refetch} = useRefetchableFragmentNode<TQuery, TKey>(
64
- fragmentNode,
65
- fragmentRef,
66
- 'useRefetchableFragment()',
67
- );
86
+ const {fragmentData, refetch} = useRefetchableFragmentNode<
87
+ {
88
+ response: TData,
89
+ variables: TVariables,
90
+ },
91
+ {
92
+ +$data: mixed,
93
+ ...
94
+ },
95
+ >(fragmentNode, fragmentRef, 'useRefetchableFragment()');
68
96
  if (__DEV__) {
69
97
  // eslint-disable-next-line react-hooks/rules-of-hooks
70
98
  useDebugValue({fragment: fragmentNode.name, data: fragmentData});
71
99
  }
72
- /* $FlowExpectedError[prop-missing] : Exposed options is a subset of internal
73
- * options */
74
- return [fragmentData, (refetch: RefetchFnDynamic<TQuery, TKey>)];
100
+
101
+ // $FlowFixMe[incompatible-return]
102
+ // $FlowFixMe[prop-missing]
103
+ // $FlowFixMe[incompatible-variance]
104
+ return [fragmentData, refetch];
75
105
  }
76
106
 
77
107
  function useRefetchableFragment<
78
- TQuery: OperationType,
79
- TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
108
+ TFragmentType: FragmentType,
109
+ TVariables: Variables,
110
+ TData,
111
+ TKey: ?{+$fragmentSpreads: TFragmentType, ...},
80
112
  >(
81
- fragmentInput: GraphQLTaggedNode,
113
+ fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
82
114
  parentFragmentRef: TKey,
83
- ): ReturnType<TQuery, TKey> {
115
+ ): ReturnType<TVariables, TData, TKey> {
84
116
  const impl = HooksImplementation.get();
85
117
  if (impl) {
86
- return impl.useRefetchableFragment<TQuery, TKey>(
118
+ return impl.useRefetchableFragment<TFragmentType, TVariables, TData, TKey>(
87
119
  fragmentInput,
88
120
  parentFragmentRef,
89
121
  );
@@ -4,13 +4,14 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  'use strict';
13
13
 
14
+ import type {RefetchableIdentifierInfo} from '../../relay-runtime/util/ReaderNode';
14
15
  import type {LoaderFn} from './useQueryLoader';
15
16
  import type {
16
17
  ConcreteRequest,
@@ -100,7 +101,7 @@ type RefetchFnExact<TQuery: OperationType, TOptions = Options> = RefetchFnBase<
100
101
  type RefetchFnInexact<
101
102
  TQuery: OperationType,
102
103
  TOptions = Options,
103
- > = RefetchFnBase<$Shape<VariablesOf<TQuery>>, TOptions>;
104
+ > = RefetchFnBase<Partial<VariablesOf<TQuery>>, TOptions>;
104
105
 
105
106
  type Action =
106
107
  | {
@@ -173,8 +174,10 @@ function useRefetchableFragmentNode<
173
174
  componentDisplayName: string,
174
175
  ): ReturnType<TQuery, TKey, InternalOptions> {
175
176
  const parentEnvironment = useRelayEnvironment();
176
- const {refetchableRequest, fragmentRefPathInResponse, identifierField} =
177
- getRefetchMetadata(fragmentNode, componentDisplayName);
177
+ const {refetchableRequest, fragmentRefPathInResponse} = getRefetchMetadata(
178
+ fragmentNode,
179
+ componentDisplayName,
180
+ );
178
181
  const fragmentIdentifier = getFragmentIdentifier(
179
182
  fragmentNode,
180
183
  parentFragmentRef,
@@ -207,10 +210,19 @@ function useRefetchableFragmentNode<
207
210
  const shouldReset =
208
211
  environment !== mirroredEnvironment ||
209
212
  fragmentIdentifier !== mirroredFragmentIdentifier;
210
- const [queryRef, loadQuery, disposeQuery] =
211
- useQueryLoader<TQuery>(refetchableRequest);
213
+ const [queryRef, loadQuery, disposeQuery] = useQueryLoader<
214
+ TQuery['variables'],
215
+ TQuery['response'],
216
+ TQuery['rawResponse'],
217
+ >((refetchableRequest: $FlowFixMe));
212
218
 
213
219
  let fragmentRef = parentFragmentRef;
220
+
221
+ const {identifierInfo} = getRefetchMetadata(
222
+ fragmentNode,
223
+ componentDisplayName,
224
+ );
225
+
214
226
  if (shouldReset) {
215
227
  dispatch({
216
228
  type: 'reset',
@@ -236,6 +248,7 @@ function useRefetchableFragmentNode<
236
248
  debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(
237
249
  refetchQuery.request.variables,
238
250
  fragmentRefPathInResponse,
251
+ identifierInfo?.identifierQueryVariableName,
239
252
  environment,
240
253
  );
241
254
  }
@@ -342,7 +355,7 @@ function useRefetchableFragmentNode<
342
355
  fragmentIdentifier,
343
356
  fragmentNode,
344
357
  fragmentRefPathInResponse,
345
- identifierField,
358
+ identifierInfo,
346
359
  loadQuery,
347
360
  parentFragmentRef,
348
361
  refetchableRequest,
@@ -378,20 +391,23 @@ function useRefetchFunction<TQuery: OperationType>(
378
391
  fragmentIdentifier: string,
379
392
  fragmentNode: ReaderFragment,
380
393
  fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
381
- identifierField: ?string,
394
+ identifierInfo: ?RefetchableIdentifierInfo,
382
395
  loadQuery: LoaderFn<TQuery>,
383
396
  parentFragmentRef: mixed,
384
397
  refetchableRequest: ConcreteRequest,
385
398
  ): RefetchFn<TQuery, InternalOptions> {
386
399
  const isMountedRef = useIsMountedRef();
387
400
  const identifierValue =
388
- identifierField != null &&
401
+ identifierInfo?.identifierField != null &&
389
402
  fragmentData != null &&
390
403
  typeof fragmentData === 'object'
391
- ? fragmentData[identifierField]
404
+ ? fragmentData[identifierInfo.identifierField]
392
405
  : null;
393
406
  return useCallback(
394
- (providedRefetchVariables, options) => {
407
+ (
408
+ providedRefetchVariables: VariablesOf<TQuery>,
409
+ options: void | InternalOptions,
410
+ ) => {
395
411
  // Bail out and warn if we're trying to refetch after the component
396
412
  // has unmounted
397
413
  if (isMountedRef.current !== true) {
@@ -452,8 +468,10 @@ function useRefetchFunction<TQuery: OperationType>(
452
468
  // If the query needs an identifier value ('id' or similar) and one
453
469
  // was not explicitly provided, read it from the fragment data.
454
470
  if (
455
- identifierField != null &&
456
- !providedRefetchVariables.hasOwnProperty('id')
471
+ identifierInfo != null &&
472
+ !providedRefetchVariables.hasOwnProperty(
473
+ identifierInfo.identifierQueryVariableName,
474
+ )
457
475
  ) {
458
476
  // @refetchable fragments are guaranteed to have an `id` selection
459
477
  // if the type is Node, implements Node, or is @fetchable. Double-check
@@ -463,11 +481,13 @@ function useRefetchFunction<TQuery: OperationType>(
463
481
  false,
464
482
  'Relay: Expected result to have a string ' +
465
483
  '`%s` in order to refetch, got `%s`.',
466
- identifierField,
484
+ identifierInfo.identifierField,
467
485
  identifierValue,
468
486
  );
469
487
  }
470
- (refetchVariables: $FlowFixMe).id = identifierValue;
488
+ (refetchVariables: $FlowFixMe)[
489
+ identifierInfo.identifierQueryVariableName
490
+ ] = identifierValue;
471
491
  }
472
492
 
473
493
  const refetchQuery = createOperationDescriptor(
@@ -516,10 +536,11 @@ if (__DEV__) {
516
536
  getInitialIDAndType(
517
537
  memoRefetchVariables: ?Variables,
518
538
  fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
539
+ identifierQueryVariableName: ?string,
519
540
  environment: IEnvironment,
520
541
  ): ?DebugIDandTypename {
521
542
  const {Record} = require('relay-runtime');
522
- const id = memoRefetchVariables?.id;
543
+ const id = memoRefetchVariables?.[identifierQueryVariableName ?? 'id'];
523
544
  if (
524
545
  fragmentRefPathInResponse.length !== 1 ||
525
546
  fragmentRefPathInResponse[0] !== 'node' ||
@@ -529,7 +550,7 @@ if (__DEV__) {
529
550
  }
530
551
  const recordSource = environment.getStore().getSource();
531
552
  const record = recordSource.get(id);
532
- const typename = record && Record.getType(record);
553
+ const typename = record == null ? null : Record.getType(record);
533
554
  if (typename == null) {
534
555
  return null;
535
556
  }
@@ -4,18 +4,18 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  'use strict';
13
13
 
14
14
  import type {IEnvironment} from 'relay-runtime';
15
15
 
16
+ const ReactRelayContext = require('./../ReactRelayContext');
16
17
  const invariant = require('invariant');
17
18
  const {useContext} = require('react');
18
- const ReactRelayContext = require('react-relay/ReactRelayContext');
19
19
 
20
20
  function useRelayEnvironment(): IEnvironment {
21
21
  const context = useContext(ReactRelayContext);
@@ -4,16 +4,16 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  'use strict';
13
13
 
14
14
  import type {ReaderFragment} from 'relay-runtime';
15
15
 
16
- const {useRef} = require('react');
16
+ const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
17
17
  const warning = require('warning');
18
18
 
19
19
  function useStaticFragmentNodeWarning(
@@ -25,7 +25,7 @@ function useStaticFragmentNodeWarning(
25
25
  // __DEV__ setting which shouldn't change. This allows us to only pay the
26
26
  // cost of `useRef` in development mode to produce the warning.
27
27
  // eslint-disable-next-line react-hooks/rules-of-hooks
28
- const initialPropRef = useRef(fragmentNode.name);
28
+ const initialPropRef = useUnsafeRef_DEPRECATED(fragmentNode.name);
29
29
  warning(
30
30
  initialPropRef.current === fragmentNode.name,
31
31
  'Relay: The %s has to remain the same over the lifetime of a component. ' +
@@ -4,9 +4,9 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  'use strict';
@@ -30,7 +30,7 @@ function useSubscribeToInvalidationState(
30
30
  callback: () => void,
31
31
  ): Disposable {
32
32
  const environment = useRelayEnvironment();
33
- const disposableRef = useRef(null);
33
+ const disposableRef = useRef<null | Disposable>(null);
34
34
 
35
35
  const stableDataIDs = Array.from(dataIDs).sort().join('');
36
36
  useEffect(() => {
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -45,7 +46,6 @@ function useSubscription<TVariables, TData, TRawResponse>(
45
46
  useEffect(() => {
46
47
  // $FlowFixMe[method-unbinding] added when improving typing for this parameters
47
48
  const {dispose} = actualRequestSubscription(environment, config);
48
- // $FlowFixMe[incompatible-call]
49
49
  return dispose;
50
50
  }, [environment, config, actualRequestSubscription]);
51
51
  }
@@ -0,0 +1,25 @@
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
+ * @flow strict-local
8
+ * @format
9
+ * @oncall relay
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const {useMemo} = require('react');
15
+
16
+ /**
17
+ * Like `useRef`, but does not warn when accessed during render. It's a bad
18
+ * pattern to read or write from a ref during render as it does not trigger
19
+ * a rerender and might result in bugs.
20
+ */
21
+ function useUnsafeRef_DEPRECATED<T>(init: T): {current: T} {
22
+ return useMemo<{current: T}>(() => ({current: init}), []);
23
+ }
24
+
25
+ module.exports = useUnsafeRef_DEPRECATED;
@@ -1,27 +0,0 @@
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
- */
10
- 'use strict';
11
-
12
- var React = require('react'); // $FlowFixMe[incompatible-use]
13
-
14
-
15
- var _React$__SECRET_INTER =
16
- /* $FlowFixMe[prop-missing] Flow doesn't know about React's internals for
17
- * good reason, but for now, Relay needs the dispatcher to read context. */
18
- React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
19
- ReactCurrentDispatcher = _React$__SECRET_INTER.ReactCurrentDispatcher,
20
- ReactCurrentOwner = _React$__SECRET_INTER.ReactCurrentOwner;
21
-
22
- function readContext(Context) {
23
- var dispatcher = ReactCurrentDispatcher != null ? ReactCurrentDispatcher.current : ReactCurrentOwner.currentDispatcher;
24
- return dispatcher.readContext(Context);
25
- }
26
-
27
- module.exports = readContext;
@@ -1,29 +0,0 @@
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
- * @flow strict-local
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- const React = require('react');
14
-
15
- // $FlowFixMe[incompatible-use]
16
- const {ReactCurrentDispatcher, ReactCurrentOwner} =
17
- /* $FlowFixMe[prop-missing] Flow doesn't know about React's internals for
18
- * good reason, but for now, Relay needs the dispatcher to read context. */
19
- React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
20
-
21
- function readContext<T>(Context: React.Context<T>): T {
22
- const dispatcher =
23
- ReactCurrentDispatcher != null
24
- ? ReactCurrentDispatcher.current
25
- : ReactCurrentOwner.currentDispatcher;
26
- return dispatcher.readContext(Context);
27
- }
28
-
29
- module.exports = readContext;