react-relay 13.1.1 → 14.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. package/ReactRelayContainerUtils.js.flow +0 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +0 -2
  4. package/ReactRelayFragmentContainer.js.flow +7 -6
  5. package/ReactRelayFragmentMockRenderer.js.flow +0 -2
  6. package/ReactRelayLocalQueryRenderer.js.flow +1 -3
  7. package/ReactRelayPaginationContainer.js.flow +13 -10
  8. package/ReactRelayQueryFetcher.js.flow +10 -11
  9. package/ReactRelayQueryRenderer.js.flow +15 -16
  10. package/ReactRelayQueryRendererContext.js.flow +1 -3
  11. package/ReactRelayRefetchContainer.js.flow +10 -7
  12. package/ReactRelayTestMocker.js.flow +0 -2
  13. package/ReactRelayTypes.js.flow +6 -8
  14. package/RelayContext.js.flow +0 -2
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -4
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +3 -5
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +3 -5
  18. package/__flowtests__/RelayModern-flowtest.js.flow +2 -4
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +2 -4
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +2 -4
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +2 -4
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +2 -4
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +2 -2
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +2 -2
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +3 -3
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -3
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +3 -3
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -3
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +2 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +2 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +2 -2
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +2 -2
  33. package/assertFragmentMap.js.flow +0 -2
  34. package/buildReactRelayContainer.js.flow +2 -4
  35. package/getRootVariablesForFragments.js.flow +0 -2
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +0 -2
  38. package/index.js +1 -1
  39. package/index.js.flow +2 -2
  40. package/isRelayEnvironment.js.flow +0 -2
  41. package/jest-react/internalAct.js.flow +25 -9
  42. package/legacy.js +1 -1
  43. package/legacy.js.flow +0 -2
  44. package/lib/ReactRelayContainerUtils.js +0 -1
  45. package/lib/ReactRelayContext.js +0 -1
  46. package/lib/ReactRelayFragmentContainer.js +10 -9
  47. package/lib/ReactRelayFragmentMockRenderer.js +0 -1
  48. package/lib/ReactRelayLocalQueryRenderer.js +0 -1
  49. package/lib/ReactRelayPaginationContainer.js +14 -11
  50. package/lib/ReactRelayQueryFetcher.js +2 -2
  51. package/lib/ReactRelayQueryRenderer.js +2 -4
  52. package/lib/ReactRelayQueryRendererContext.js +0 -1
  53. package/lib/ReactRelayRefetchContainer.js +11 -14
  54. package/lib/ReactRelayTestMocker.js +1 -2
  55. package/lib/ReactRelayTypes.js +0 -1
  56. package/lib/RelayContext.js +0 -1
  57. package/lib/assertFragmentMap.js +0 -1
  58. package/lib/buildReactRelayContainer.js +1 -2
  59. package/lib/getRootVariablesForFragments.js +1 -2
  60. package/lib/hooks.js +0 -1
  61. package/lib/index.js +3 -1
  62. package/lib/isRelayEnvironment.js +0 -1
  63. package/lib/jest-react/internalAct.js +24 -4
  64. package/lib/legacy.js +0 -1
  65. package/lib/multi-actor/useRelayActorEnvironment.js +0 -1
  66. package/lib/readContext.js +2 -2
  67. package/lib/relay-hooks/EntryPointContainer.react.js +0 -1
  68. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -1
  69. package/lib/relay-hooks/FragmentResource.js +68 -29
  70. package/lib/relay-hooks/HooksImplementation.js +29 -0
  71. package/lib/relay-hooks/InternalLogger.js +0 -1
  72. package/lib/relay-hooks/LRUCache.js +0 -1
  73. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -1
  74. package/lib/relay-hooks/MatchContainer.js +2 -2
  75. package/lib/relay-hooks/ProfilerContext.js +0 -1
  76. package/lib/relay-hooks/QueryResource.js +5 -168
  77. package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -1
  78. package/lib/relay-hooks/SuspenseResource.js +1 -2
  79. package/lib/relay-hooks/loadQuery.js +1 -1
  80. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -13
  81. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -1
  82. package/lib/relay-hooks/react-cache/RelayReactCache.js +36 -0
  83. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +344 -0
  84. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +239 -0
  85. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +598 -0
  86. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +50 -0
  87. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +55 -0
  88. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +150 -0
  89. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +124 -0
  90. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +367 -0
  91. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +45 -0
  92. package/lib/relay-hooks/useBlockingPaginationFragment.js +4 -3
  93. package/lib/relay-hooks/useClientQuery.js +33 -0
  94. package/lib/relay-hooks/useEntryPointLoader.js +1 -2
  95. package/lib/relay-hooks/useFetchTrackingRef.js +0 -1
  96. package/lib/relay-hooks/useFragment.js +15 -2
  97. package/lib/relay-hooks/useFragmentNode.js +0 -1
  98. package/lib/relay-hooks/useIsMountedRef.js +0 -1
  99. package/lib/relay-hooks/useLazyLoadQuery.js +4 -2
  100. package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -1
  101. package/lib/relay-hooks/useLoadMoreFunction.js +1 -2
  102. package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -1
  103. package/lib/relay-hooks/useMemoVariables.js +0 -1
  104. package/lib/relay-hooks/useMutation.js +5 -7
  105. package/lib/relay-hooks/usePaginationFragment.js +15 -3
  106. package/lib/relay-hooks/usePreloadedQuery.js +4 -2
  107. package/lib/relay-hooks/useQueryLoader.js +1 -2
  108. package/lib/relay-hooks/useRefetchableFragment.js +14 -2
  109. package/lib/relay-hooks/useRefetchableFragmentNode.js +1 -2
  110. package/lib/relay-hooks/useRelayEnvironment.js +0 -1
  111. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -1
  112. package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -1
  113. package/lib/relay-hooks/useSubscription.js +0 -1
  114. package/multi-actor/useRelayActorEnvironment.js.flow +0 -2
  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 -2
  123. package/relay-hooks/EntryPointContainer.react.js.flow +2 -4
  124. package/relay-hooks/EntryPointTypes.flow.js.flow +30 -32
  125. package/relay-hooks/FragmentResource.js.flow +80 -37
  126. package/relay-hooks/HooksImplementation.js.flow +43 -0
  127. package/relay-hooks/InternalLogger.js.flow +0 -2
  128. package/relay-hooks/LRUCache.js.flow +0 -2
  129. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -6
  130. package/relay-hooks/MatchContainer.js.flow +11 -6
  131. package/relay-hooks/ProfilerContext.js.flow +0 -2
  132. package/relay-hooks/QueryResource.js.flow +12 -209
  133. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -4
  134. package/relay-hooks/SuspenseResource.js.flow +0 -2
  135. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -3
  136. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  137. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +2 -2
  138. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +2 -2
  139. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +4 -6
  140. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +0 -2
  141. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +4 -6
  142. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +0 -2
  143. package/relay-hooks/__flowtests__/utils.js.flow +8 -10
  144. package/relay-hooks/loadQuery.js.flow +2 -1
  145. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +11 -20
  146. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +0 -2
  147. package/relay-hooks/react-cache/RelayReactCache.js.flow +40 -0
  148. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +430 -0
  149. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
  150. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +599 -0
  151. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +72 -0
  152. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +70 -0
  153. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +171 -0
  154. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +151 -0
  155. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +595 -0
  156. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
  157. package/relay-hooks/useBlockingPaginationFragment.js.flow +4 -6
  158. package/relay-hooks/useClientQuery.js.flow +39 -0
  159. package/relay-hooks/useEntryPointLoader.js.flow +6 -8
  160. package/relay-hooks/useFetchTrackingRef.js.flow +2 -4
  161. package/relay-hooks/useFragment.js.flow +17 -12
  162. package/relay-hooks/useFragmentNode.js.flow +2 -4
  163. package/relay-hooks/useIsMountedRef.js.flow +1 -3
  164. package/relay-hooks/useLazyLoadQuery.js.flow +17 -5
  165. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -4
  166. package/relay-hooks/useLoadMoreFunction.js.flow +6 -8
  167. package/relay-hooks/useMemoOperationDescriptor.js.flow +0 -2
  168. package/relay-hooks/useMemoVariables.js.flow +0 -2
  169. package/relay-hooks/useMutation.js.flow +5 -7
  170. package/relay-hooks/usePaginationFragment.js.flow +44 -19
  171. package/relay-hooks/usePreloadedQuery.js.flow +14 -5
  172. package/relay-hooks/useQueryLoader.js.flow +4 -6
  173. package/relay-hooks/useRefetchableFragment.js.flow +32 -3
  174. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -25
  175. package/relay-hooks/useRelayEnvironment.js.flow +0 -2
  176. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +0 -2
  177. package/relay-hooks/useSubscribeToInvalidationState.js.flow +0 -2
  178. package/relay-hooks/useSubscription.js.flow +14 -10
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  function getComponentName(component: React$ComponentType<any>): string {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v13.1.1
2
+ * Relay v14.1.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
  import type {RelayContext} from 'relay-runtime/store/RelayStoreTypes';
15
13
 
@@ -8,14 +8,12 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
-
15
12
  import type {GeneratedNodeMap, RelayProp, $RelayProps} from './ReactRelayTypes';
16
13
  import type {
17
14
  FragmentMap,
18
15
  FragmentSpecResolver,
16
+ IEnvironment,
19
17
  RelayContext,
20
18
  } from 'relay-runtime';
21
19
 
@@ -58,7 +56,7 @@ function createContainerWithFragments<
58
56
 
59
57
  return class extends React.Component<ContainerProps, ContainerState> {
60
58
  static displayName = containerName;
61
- constructor(props) {
59
+ constructor(props: $FlowFixMe) {
62
60
  super(props);
63
61
  const relayContext = assertRelayContext(props.__relayContext);
64
62
  const rootIsQueryRenderer = props.__rootIsQueryRenderer ?? false;
@@ -163,7 +161,10 @@ function createContainerWithFragments<
163
161
  this.state.resolver.dispose();
164
162
  }
165
163
 
166
- shouldComponentUpdate(nextProps, nextState): boolean {
164
+ shouldComponentUpdate(
165
+ nextProps: ContainerProps,
166
+ nextState: ContainerState,
167
+ ): boolean {
167
168
  // Short-circuit if any Relay-related data has changed
168
169
  if (nextState.data !== this.state.data) {
169
170
  return true;
@@ -247,7 +248,7 @@ function createContainerWithFragments<
247
248
  };
248
249
  }
249
250
 
250
- function getRelayProp(environment) {
251
+ function getRelayProp(environment: IEnvironment) {
251
252
  return {
252
253
  environment,
253
254
  };
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  const ReactRelayContext = require('./ReactRelayContext');
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {ReactRelayQueryRendererContext as ReactRelayQueryRendererContextType} from './ReactRelayQueryRendererContext';
@@ -40,7 +38,7 @@ const queryRendererContext: ReactRelayQueryRendererContextType = {
40
38
  rootIsQueryRenderer: true,
41
39
  };
42
40
 
43
- function useDeepCompare<T: interface {}>(value: T): T {
41
+ function useDeepCompare<T: {...}>(value: T): T {
44
42
  const latestValue = React.useRef(value);
45
43
  if (!areEqual(latestValue.current, value)) {
46
44
  if (__DEV__) {
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {
@@ -235,7 +233,7 @@ function createGetConnectionFromProps(metadata: ReactConnectionMetadata) {
235
233
  'ReactRelayPaginationContainer: Unable to synthesize a ' +
236
234
  'getConnectionFromProps function.',
237
235
  );
238
- return props => {
236
+ return (props: any) => {
239
237
  let data = props[metadata.fragmentName];
240
238
  for (let i = 0; i < path.length; i++) {
241
239
  if (!data || typeof data !== 'object') {
@@ -264,7 +262,9 @@ function createGetFragmentVariables(
264
262
 
265
263
  type ReactConnectionMetadata = ConnectionMetadata & {fragmentName: string, ...};
266
264
 
267
- function findConnectionMetadata(fragments): ReactConnectionMetadata {
265
+ function findConnectionMetadata(
266
+ fragments: FragmentMap,
267
+ ): ReactConnectionMetadata {
268
268
  let foundConnectionMetadata = null;
269
269
  let isRelayModern = false;
270
270
  for (const fragmentName in fragments) {
@@ -308,7 +308,7 @@ function toObserver(observerOrCallback: ?ObserverOrCallback): Observer<void> {
308
308
  ? {
309
309
  error: observerOrCallback,
310
310
  complete: observerOrCallback,
311
- unsubscribe: subscription => {
311
+ unsubscribe: (subscription: Subscription) => {
312
312
  typeof observerOrCallback === 'function' && observerOrCallback();
313
313
  },
314
314
  }
@@ -356,7 +356,7 @@ function createContainerWithFragments<
356
356
  _isUnmounted: boolean;
357
357
  _hasFetched: boolean;
358
358
 
359
- constructor(props) {
359
+ constructor(props: any) {
360
360
  super(props);
361
361
  const relayContext = assertRelayContext(props.__relayContext);
362
362
  const rootIsQueryRenderer = props.__rootIsQueryRenderer ?? false;
@@ -415,7 +415,7 @@ function createContainerWithFragments<
415
415
  * for updates. Props may be the same in which case previous data and
416
416
  * subscriptions can be reused.
417
417
  */
418
- UNSAFE_componentWillReceiveProps(nextProps) {
418
+ UNSAFE_componentWillReceiveProps(nextProps: any) {
419
419
  const relayContext = assertRelayContext(nextProps.__relayContext);
420
420
  const rootIsQueryRenderer = nextProps.__rootIsQueryRenderer ?? false;
421
421
  const prevIDs = getDataIDsFromObject(fragments, this.props);
@@ -479,7 +479,10 @@ function createContainerWithFragments<
479
479
  this._cleanup();
480
480
  }
481
481
 
482
- shouldComponentUpdate(nextProps, nextState): boolean {
482
+ shouldComponentUpdate(
483
+ nextProps: Props,
484
+ nextState: ContainerState,
485
+ ): boolean {
483
486
  // Short-circuit if any Relay-related data has changed
484
487
  if (
485
488
  nextState.data !== this.state.data ||
@@ -722,7 +725,7 @@ function createContainerWithFragments<
722
725
  return this._queryFetcher;
723
726
  }
724
727
 
725
- _canFetchPage(method): boolean {
728
+ _canFetchPage(method: 'loadMore' | 'refetchConnection'): boolean {
726
729
  if (this._isUnmounted) {
727
730
  warning(
728
731
  false,
@@ -813,7 +816,7 @@ function createContainerWithFragments<
813
816
  }
814
817
  this._hasFetched = true;
815
818
 
816
- const onNext = (payload, complete) => {
819
+ const onNext = (payload: mixed, complete: () => void) => {
817
820
  const prevData = this._resolver.resolve();
818
821
  this._resolver.setVariables(
819
822
  getFragmentVariables(
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {
@@ -35,26 +33,26 @@ type OnDataChange = ({
35
33
  }) => void;
36
34
 
37
35
  /** The external API of 'fetch' **/
38
- export type FetchOptions = {|
36
+ export type FetchOptions = {
39
37
  environment: IEnvironment,
40
38
  onDataChange?: null | OnDataChange,
41
39
  operation: OperationDescriptor,
42
- |};
40
+ };
43
41
 
44
42
  // Internally we keep an array of onDataChange callbacks, to support reusing
45
43
  // the queryRenderer for multiple components.
46
- type FetchOptionsInternal = {|
44
+ type FetchOptionsInternal = {
47
45
  environment: IEnvironment,
48
46
  onDataChangeCallbacks: Array<OnDataChange>,
49
47
  operation: OperationDescriptor,
50
- |};
48
+ };
51
49
 
52
- export type ExecuteConfig = {|
50
+ export type ExecuteConfig = {
53
51
  environment: IEnvironment,
54
52
  operation: OperationDescriptor,
55
53
  // Allows pagination container to retain results from previous queries
56
54
  preservePreviousReferences?: boolean,
57
- |};
55
+ };
58
56
 
59
57
  class ReactRelayQueryFetcher {
60
58
  _fetchOptions: ?FetchOptionsInternal;
@@ -77,10 +75,10 @@ class ReactRelayQueryFetcher {
77
75
  }
78
76
  }
79
77
 
80
- getSelectionReferences(): {|
78
+ getSelectionReferences(): {
81
79
  cacheSelectionReference: ?Disposable,
82
80
  selectionReferences: Array<Disposable>,
83
- |} {
81
+ } {
84
82
  return {
85
83
  cacheSelectionReference: this._cacheSelectionReference,
86
84
  selectionReferences: this._selectionReferences,
@@ -194,6 +192,7 @@ class ReactRelayQueryFetcher {
194
192
  onDataChange &&
195
193
  this._fetchOptions.onDataChangeCallbacks.indexOf(onDataChange) === -1
196
194
  ) {
195
+ // $FlowFixMe[incompatible-use]
197
196
  this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
198
197
  }
199
198
 
@@ -320,7 +319,7 @@ class ReactRelayQueryFetcher {
320
319
  }: {
321
320
  notifyFirstResult: boolean,
322
321
  ...
323
- }) {
322
+ }): void {
324
323
  invariant(
325
324
  this._fetchOptions,
326
325
  'ReactRelayQueryFetcher: `_onQueryDataAvailable` should have been called after having called `fetch`',
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {ReactRelayQueryRendererContext as ReactRelayQueryRendererContextType} from './ReactRelayQueryRendererContext';
@@ -29,13 +27,12 @@ const ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext
29
27
  const areEqual = require('areEqual');
30
28
  const React = require('react');
31
29
  const {
32
- RelayFeatureFlags,
33
30
  createOperationDescriptor,
34
31
  deepFreeze,
35
32
  getRequest,
36
33
  } = require('relay-runtime');
37
34
 
38
- type RetryCallbacks = {|
35
+ type RetryCallbacks = {
39
36
  handleDataChange:
40
37
  | null
41
38
  | (({
@@ -44,34 +41,39 @@ type RetryCallbacks = {|
44
41
  ...
45
42
  }) => void),
46
43
  handleRetryAfterError: null | ((error: Error) => void),
47
- |};
44
+ };
48
45
 
49
- export type RenderProps<T> = {|
46
+ export type RenderProps<T> = {
50
47
  error: ?Error,
51
48
  props: ?T,
52
49
  retry: ?(cacheConfigOverride?: CacheConfig) => void,
53
- |};
50
+ };
54
51
  /**
55
52
  * React may double-fire the constructor, and we call 'fetch' in the
56
53
  * constructor. If a request is already in flight from a previous call to the
57
54
  * constructor, just reuse the query fetcher and wait for the response.
58
55
  */
59
- const requestCache = {};
56
+ const requestCache: {
57
+ [string]: void | {
58
+ queryFetcher: ReactRelayQueryFetcher,
59
+ snapshot: ?Snapshot,
60
+ },
61
+ } = {};
60
62
 
61
63
  const queryRendererContext: ReactRelayQueryRendererContextType = {
62
64
  rootIsQueryRenderer: true,
63
65
  };
64
66
 
65
- export type Props = {|
67
+ export type Props = {
66
68
  cacheConfig?: ?CacheConfig,
67
69
  fetchPolicy?: 'store-and-network' | 'network-only',
68
70
  environment: IEnvironment,
69
71
  query: ?GraphQLTaggedNode,
70
72
  render: (renderProps: RenderProps<Object>) => React.Node,
71
73
  variables: Variables,
72
- |};
74
+ };
73
75
 
74
- type State = {|
76
+ type State = {
75
77
  error: Error | null,
76
78
  prevPropsEnvironment: IEnvironment,
77
79
  prevPropsVariables: Variables,
@@ -82,7 +84,7 @@ type State = {|
82
84
  retryCallbacks: RetryCallbacks,
83
85
  requestCacheKey: ?string,
84
86
  snapshot: Snapshot | null,
85
- |};
87
+ };
86
88
 
87
89
  /**
88
90
  * @public
@@ -157,10 +159,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
157
159
  }
158
160
 
159
161
  componentDidMount() {
160
- if (
161
- RelayFeatureFlags.ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT === true &&
162
- this._maybeHiddenOrFastRefresh === true
163
- ) {
162
+ if (this._maybeHiddenOrFastRefresh === true) {
164
163
  // This block only runs if the component has previously "unmounted"
165
164
  // due to it being hidden by the Offscreen API, or during fast refresh.
166
165
  // At this point, the current cached resource will have been disposed
@@ -8,12 +8,10 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
  const React = require('react');
15
13
 
16
- export type ReactRelayQueryRendererContext = {|rootIsQueryRenderer: boolean|};
14
+ export type ReactRelayQueryRendererContext = {rootIsQueryRenderer: boolean};
17
15
 
18
16
  module.exports = (React.createContext({
19
17
  rootIsQueryRenderer: false,
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {
@@ -24,6 +22,7 @@ import type {
24
22
  Disposable,
25
23
  FragmentMap,
26
24
  GraphQLTaggedNode,
25
+ IEnvironment,
27
26
  RelayContext,
28
27
  Subscription,
29
28
  Variables,
@@ -86,7 +85,7 @@ function createContainerWithFragments<
86
85
  _queryFetcher: ?ReactRelayQueryFetcher;
87
86
  _isUnmounted: boolean;
88
87
 
89
- constructor(props) {
88
+ constructor(props: any) {
90
89
  super(props);
91
90
  const relayContext = assertRelayContext(props.__relayContext);
92
91
  const rootIsQueryRenderer = props.__rootIsQueryRenderer ?? false;
@@ -217,7 +216,10 @@ function createContainerWithFragments<
217
216
  this._refetchSubscription && this._refetchSubscription.unsubscribe();
218
217
  }
219
218
 
220
- shouldComponentUpdate(nextProps, nextState): boolean {
219
+ shouldComponentUpdate(
220
+ nextProps: ContainerProps,
221
+ nextState: ContainerState,
222
+ ): boolean {
221
223
  // Short-circuit if any Relay-related data has changed
222
224
  if (
223
225
  nextState.data !== this.state.data ||
@@ -360,9 +362,7 @@ function createContainerWithFragments<
360
362
  );
361
363
 
362
364
  // TODO: T26288752 find a better way
363
- /* eslint-disable lint/react-state-props-mutation */
364
365
  this.state.localVariables = fetchVariables;
365
- /* eslint-enable lint/react-state-props-mutation */
366
366
 
367
367
  // Cancel any previously running refetch.
368
368
  this._refetchSubscription && this._refetchSubscription.unsubscribe();
@@ -465,7 +465,10 @@ function createContainerWithFragments<
465
465
  };
466
466
  }
467
467
 
468
- function getRelayProp(environment, refetch): RelayRefetchProp {
468
+ function getRelayProp(
469
+ environment: IEnvironment,
470
+ refetch: RelayRefetchProp['refetch'],
471
+ ): RelayRefetchProp {
469
472
  return {
470
473
  environment,
471
474
  refetch,
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {
@@ -29,7 +27,7 @@ export type ObserverOrCallback = Observer<void> | ((error: ?Error) => mixed);
29
27
  // RelayRefetchProp to flow into a RelayProp.
30
28
  export type RelayProp = {+environment: IEnvironment, ...};
31
29
 
32
- export type RelayPaginationProp = {|
30
+ export type RelayPaginationProp = {
33
31
  +environment: IEnvironment,
34
32
  +hasMore: () => boolean,
35
33
  +isLoading: () => boolean,
@@ -43,9 +41,9 @@ export type RelayPaginationProp = {|
43
41
  observerOrCallback: ?ObserverOrCallback,
44
42
  refetchVariables: ?Variables,
45
43
  ) => ?Disposable,
46
- |};
44
+ };
47
45
 
48
- export type RelayRefetchProp = {|
46
+ export type RelayRefetchProp = {
49
47
  +environment: IEnvironment,
50
48
  +refetch: (
51
49
  refetchVariables: Variables | ((fragmentVariables: Variables) => Variables),
@@ -53,13 +51,13 @@ export type RelayRefetchProp = {|
53
51
  observerOrCallback: ?ObserverOrCallback,
54
52
  options?: RefetchOptions,
55
53
  ) => Disposable,
56
- |};
54
+ };
57
55
 
58
- export type RefetchOptions = {|
56
+ export type RefetchOptions = {
59
57
  +force?: boolean,
60
58
  +fetchPolicy?: 'store-or-network' | 'network-only',
61
59
  +metadata?: {[key: string]: mixed, ...},
62
- |};
60
+ };
63
61
 
64
62
  /**
65
63
  * A utility type which takes the type of a fragment's data (typically found in
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {RelayContext} from 'relay-runtime';
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  const {
@@ -45,7 +43,7 @@ class BarComponent extends React.Component<{
45
43
  requiredProp: string,
46
44
  ...
47
45
  }> {
48
- static defaultProps = {
46
+ static defaultProps: {defaultProp: string} = {
49
47
  defaultProp: 'default',
50
48
  };
51
49
  getNum(): number {
@@ -127,7 +125,7 @@ module.exports = {
127
125
  return <Bar {...props} />;
128
126
  },
129
127
  checkStaticsAndMethodsProxying(): React.Node {
130
- class ProxyChecker extends React.PureComponent<{||}> {
128
+ class ProxyChecker extends React.PureComponent<{}> {
131
129
  _barRef: ?BarComponent;
132
130
  getString(): string {
133
131
  const ok = this._barRef ? this._barRef.getNum() : 'default'; // legit
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  const {
@@ -33,13 +31,13 @@ class FooComponent extends React.Component {
33
31
  requiredProp: string,
34
32
  ...
35
33
  };
36
- static defaultProps = {
34
+ static defaultProps: {defaultProp: string} = {
37
35
  defaultProp: 'default',
38
36
  };
39
37
  getNum(): number {
40
38
  return 42;
41
39
  }
42
- render() {
40
+ render(): React.Node {
43
41
  const reqLen = this.props.requiredProp.length;
44
42
  const optionalProp = this.props.optionalProp;
45
43
 
@@ -159,7 +157,7 @@ module.exports = {
159
157
  /** $FlowExpectedError: Foo `getNum` gives number, but `getString` assumes string **/
160
158
  return bad ? 'not good' : ok;
161
159
  }
162
- render() {
160
+ render(): React.Node {
163
161
  return (
164
162
  <Foo
165
163
  componentRef={ref => {
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  const {
@@ -32,13 +30,13 @@ class FooComponent extends React.Component {
32
30
  requiredProp: string,
33
31
  ...
34
32
  };
35
- static defaultProps = {
33
+ static defaultProps: {defaultProp: string} = {
36
34
  defaultProp: 'default',
37
35
  };
38
36
  getNum(): number {
39
37
  return 42;
40
38
  }
41
- render() {
39
+ render(): React.Node {
42
40
  const reqLen = this.props.requiredProp.length;
43
41
  const optionalProp = this.props.optionalProp;
44
42
 
@@ -142,7 +140,7 @@ module.exports = {
142
140
  /** $FlowExpectedError: Foo `getNum` gives number, but `getString` assumes string **/
143
141
  return bad ? 'not good' : ok;
144
142
  }
145
- render() {
143
+ render(): React.Node {
146
144
  return (
147
145
  <Foo
148
146
  componentRef={ref => {
@@ -8,8 +8,6 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {$FragmentRef} from '../ReactRelayTypes';
@@ -252,9 +250,9 @@ declare var aComplexUserRef: {
252
250
  optionalUsers={null}
253
251
  />;
254
252
 
255
- class AnyTest extends React.Component<{|
253
+ class AnyTest extends React.Component<{
256
254
  anything: any,
257
- |}> {}
255
+ }> {}
258
256
  const AnyTestContainer = createFragmentContainer(AnyTest, {});
259
257
 
260
258
  <AnyTestContainer anything={42} />;
@@ -8,16 +8,14 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {RelayModernFlowtest_user$ref} from './RelayModernFlowtest_user.graphql';
16
14
  import type {FragmentType} from 'relay-runtime';
17
15
 
18
16
  declare export opaque type RelayModernFlowtest_badref$ref: FragmentType;
19
- export type RelayModernFlowtest_badref = {|
17
+ export type RelayModernFlowtest_badref = {
20
18
  +id: string,
21
19
  +$fragmentSpreads: RelayModernFlowtest_user$ref,
22
20
  +$fragmentType: RelayModernFlowtest_badref$ref,
23
- |};
21
+ };
@@ -8,16 +8,14 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {RelayModernFlowtest_user$ref} from './RelayModernFlowtest_user.graphql';
16
14
  import type {FragmentType} from 'relay-runtime';
17
15
 
18
16
  declare export opaque type RelayModernFlowtest_notref$ref: FragmentType;
19
- export type RelayModernFlowtest_notref = {|
17
+ export type RelayModernFlowtest_notref = {
20
18
  +id: string,
21
19
  +$fragmentSpreads: RelayModernFlowtest_user$ref,
22
20
  +$fragmentType: RelayModernFlowtest_notref$ref,
23
- |};
21
+ };
@@ -8,14 +8,12 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {FragmentType} from 'relay-runtime';
16
14
 
17
15
  declare export opaque type RelayModernFlowtest_user$ref: FragmentType;
18
- export type RelayModernFlowtest_user = {|
16
+ export type RelayModernFlowtest_user = {
19
17
  +name: ?string,
20
18
  +$fragmentType: RelayModernFlowtest_user$ref,
21
- |};
19
+ };
@@ -8,14 +8,12 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {FragmentType} from 'relay-runtime';
16
14
 
17
15
  declare export opaque type RelayModernFlowtest_users$ref: FragmentType;
18
- export type RelayModernFlowtest_users = $ReadOnlyArray<{|
16
+ export type RelayModernFlowtest_users = $ReadOnlyArray<{
19
17
  +name: ?string,
20
18
  +$fragmentType: RelayModernFlowtest_users$ref,
21
- |}>;
19
+ }>;