react-relay 14.0.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -2
  4. package/ReactRelayFragmentContainer.js.flow +6 -4
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -2
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -5
  7. package/ReactRelayPaginationContainer.js.flow +21 -14
  8. package/ReactRelayQueryFetcher.js.flow +28 -16
  9. package/ReactRelayQueryRenderer.js.flow +42 -13
  10. package/ReactRelayQueryRendererContext.js.flow +2 -3
  11. package/ReactRelayRefetchContainer.js.flow +9 -9
  12. package/ReactRelayTestMocker.js.flow +3 -3
  13. package/ReactRelayTypes.js.flow +7 -8
  14. package/RelayContext.js.flow +1 -2
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
  18. package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
  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 -2
  34. package/buildReactRelayContainer.js.flow +7 -7
  35. package/getRootVariablesForFragments.js.flow +1 -3
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -2
  38. package/index.js +1 -1
  39. package/index.js.flow +6 -2
  40. package/isRelayEnvironment.js.flow +1 -2
  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 -2
  46. package/lib/ReactRelayContainerUtils.js +2 -3
  47. package/lib/ReactRelayContext.js +3 -4
  48. package/lib/ReactRelayFragmentContainer.js +47 -73
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -4
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -31
  51. package/lib/ReactRelayPaginationContainer.js +74 -164
  52. package/lib/ReactRelayQueryFetcher.js +49 -76
  53. package/lib/ReactRelayQueryRenderer.js +63 -84
  54. package/lib/ReactRelayQueryRendererContext.js +2 -2
  55. package/lib/ReactRelayRefetchContainer.js +58 -108
  56. package/lib/ReactRelayTestMocker.js +33 -68
  57. package/lib/ReactRelayTypes.js +2 -1
  58. package/lib/RelayContext.js +4 -7
  59. package/lib/assertFragmentMap.js +3 -5
  60. package/lib/buildReactRelayContainer.js +11 -27
  61. package/lib/getRootVariablesForFragments.js +6 -10
  62. package/lib/hooks.js +5 -18
  63. package/lib/index.js +7 -24
  64. package/lib/isRelayEnvironment.js +5 -4
  65. package/lib/jest-react/enqueueTask.js +5 -9
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +9 -20
  68. package/lib/legacy.js +2 -8
  69. package/lib/multi-actor/ActorChange.js +2 -5
  70. package/lib/multi-actor/index.js +2 -1
  71. package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
  74. package/lib/relay-hooks/FragmentResource.js +109 -203
  75. package/lib/relay-hooks/HooksImplementation.js +3 -6
  76. package/lib/relay-hooks/InternalLogger.js +2 -3
  77. package/lib/relay-hooks/LRUCache.js +2 -20
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
  79. package/lib/relay-hooks/MatchContainer.js +15 -24
  80. package/lib/relay-hooks/ProfilerContext.js +3 -3
  81. package/lib/relay-hooks/QueryResource.js +31 -101
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
  83. package/lib/relay-hooks/SuspenseResource.js +9 -33
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +42 -78
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
  99. package/lib/relay-hooks/useClientQuery.js +30 -0
  100. package/lib/relay-hooks/useEntryPointLoader.js +18 -38
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
  102. package/lib/relay-hooks/useFragment.js +8 -19
  103. package/lib/relay-hooks/useFragmentNode.js +20 -32
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -6
  105. package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
  106. package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
  107. package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
  109. package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
  111. package/lib/relay-hooks/useMemoVariables.js +15 -34
  112. package/lib/relay-hooks/useMutation.js +9 -27
  113. package/lib/relay-hooks/usePaginationFragment.js +73 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +13 -44
  115. package/lib/relay-hooks/useQueryLoader.js +24 -49
  116. package/lib/relay-hooks/useRefetchableFragment.js +19 -17
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -8
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
  121. package/lib/relay-hooks/useSubscription.js +5 -10
  122. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
  123. package/multi-actor/ActorChange.js.flow +1 -1
  124. package/multi-actor/index.js.flow +1 -1
  125. package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
  126. package/package.json +2 -2
  127. package/react-relay-hooks.js +2 -2
  128. package/react-relay-hooks.min.js +2 -2
  129. package/react-relay-legacy.js +2 -2
  130. package/react-relay-legacy.min.js +2 -2
  131. package/react-relay.js +2 -2
  132. package/react-relay.min.js +2 -2
  133. package/relay-hooks/EntryPointContainer.react.js.flow +3 -5
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
  135. package/relay-hooks/FragmentResource.js.flow +43 -19
  136. package/relay-hooks/HooksImplementation.js.flow +7 -9
  137. package/relay-hooks/InternalLogger.js.flow +1 -3
  138. package/relay-hooks/LRUCache.js.flow +1 -3
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
  140. package/relay-hooks/MatchContainer.js.flow +6 -8
  141. package/relay-hooks/ProfilerContext.js.flow +1 -3
  142. package/relay-hooks/QueryResource.js.flow +29 -11
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
  144. package/relay-hooks/SuspenseResource.js.flow +1 -3
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
  147. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  149. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +39 -39
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
  153. package/relay-hooks/__flowtests__/utils.js.flow +21 -12
  154. package/relay-hooks/loadEntryPoint.js.flow +11 -6
  155. package/relay-hooks/loadQuery.js.flow +11 -7
  156. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
  169. package/relay-hooks/useClientQuery.js.flow +39 -0
  170. package/relay-hooks/useEntryPointLoader.js.flow +16 -14
  171. package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
  172. package/relay-hooks/useFragment.js.flow +2 -4
  173. package/relay-hooks/useFragmentNode.js.flow +7 -8
  174. package/relay-hooks/useIsMountedRef.js.flow +2 -4
  175. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  176. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  177. package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
  179. package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
  181. package/relay-hooks/useMemoVariables.js.flow +13 -31
  182. package/relay-hooks/useMutation.js.flow +6 -8
  183. package/relay-hooks/usePaginationFragment.js.flow +75 -43
  184. package/relay-hooks/usePreloadedQuery.js.flow +49 -43
  185. package/relay-hooks/useQueryLoader.js.flow +89 -28
  186. package/relay-hooks/useRefetchableFragment.js.flow +83 -23
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -4
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
  191. package/relay-hooks/useSubscription.js.flow +1 -3
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -28
  194. package/readContext.js.flow +0 -31
