react-relay 14.0.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -5,12 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  * @flow strict-local
8
- * @emails oncall+relay
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 {Cache} from './LRUCache';
@@ -31,8 +29,8 @@ const {getQueryResourceForEnvironment} = require('./QueryResource');
31
29
  const SuspenseResource = require('./SuspenseResource');
32
30
  const invariant = require('invariant');
33
31
  const {
34
- RelayFeatureFlags,
35
32
  __internal: {fetchQuery, getPromiseForActiveRequest},
33
+ RelayFeatureFlags,
36
34
  createOperationDescriptor,
37
35
  getFragmentIdentifier,
38
36
  getPendingOperationsForFragment,
@@ -46,13 +44,13 @@ const {
46
44
  export type FragmentResource = FragmentResourceImpl;
47
45
 
48
46
  type FragmentResourceCache = Cache<
49
- | {|
47
+ | {
50
48
  kind: 'pending',
51
49
  pendingOperations: $ReadOnlyArray<RequestDescriptor>,
52
50
  promise: Promise<mixed>,
53
51
  result: FragmentResult,
54
- |}
55
- | {|kind: 'done', result: FragmentResult|},
52
+ }
53
+ | {kind: 'done', result: FragmentResult},
56
54
  >;
57
55
 
58
56
  const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
@@ -63,13 +61,13 @@ interface IMap<K, V> {
63
61
 
64
62
  type SingularOrPluralSnapshot = Snapshot | $ReadOnlyArray<Snapshot>;
65
63
 
66
- opaque type FragmentResult: {data: mixed, ...} = {|
64
+ opaque type FragmentResult: {data: mixed, ...} = {
67
65
  cacheKey: string,
68
66
  data: mixed,
69
67
  isMissingData: boolean,
70
68
  snapshot: SingularOrPluralSnapshot | null,
71
69
  storeEpoch: number,
72
- |};
70
+ };
73
71
 
74
72
  // TODO: Fix to not rely on LRU. If the number of active fragments exceeds this
75
73
  // capacity, readSpec() will fail to find cached entries and break object
@@ -77,7 +75,7 @@ opaque type FragmentResult: {data: mixed, ...} = {|
77
75
  const CACHE_CAPACITY = 1000000;
78
76
 
79
77
  // this is frozen so that users don't accidentally push data into the array
80
- const CONSTANT_READONLY_EMPTY_ARRAY = Object.freeze([]);
78
+ const CONSTANT_READONLY_EMPTY_ARRAY: Array<$FlowFixMe> = Object.freeze([]);
81
79
 
82
80
  function isMissingData(snapshot: SingularOrPluralSnapshot): boolean {
83
81
  if (Array.isArray(snapshot)) {
@@ -178,7 +176,7 @@ class ClientEdgeQueryResultsCache {
178
176
  }
179
177
  }
180
178
 
181
- _retain(id: string) {
179
+ _retain(id: string): {dispose: () => void} {
182
180
  const retainCount = (this._retainCounts.get(id) ?? 0) + 1;
183
181
  this._retainCounts.set(id, retainCount);
184
182
  return {
@@ -306,9 +304,23 @@ class FragmentResourceImpl {
306
304
  cachedValue.result.snapshot &&
307
305
  !missingLiveResolverFields(cachedValue.result.snapshot)?.length
308
306
  ) {
309
- this._handlePotentialSnapshotErrorsInSnapshot(
307
+ this._throwOrLogErrorsInSnapshot(
308
+ // $FlowFixMe[incompatible-call]
310
309
  cachedValue.result.snapshot,
311
310
  );
311
+
312
+ // This cache gets populated directly whenever the store notifies us of
313
+ // an update. That mechanism does not check for missing data, or
314
+ // in-flight requests.
315
+ if (cachedValue.result.isMissingData) {
316
+ environment.__log({
317
+ name: 'fragmentresource.missing_data',
318
+ data: cachedValue.result.data,
319
+ fragment: fragmentNode,
320
+ isRelayHooks: true,
321
+ cached: true,
322
+ });
323
+ }
312
324
  return cachedValue.result;
313
325
  }
314
326
  }
@@ -347,7 +359,7 @@ class FragmentResourceImpl {
347
359
  storeEpoch,
348
360
  );
349
361
  if (!fragmentResult.isMissingData) {
350
- this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
362
+ this._throwOrLogErrorsInSnapshot(snapshot);
351
363
 
352
364
  this._cache.set(fragmentIdentifier, {
353
365
  kind: 'done',
@@ -471,7 +483,19 @@ class FragmentResourceImpl {
471
483
  }
472
484
  }
473
485
 
474
- this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
486
+ this._throwOrLogErrorsInSnapshot(snapshot);
487
+
488
+ // At this point, there's nothing we can do. We don't have all the expected
489
+ // data, but there's no indication the missing data will be fulfilled. So we
490
+ // choose to return potentially non-typesafe data. The data returned here
491
+ // might not match the generated types for this fragment/operation.
492
+ environment.__log({
493
+ name: 'fragmentresource.missing_data',
494
+ data: fragmentResult.data,
495
+ fragment: fragmentNode,
496
+ isRelayHooks: true,
497
+ cached: false,
498
+ });
475
499
  return getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
476
500
  }
477
501
 
@@ -481,7 +505,7 @@ class FragmentResourceImpl {
481
505
  fragmentRef: mixed,
482
506
  request: ConcreteRequest,
483
507
  clientEdgeDestinationID: DataID,
484
- ) {
508
+ ): {queryResult: QueryResult, requestDescriptor: RequestDescriptor} {
485
509
  const originalVariables = getVariablesFromFragment(
486
510
  fragmentNode,
487
511
  fragmentRef,
@@ -507,7 +531,7 @@ class FragmentResourceImpl {
507
531
  };
508
532
  }
509
533
 
510
- _handlePotentialSnapshotErrorsInSnapshot(snapshot: SingularOrPluralSnapshot) {
534
+ _throwOrLogErrorsInSnapshot(snapshot: SingularOrPluralSnapshot) {
511
535
  if (Array.isArray(snapshot)) {
512
536
  snapshot.forEach(s => {
513
537
  handlePotentialSnapshotErrors(
@@ -716,10 +740,10 @@ class FragmentResourceImpl {
716
740
  fragmentNode: ReaderFragment,
717
741
  fragmentOwner: RequestDescriptor,
718
742
  fragmentResult: FragmentResult,
719
- ): {|
743
+ ): {
720
744
  promise: Promise<void>,
721
745
  pendingOperations: $ReadOnlyArray<RequestDescriptor>,
722
- |} | null {
746
+ } | null {
723
747
  const pendingOperationsResult = getPendingOperationsForFragment(
724
748
  this._environment,
725
749
  fragmentNode,
@@ -738,7 +762,7 @@ class FragmentResourceImpl {
738
762
  .then(() => {
739
763
  this._cache.delete(cacheKey);
740
764
  })
741
- .catch((error: Error) => {
765
+ .catch<void>((error: Error) => {
742
766
  this._cache.delete(cacheKey);
743
767
  });
744
768
  // $FlowExpectedError[prop-missing] Expando to annotate Promises.
@@ -4,26 +4,24 @@
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
- // flowlint ambiguous-object-type:error
15
-
16
14
  import typeof useFragment from './useFragment';
17
- import type {UseLazyLoadQueryHookType} from './useLazyLoadQuery';
18
- import type {UsePreloadedQueryHookType} from './usePreloadedQuery';
15
+ import type {UsePaginationFragmentType} from './usePaginationFragment';
16
+ import type {UseRefetchableFragmentType} from './useRefetchableFragment';
19
17
 
20
18
  const warning = require('warning');
21
19
 
22
- type HooksImplementation = {|
20
+ type HooksImplementation = {
23
21
  useFragment: useFragment,
24
- useLazyLoadQuery: UseLazyLoadQueryHookType,
25
- usePreloadedQuery: UsePreloadedQueryHookType,
26
- |};
22
+ usePaginationFragment: UsePaginationFragmentType,
23
+ useRefetchableFragment: UseRefetchableFragmentType,
24
+ };
27
25
 
28
26
  let implementation: HooksImplementation | null = null;
29
27
 
@@ -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
  type LogEvent = (eventData: string) => void;
@@ -5,12 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  * @flow strict-local
8
- * @emails oncall+relay
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 invariant = require('invariant');
@@ -4,15 +4,13 @@
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
+ import type {OperationType} from '../../relay-runtime/util/RelayRuntimeTypes';
16
14
  import type {
17
15
  EntryPoint,
18
16
  EntryPointComponent,
@@ -27,13 +25,13 @@ const React = require('react');
27
25
  const {useContext, useEffect, useMemo} = require('react');
28
26
  const {stableCopy} = require('relay-runtime');
29
27
 
30
- type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{|
28
+ type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{
31
29
  entryPoints: React.ElementConfig<TEntryPointComponent>['entryPoints'],
32
30
  extraProps: React.ElementConfig<TEntryPointComponent>['extraProps'],
33
31
  getComponent: () => TEntryPointComponent,
34
32
  queries: React.ElementConfig<TEntryPointComponent>['queries'],
35
33
  rootModuleID: string,
36
- |}>;
34
+ }>;
37
35
 
38
36
  type EntryPointContainerProps<
39
37
  TEntryPointParams,
@@ -42,7 +40,7 @@ type EntryPointContainerProps<
42
40
  TRuntimeProps,
43
41
  TExtraProps,
44
42
  > = $ReadOnly<
45
- $ReadOnly<{|
43
+ $ReadOnly<{
46
44
  entryPoint: EntryPoint<
47
45
  TEntryPointParams,
48
46
  EntryPointComponent<
@@ -55,7 +53,7 @@ type EntryPointContainerProps<
55
53
  entryPointParams: TEntryPointParams,
56
54
  environmentProvider?: IEnvironmentProvider<EnvironmentProviderOptions>,
57
55
  props: TRuntimeProps,
58
- |}>,
56
+ }>,
59
57
  >;
60
58
 
61
59
  function stableStringify(value: mixed): string {
@@ -99,7 +97,10 @@ function prepareEntryPoint<
99
97
  environmentProviderOptions,
100
98
  );
101
99
 
102
- preloadedQueries[queryPropName] = preloadQuery_DEPRECATED(
100
+ preloadedQueries[queryPropName] = preloadQuery_DEPRECATED<
101
+ OperationType,
102
+ mixed,
103
+ >(
103
104
  environment,
104
105
  parameters,
105
106
  variables,
@@ -118,11 +119,15 @@ function prepareEntryPoint<
118
119
  }
119
120
  const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
120
121
  entryPointDescription;
121
- preloadedEntryPoints[entryPointPropName] = prepareEntryPoint(
122
- environmentProvider,
123
- nestedEntryPoint,
124
- nestedParams,
125
- );
122
+ preloadedEntryPoints[entryPointPropName] = prepareEntryPoint<
123
+ _,
124
+ {...},
125
+ {...},
126
+ {...},
127
+ mixed,
128
+ EntryPointComponent<{...}, {...}, {...}, mixed>,
129
+ _,
130
+ >(environmentProvider, nestedEntryPoint, nestedParams);
126
131
  });
127
132
  }
128
133
  return {
@@ -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
  const React = require('react');
@@ -87,7 +85,7 @@ const {useMemo} = React;
87
85
 
88
86
  // Note: this type is intentionally non-exact, it is expected that the
89
87
  // object may contain sibling fields.
90
- type TypenameOnlyPointer = {|+__typename: string|};
88
+ type TypenameOnlyPointer = {+__typename: string};
91
89
  export type MatchPointer = {
92
90
  +__fragmentPropName?: ?string,
93
91
  +__module_component?: mixed,
@@ -95,12 +93,12 @@ export type MatchPointer = {
95
93
  ...
96
94
  };
97
95
 
98
- export type MatchContainerProps<TProps: {...}, TFallback: React.Node> = {|
96
+ export type MatchContainerProps<TProps: {...}, TFallback: React.Node> = {
99
97
  +fallback?: ?TFallback,
100
98
  +loader: (module: mixed) => React.AbstractComponent<TProps>,
101
99
  +match: ?MatchPointer | ?TypenameOnlyPointer,
102
100
  +props?: TProps,
103
- |};
101
+ };
104
102
 
105
103
  function MatchContainer<TProps: {...}, TFallback: React.Node | null>({
106
104
  fallback,
@@ -150,11 +148,11 @@ function MatchContainer<TProps: {...}, TFallback: React.Node | null>({
150
148
  // output of subscriptions already has a stable identity.
151
149
  if (__fragmentPropName != null && __id != null && __fragments != null) {
152
150
  const fragProps: {
153
- [string]: {|
151
+ [string]: {
154
152
  __fragmentOwner: $FlowFixMe,
155
153
  __fragments: $FlowFixMe,
156
154
  __id: string,
157
- |},
155
+ },
158
156
  } = {};
159
157
  fragProps[__fragmentPropName] = {__id, __fragments, __fragmentOwner};
160
158
  return fragProps;
@@ -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
  // This contextual profiler can be used to wrap a react sub-tree. It will bind
15
13
  // the RelayProfiler during the render phase of these components. Allows
16
14
  // collecting metrics for a specific part of your application.
@@ -5,12 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  * @flow strict-local
8
- * @emails oncall+relay
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 {Cache} from './LRUCache';
@@ -37,11 +35,12 @@ const warning = require('warning');
37
35
 
38
36
  const CACHE_CAPACITY = 1000;
39
37
  const DEFAULT_FETCH_POLICY = 'store-or-network';
38
+ const DEFAULT_LIVE_FETCH_POLICY = 'store-and-network';
40
39
 
41
40
  export type QueryResource = QueryResourceImpl;
42
41
 
43
42
  type QueryResourceCache = Cache<QueryResourceCacheEntry>;
44
- type QueryResourceCacheEntry = {|
43
+ type QueryResourceCacheEntry = {
45
44
  +id: number,
46
45
  +cacheIdentifier: string,
47
46
  +operationAvailability: ?OperationAvailability,
@@ -56,17 +55,17 @@ type QueryResourceCacheEntry = {|
56
55
  temporaryRetain(environment: IEnvironment): Disposable,
57
56
  permanentRetain(environment: IEnvironment): Disposable,
58
57
  releaseTemporaryRetain(): void,
59
- |};
58
+ };
60
59
  export opaque type QueryResult: {
61
60
  fragmentNode: ReaderFragment,
62
61
  fragmentRef: mixed,
63
62
  ...
64
- } = {|
63
+ } = {
65
64
  cacheIdentifier: string,
66
65
  fragmentNode: ReaderFragment,
67
66
  fragmentRef: mixed,
68
67
  operation: OperationDescriptor,
69
- |};
68
+ };
70
69
 
71
70
  const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
72
71
  interface IMap<K, V> {
@@ -85,7 +84,11 @@ function getQueryCacheIdentifier(
85
84
  maybeRenderPolicy: ?RenderPolicy,
86
85
  cacheBreaker?: ?string | ?number,
87
86
  ): string {
88
- const fetchPolicy = maybeFetchPolicy ?? DEFAULT_FETCH_POLICY;
87
+ const fetchPolicy =
88
+ maybeFetchPolicy ??
89
+ (operationIsLiveQuery(operation)
90
+ ? DEFAULT_LIVE_FETCH_POLICY
91
+ : DEFAULT_FETCH_POLICY);
89
92
  const renderPolicy =
90
93
  maybeRenderPolicy ?? environment.UNSTABLE_getDefaultRenderPolicy();
91
94
  const cacheIdentifier = `${fetchPolicy}-${renderPolicy}-${operation.request.identifier}`;
@@ -145,7 +148,18 @@ function createCacheEntry(
145
148
  };
146
149
  });
147
150
 
148
- const cacheEntry = {
151
+ const cacheEntry: {
152
+ cacheIdentifier: string,
153
+ getValue(): QueryResult | Promise<void> | Error,
154
+ id: number,
155
+ operationAvailability: ?OperationAvailability,
156
+ permanentRetain(environment: IEnvironment): Disposable,
157
+ processedPayloadsCount: number,
158
+ releaseTemporaryRetain(): void,
159
+ setNetworkSubscription(subscription: ?Subscription): void,
160
+ setValue(val: QueryResult | Promise<void> | Error): void,
161
+ temporaryRetain(environment: IEnvironment): Disposable,
162
+ } = {
149
163
  cacheIdentifier,
150
164
  id: nextID++,
151
165
  processedPayloadsCount: 0,
@@ -227,7 +241,11 @@ class QueryResourceImpl {
227
241
  profilerContext: mixed,
228
242
  ): QueryResult {
229
243
  const environment = this._environment;
230
- const fetchPolicy = maybeFetchPolicy ?? DEFAULT_FETCH_POLICY;
244
+ const fetchPolicy =
245
+ maybeFetchPolicy ??
246
+ (operationIsLiveQuery(operation)
247
+ ? DEFAULT_LIVE_FETCH_POLICY
248
+ : DEFAULT_FETCH_POLICY);
231
249
  const renderPolicy =
232
250
  maybeRenderPolicy ?? environment.UNSTABLE_getDefaultRenderPolicy();
233
251
 
@@ -527,7 +545,7 @@ class QueryResourceImpl {
527
545
 
528
546
  let cacheEntry = this._cache.get(cacheIdentifier);
529
547
  if (!cacheEntry) {
530
- const networkPromise = new Promise(resolve => {
548
+ const networkPromise = new Promise<void>(resolve => {
531
549
  resolveNetworkPromise = resolve;
532
550
  });
533
551
 
@@ -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 {IEnvironment} from 'relay-runtime';
@@ -19,18 +17,18 @@ import type {
19
17
  IActorEnvironment,
20
18
  } from 'relay-runtime/multi-actor-environment';
21
19
 
20
+ const ReactRelayContext = require('./../ReactRelayContext');
22
21
  const React = require('react');
23
- const ReactRelayContext = require('react-relay/ReactRelayContext');
24
22
 
25
23
  const {useMemo} = React;
26
24
 
27
- type Props = $ReadOnly<{|
25
+ type Props = $ReadOnly<{
28
26
  children: React.Node,
29
27
  environment: IEnvironment,
30
28
  getEnvironmentForActor?: ?(
31
29
  actorIdentifier: ActorIdentifier,
32
30
  ) => IActorEnvironment,
33
- |}>;
31
+ }>;
34
32
 
35
33
  function RelayEnvironmentProvider(props: Props): React.Node {
36
34
  const {children, environment, getEnvironmentForActor} = props;
@@ -5,12 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  * @flow strict-local
8
- * @emails oncall+relay
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 {Disposable, IEnvironment} from 'relay-runtime';
@@ -4,11 +4,13 @@
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
+ /* eslint-disable no-unused-vars */
13
+
12
14
  'use strict';
13
15
 
14
16
  import type {
@@ -17,15 +19,15 @@ import type {
17
19
  EntryPointProps,
18
20
  } from '../../EntryPointTypes.flow';
19
21
 
20
- type MyComponentOtherProps = $ReadOnly<{|
22
+ type MyComponentOtherProps = $ReadOnly<{
21
23
  foo: string,
22
- |}>;
24
+ }>;
23
25
 
24
26
  type MyComponentProps = EntryPointProps<{}, {}, MyComponentOtherProps, {}>;
25
27
 
26
28
  const MyComponent = (_props: MyComponentProps) => null;
27
29
 
28
- type PreloadParams = $ReadOnly<{||}>;
30
+ type PreloadParams = $ReadOnly<{}>;
29
31
 
30
32
  type MyComponentEntryPointType = EntryPoint<PreloadParams, typeof MyComponent>;
31
33
 
@@ -4,19 +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 {JSResourceReference} from 'JSResourceReference';
15
14
  import type {
16
15
  EntryPoint,
17
16
  EntryPointProps,
18
17
  PreloadedEntryPoint,
19
18
  } from '../../EntryPointTypes.flow';
19
+ import type {JSResourceReference} from 'JSResourceReference';
20
20
 
21
21
  declare function mockJSResource<TModule>(
22
22
  module: TModule,
@@ -27,9 +27,9 @@ type NestedEntrypointComponentProps = EntryPointProps<{}>;
27
27
  const NestedEntrypointComponent = (_props: NestedEntrypointComponentProps) =>
28
28
  null;
29
29
 
30
- type NestedEntrypointPreloadParams = $ReadOnly<{|
30
+ type NestedEntrypointPreloadParams = $ReadOnly<{
31
31
  subEntrypointPreloadParam: string,
32
- |}>;
32
+ }>;
33
33
 
34
34
  type NestedEntryPointType = EntryPoint<
35
35
  NestedEntrypointPreloadParams,
@@ -4,7 +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
- * @generated SignedSource<<8a8e68a3fde4da3f77546ac4952f2635>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<fef9e96f393a59b2e761b70b1c3ddc50>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep
@@ -4,7 +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
- * @generated SignedSource<<0b4a6e76a104111de9ddd4dd9abe667c>>
7
+ * @oncall relay
8
+ *
9
+ * @generated SignedSource<<1bd343735be9917826ee3203cf6756c4>>
8
10
  * @flow
9
11
  * @lightSyntaxTransform
10
12
  * @nogrep