@@ -4,23 +4,22 @@
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
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
14
+ import type {RefetchableFragment} from '../../relay-runtime/util/RelayRuntimeTypes';
16
15
  import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
17
- import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
16
+ import type {Options} from './useRefetchableFragmentNode';
18
17
  import type {
18
+ Disposable,
19
19
  FragmentType,
20
20
  GraphQLResponse,
21
- GraphQLTaggedNode,
22
21
  Observer,
23
- OperationType,
22
+ Variables,
24
23
  } from 'relay-runtime';
25
24
 
26
25
  const useLoadMoreFunction = require('./useLoadMoreFunction');
@@ -34,35 +33,54 @@ const {
34
33
  getPaginationMetadata,
35
34
  } = require('relay-runtime');
36
35
 
37
- export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
38
- data: TFragmentData,
39
- loadNext: LoadMoreFn<TQuery>,
40
- loadPrevious: LoadMoreFn<TQuery>,
41
- hasNext: boolean,
42
- hasPrevious: boolean,
43
- refetch: RefetchFnDynamic<TQuery, TKey>,
44
- |};
36
+ type RefetchVariables<TVariables, TKey> =
37
+ // NOTE: This $Call ensures that the type of the variables is either:
38
+ // - nullable if the provided ref type is non-nullable
39
+ // - non-nullable if the provided ref type is nullable, and the caller need to provide the full set of variables
40
+ // prettier-ignore
41
+ $Call<
42
+ & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => $Shape<TVariables>)
43
+ & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
44
+ TKey,
45
+ >;
45
46
 
46
- function useBlockingPaginationFragment<
47
- TQuery: OperationType,
48
- TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
49
- >(
50
- fragmentInput: GraphQLTaggedNode,
51
- parentFragmentRef: TKey,
52
- componentDisplayName: string = 'useBlockingPaginationFragment()',
53
- ): ReturnType<
54
- TQuery,
55
- TKey,
47
+ type RefetchFnBase<TVars, TOptions> = (
48
+ vars: TVars,
49
+ options?: TOptions,
50
+ ) => Disposable;
51
+
52
+ type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
53
+ RefetchVariables<TVariables, TKey>,
54
+ TOptions,
55
+ >;
56
+
57
+ type ReturnType<TVariables, TData, TKey> = {
56
58
  // NOTE: This $Call ensures that the type of the returned data is either:
57
59
  // - nullable if the provided ref type is nullable
58
60
  // - non-nullable if the provided ref type is non-nullable
59
61
  // prettier-ignore
60
- $Call<
61
- & (<TFragmentData>( { +$data?: TFragmentData, ... }) => TFragmentData)
62
- & (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
62
+ data: $Call<
63
+ & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
64
+ & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
63
65
  TKey,
64
66
  >,
65
- > {
67
+ loadNext: LoadMoreFn<TVariables>,
68
+ loadPrevious: LoadMoreFn<TVariables>,
69
+ hasNext: boolean,
70
+ hasPrevious: boolean,
71
+ refetch: RefetchFn<TVariables, TKey>,
72
+ };
73
+
74
+ function useBlockingPaginationFragment<
75
+ TFragmentType: FragmentType,
76
+ TVariables: Variables,
77
+ TData,
78
+ TKey: ?{+$fragmentSpreads: TFragmentType, ...},
79
+ >(
80
+ fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
81
+ parentFragmentRef: TKey,
82
+ componentDisplayName: string = 'useBlockingPaginationFragment()',
83
+ ): ReturnType<TVariables, TData, TKey> {
66
84
  const fragmentNode = getFragment(fragmentInput);
67
85
  useStaticFragmentNodeWarning(
68
86
  fragmentNode,
@@ -88,33 +106,39 @@ function useBlockingPaginationFragment<
88
106
  refetch,
89
107
  disableStoreUpdates,
90
108
  enableStoreUpdates,
91
- } = useRefetchableFragmentNode<TQuery, TKey>(
92
- fragmentNode,
93
- parentFragmentRef,
94
- componentDisplayName,
95
- );
109
+ } = useRefetchableFragmentNode<
110
+ {
111
+ response: TData,
112
+ variables: TVariables,
113
+ },
114
+ {
115
+ +$data: mixed,
116
+ ...
117
+ },
118
+ >(fragmentNode, parentFragmentRef, componentDisplayName);
96
119
  const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
97
120
 
98
121
  // Backward pagination
99
- const [loadPrevious, hasPrevious, disposeFetchPrevious] = useLoadMore<TQuery>(
100
- {
101
- componentDisplayName,
102
- connectionPathInFragmentData,
103
- direction: 'backward',
104
- disableStoreUpdates,
105
- enableStoreUpdates,
106
- fragmentData,
107
- fragmentIdentifier,
108
- fragmentNode,
109
- fragmentRef,
110
- identifierField,
111
- paginationMetadata,
112
- paginationRequest,
113
- },
114
- );
122
+ const [loadPrevious, hasPrevious, disposeFetchPrevious] = useLoadMore<
123
+ TVariables,
124
+ TData,
125
+ >({
126
+ componentDisplayName,
127
+ connectionPathInFragmentData,
128
+ direction: 'backward',
129
+ disableStoreUpdates,
130
+ enableStoreUpdates,
131
+ fragmentData,
132
+ fragmentIdentifier,
133
+ fragmentNode,
134
+ fragmentRef,
135
+ identifierField,
136
+ paginationMetadata,
137
+ paginationRequest,
138
+ });
115
139
 
116
140
  // Forward pagination
117
- const [loadNext, hasNext, disposeFetchNext] = useLoadMore<TQuery>({
141
+ const [loadNext, hasNext, disposeFetchNext] = useLoadMore<TVariables, TData>({
118
142
  componentDisplayName,
119
143
  connectionPathInFragmentData,
120
144
  direction: 'forward',
@@ -129,8 +153,8 @@ function useBlockingPaginationFragment<
129
153
  paginationRequest,
130
154
  });
131
155
 
132
- const refetchPagination: RefetchFnDynamic<TQuery, TKey> = useCallback(
133
- (variables, options) => {
156
+ const refetchPagination: RefetchFn<TVariables, TKey> = useCallback(
157
+ (variables: TVariables, options: void | Options) => {
134
158
  disposeFetchNext();
135
159
  disposeFetchPrevious();
136
160
  return refetch(variables, {...options, __environment: undefined});
@@ -139,7 +163,8 @@ function useBlockingPaginationFragment<
139
163
  );
140
164
 
141
165
  return {
142
- data: fragmentData,
166
+ // $FlowFixMe[incompatible-cast]
167
+ data: (fragmentData: TData),
143
168
  loadNext,
144
169
  loadPrevious,
145
170
  hasNext,
@@ -148,7 +173,7 @@ function useBlockingPaginationFragment<
148
173
  };
149
174
  }
150
175
 
151
- function useLoadMore<TQuery: OperationType>(args: {|
176
+ function useLoadMore<TVariables: Variables>(args: {
152
177
  disableStoreUpdates: () => void,
153
178
  enableStoreUpdates: () => void,
154
179
  ...$Exact<
@@ -161,11 +186,13 @@ function useLoadMore<TQuery: OperationType>(args: {|
161
186
  },
162
187
  >,
163
188
  >,
164
- |}): [LoadMoreFn<TQuery>, boolean, () => void] {
189
+ }): [LoadMoreFn<TVariables>, boolean, () => void] {
165
190
  const {disableStoreUpdates, enableStoreUpdates, ...loadMoreArgs} = args;
166
- const [requestPromise, setRequestPromise] = useState(null);
167
- const requestPromiseRef = useRef(null);
168
- const promiseResolveRef = useRef(null);
191
+ const [requestPromise, setRequestPromise] = useState<null | Promise<mixed>>(
192
+ null,
193
+ );
194
+ const requestPromiseRef = useRef<null | Promise<mixed>>(null);
195
+ const promiseResolveRef = useRef<null | (() => void)>(null);
169
196
 
170
197
  const promiseResolve = () => {
171
198
  if (promiseResolveRef.current != null) {
@@ -210,7 +237,7 @@ function useLoadMore<TQuery: OperationType>(args: {|
210
237
  // and blow away the whole list of items.
211
238
  error: promiseResolve,
212
239
  };
213
- const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TQuery>({
240
+ const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
214
241
  ...loadMoreArgs,
215
242
  observer,
216
243
  onReset: handleReset,
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ * @oncall relay
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ import type {ClientQuery, Query, RenderPolicy, Variables} from 'relay-runtime';
15
+
16
+ const useLazyLoadQuery = require('./useLazyLoadQuery');
17
+
18
+ /**
19
+ * This hook can be used to render client-only queries.
20
+ * These queries are consist of queries for client-only data,
21
+ * schematized via local schema extensions and/or Relay resolvers.
22
+ */
23
+ function useClientQuery<TVariables: Variables, TData>(
24
+ gqlQuery: ClientQuery<TVariables, TData>,
25
+ variables: TVariables,
26
+ options?: {
27
+ UNSTABLE_renderPolicy?: RenderPolicy,
28
+ },
29
+ ): TData {
30
+ // $FlowFixMe[incompatible-type] client queries can be used with useLazyLoadQuery, but only with `store-only` policy.
31
+ const query: Query<TVariables, TData> = gqlQuery;
32
+
33
+ return useLazyLoadQuery(query, variables, {
34
+ ...options,
35
+ fetchPolicy: 'store-only',
36
+ });
37
+ }
38
+
39
+ module.exports = useClientQuery;
@@ -4,13 +4,11 @@
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
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {
@@ -47,9 +45,9 @@ type UseEntryPointLoaderHookReturnType<
47
45
  // NullEntryPointReference needs to implement referential equality,
48
46
  // so that multiple NullEntryPointReferences can be in the same set
49
47
  // (corresponding to multiple calls to disposeEntryPoint).
50
- type NullEntryPointReference = {|
48
+ type NullEntryPointReference = {
51
49
  kind: 'NullEntryPointReference',
52
- |};
50
+ };
53
51
  const initialNullEntryPointReferenceState = {kind: 'NullEntryPointReference'};
54
52
 
55
53
  function useLoadEntryPoint<
@@ -68,14 +66,14 @@ function useLoadEntryPoint<
68
66
  >(
69
67
  environmentProvider: IEnvironmentProvider<EnvironmentProviderOptions>,
70
68
  entryPoint: TEntryPoint,
71
- options?: ?{|
69
+ options?: ?{
72
70
  // TODO(T83890478): Remove once Offscreen API lands in xplat
73
71
  // and we can use it in tests
74
- TEST_ONLY__initialEntryPointData?: ?{|
72
+ TEST_ONLY__initialEntryPointData?: ?{
75
73
  entryPointReference: ?PreloadedEntryPoint<TEntryPointComponent>,
76
74
  entryPointParams: ?TEntryPointParams,
77
- |},
78
- |},
75
+ },
76
+ },
79
77
  ): UseEntryPointLoaderHookReturnType<
80
78
  TEntryPointParams,
81
79
  TPreloadedQueries,
@@ -136,11 +134,15 @@ function useLoadEntryPoint<
136
134
  const entryPointLoaderCallback = useCallback(
137
135
  (params: TEntryPointParams) => {
138
136
  if (isMountedRef.current) {
139
- const updatedEntryPointReference = loadEntryPoint(
140
- environmentProvider,
141
- entryPoint,
142
- params,
143
- );
137
+ const updatedEntryPointReference = loadEntryPoint<
138
+ TEntryPointParams,
139
+ TPreloadedQueries,
140
+ TPreloadedEntryPoints,
141
+ TRuntimeProps,
142
+ TExtraProps,
143
+ TEntryPointComponent,
144
+ TEntryPoint,
145
+ >(environmentProvider, entryPoint, params);
144
146
  undisposedEntryPointReferencesRef.current.add(
145
147
  updatedEntryPointReference,
146
148
  );
@@ -4,18 +4,17 @@
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
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {Subscription} from 'relay-runtime';
17
15
 
18
- const {useCallback, useEffect, useRef} = require('react');
16
+ const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
17
+ const {useCallback, useEffect} = require('react');
19
18
 
20
19
  /**
21
20
  * This hook returns a mutable React ref that holds the value of whether a
@@ -29,14 +28,14 @@ const {useCallback, useEffect, useRef} = require('react');
29
28
  * The additional functions returned by this Hook can be used to mutate
30
29
  * the ref.
31
30
  */
32
- function useFetchTrackingRef(): {|
31
+ function useFetchTrackingRef(): {
33
32
  isFetchingRef: {current: ?boolean, ...},
34
33
  startFetch: Subscription => void,
35
34
  disposeFetch: () => void,
36
35
  completeFetch: () => void,
37
- |} {
38
- const subscriptionRef = useRef<?Subscription>(null);
39
- const isFetchingRef = useRef<?boolean>(false);
36
+ } {
37
+ const subscriptionRef = useUnsafeRef_DEPRECATED<?Subscription>(null);
38
+ const isFetchingRef = useUnsafeRef_DEPRECATED<?boolean>(false);
40
39
 
41
40
  const disposeFetch = useCallback(() => {
42
41
  if (subscriptionRef.current != null) {
@@ -4,13 +4,11 @@
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
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
@@ -52,7 +50,7 @@ function useFragment_LEGACY(fragment: GraphQLTaggedNode, key: mixed): mixed {
52
50
 
53
51
  const fragmentNode = getFragment(fragment);
54
52
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
55
- const {data} = useFragmentNode<_>(fragmentNode, key, 'useFragment()');
53
+ const {data} = useFragmentNode<mixed>(fragmentNode, key, 'useFragment()');
56
54
  if (__DEV__) {
57
55
  // eslint-disable-next-line react-hooks/rules-of-hooks
58
56
  useDebugValue({fragment: fragmentNode.name, data});
@@ -4,28 +4,27 @@
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
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {ReaderFragment} from 'relay-runtime';
17
15
 
18
16
  const {getFragmentResourceForEnvironment} = require('./FragmentResource');
19
17
  const useRelayEnvironment = require('./useRelayEnvironment');
20
- const {useEffect, useRef, useState} = require('react');
18
+ const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
19
+ const {useEffect, useState} = require('react');
21
20
  const {getFragmentIdentifier} = require('relay-runtime');
22
21
  const warning = require('warning');
23
22
 
24
- type ReturnType<TFragmentData: mixed> = {|
23
+ type ReturnType<TFragmentData: mixed> = {
25
24
  data: TFragmentData,
26
25
  disableStoreUpdates: () => void,
27
26
  enableStoreUpdates: () => void,
28
- |};
27
+ };
29
28
 
30
29
  function useFragmentNode<TFragmentData: mixed>(
31
30
  fragmentNode: ReaderFragment,
@@ -35,7 +34,7 @@ function useFragmentNode<TFragmentData: mixed>(
35
34
  const environment = useRelayEnvironment();
36
35
  const FragmentResource = getFragmentResourceForEnvironment(environment);
37
36
 
38
- const isMountedRef = useRef(false);
37
+ const isMountedRef = useUnsafeRef_DEPRECATED(false);
39
38
  const [, forceUpdate] = useState(0);
40
39
  const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
41
40
 
@@ -47,7 +46,7 @@ function useFragmentNode<TFragmentData: mixed>(
47
46
  componentDisplayName,
48
47
  );
49
48
 
50
- const isListeningForUpdatesRef = useRef(true);
49
+ const isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
51
50
  function enableStoreUpdates() {
52
51
  isListeningForUpdatesRef.current = true;
53
52
  const didMissUpdates =
@@ -4,18 +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
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  const {useEffect, useRef} = require('react');
17
15
 
18
- function useIsMountedRef(): {|current: boolean|} {
16
+ function useIsMountedRef(): {current: boolean} {
19
17
  const isMountedRef = useRef(true);
20
18
 
21
19
  useEffect(() => {
@@ -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';
@@ -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';
@@ -4,25 +4,21 @@
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
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {
17
15
  CacheConfig,
18
- ClientQuery,
19
16
  FetchPolicy,
20
17
  Query,
21
18
  RenderPolicy,
22
19
  Variables,
23
20
  } from 'relay-runtime';
24
21
 
25
- const HooksImplementation = require('./HooksImplementation');
26
22
  const {useTrackLoadQueryInRender} = require('./loadQuery');
27
23
  const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
28
24
  const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
@@ -35,25 +31,25 @@ const {
35
31
  // a separate hooks implementation in ./HooksImplementation -- it can
36
32
  // be removed after we stop doing that.
37
33
  export type UseLazyLoadQueryHookType = <TVariables: Variables, TData>(
38
- gqlQuery: Query<TVariables, TData> | ClientQuery<TVariables, TData>,
34
+ gqlQuery: Query<TVariables, TData>,
39
35
  variables: TVariables,
40
- options?: {|
36
+ options?: {
41
37
  fetchKey?: string | number,
42
38
  fetchPolicy?: FetchPolicy,
43
39
  networkCacheConfig?: CacheConfig,
44
40
  UNSTABLE_renderPolicy?: RenderPolicy,
45
- |},
41
+ },
46
42
  ) => TData;
47
43
 
48
- function useLazyLoadQuery_LEGACY<TVariables: Variables, TData>(
49
- gqlQuery: Query<TVariables, TData> | ClientQuery<TVariables, TData>,
44
+ function useLazyLoadQuery<TVariables: Variables, TData>(
45
+ gqlQuery: Query<TVariables, TData>,
50
46
  variables: TVariables,
51
- options?: {|
47
+ options?: {
52
48
  fetchKey?: string | number,
53
49
  fetchPolicy?: FetchPolicy,
54
50
  networkCacheConfig?: CacheConfig,
55
51
  UNSTABLE_renderPolicy?: RenderPolicy,
56
- |},
52
+ },
57
53
  ): TData {
58
54
  // We need to use this hook in order to be able to track if
59
55
  // loadQuery was called during render
@@ -68,7 +64,7 @@ function useLazyLoadQuery_LEGACY<TVariables: Variables, TData>(
68
64
  ? options.networkCacheConfig
69
65
  : {force: true},
70
66
  );
71
- const data = useLazyLoadQueryNode({
67
+ const data = useLazyLoadQueryNode<$FlowFixMe>({
72
68
  componentDisplayName: 'useLazyLoadQuery()',
73
69
  fetchKey: options?.fetchKey,
74
70
  fetchObservable: fetchQuery(environment, query),
@@ -79,23 +75,4 @@ function useLazyLoadQuery_LEGACY<TVariables: Variables, TData>(
79
75
  return data;
80
76
  }
81
77
 
82
- function useLazyLoadQuery<TVariables: Variables, TData>(
83
- gqlQuery: Query<TVariables, TData> | ClientQuery<TVariables, TData>,
84
- variables: TVariables,
85
- options?: {|
86
- fetchKey?: string | number,
87
- fetchPolicy?: FetchPolicy,
88
- networkCacheConfig?: CacheConfig,
89
- UNSTABLE_renderPolicy?: RenderPolicy,
90
- |},
91
- ): TData {
92
- const impl = HooksImplementation.get();
93
- if (impl) {
94
- return impl.useLazyLoadQuery(gqlQuery, variables, options);
95
- } else {
96
- // eslint-disable-next-line react-hooks/rules-of-hooks
97
- return useLazyLoadQuery_LEGACY(gqlQuery, variables, options);
98
- }
99
- }
100
-
101
78
  module.exports = (useLazyLoadQuery: UseLazyLoadQueryHookType);
@@ -4,13 +4,11 @@
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
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {
@@ -41,14 +39,14 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
41
39
  fetchPolicy,
42
40
  fetchKey,
43
41
  renderPolicy,
44
- }: {|
42
+ }: {
45
43
  query: OperationDescriptor,
46
44
  componentDisplayName: string,
47
45
  fetchObservable: Observable<GraphQLResponse>,
48
46
  fetchPolicy?: ?FetchPolicy,
49
47
  fetchKey?: ?string | ?number,
50
48
  renderPolicy?: ?RenderPolicy,
51
- |}): TQuery['response'] {
49
+ }): TQuery['response'] {
52
50
  const environment = useRelayEnvironment();
53
51
  const profilerContext = useContext(ProfilerContext);
54
52
  const QueryResource = getQueryResourceForEnvironment(environment);
@@ -127,7 +125,7 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
127
125
  });
128
126
 
129
127
  const {fragmentNode, fragmentRef} = preparedQueryResult;
130
- const {data} = useFragmentNode(
128
+ const {data} = useFragmentNode<$FlowFixMe>(
131
129
  fragmentNode,
132
130
  fragmentRef,
133
131
  componentDisplayName,