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,92 +4,92 @@
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
  import type {LoadMoreFn} from '../useLoadMoreFunction';
15
13
  import type {
16
14
  FetchFn,
17
15
  NonNullableData,
18
16
  NullableData,
19
- QueryOperation,
20
17
  QueryVariables,
21
18
  QueryVariablesSubset,
22
19
  } from './utils';
23
- import type {IEnvironment, OperationType} from 'relay-runtime';
20
+ import type {IEnvironment, Variables} from 'relay-runtime';
24
21
 
25
22
  import useBlockingPaginationFragment from '../useBlockingPaginationFragment';
26
23
  import {
27
24
  fragmentData,
28
- fragmentInput,
29
25
  keyAnotherNonNullable,
30
26
  keyAnotherNullable,
31
27
  keyNonNullable,
32
28
  keyNullable,
29
+ refetchableFragmentInput,
33
30
  } from './utils';
34
31
 
35
32
  type ExpectedReturnType<
36
- TQuery: OperationType,
37
- TQueryVariables,
33
+ TRefetchVariables: Variables,
34
+ TLoadMoreVariables: Variables,
38
35
  TFragmentData,
39
- > = {|
36
+ > = {
40
37
  data: TFragmentData,
41
- loadNext: LoadMoreFn<TQuery>,
42
- loadPrevious: LoadMoreFn<TQuery>,
38
+ loadNext: LoadMoreFn<TLoadMoreVariables>,
39
+ loadPrevious: LoadMoreFn<TLoadMoreVariables>,
43
40
  hasNext: boolean,
44
41
  hasPrevious: boolean,
45
- refetch: FetchFn<TQueryVariables>,
46
- |};
42
+ refetch: FetchFn<TRefetchVariables>,
43
+ };
47
44
 
48
45
  /* eslint-disable react-hooks/rules-of-hooks */
49
46
 
50
47
  // Nullability of returned data type is correct
51
- (useBlockingPaginationFragment<QueryOperation, _>(
52
- fragmentInput,
48
+ (useBlockingPaginationFragment(
49
+ refetchableFragmentInput,
53
50
  keyNonNullable,
54
- ): ExpectedReturnType<QueryOperation, QueryVariablesSubset, NonNullableData>);
51
+ ): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
55
52
 
56
- (useBlockingPaginationFragment<QueryOperation, _>(
57
- fragmentInput,
53
+ (useBlockingPaginationFragment(
54
+ refetchableFragmentInput,
58
55
  keyNullable,
59
- ): ExpectedReturnType<QueryOperation, QueryVariables, NullableData>);
56
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
60
57
 
61
58
  // $FlowExpectedError: can't cast nullable to non-nullable
62
- (useBlockingPaginationFragment<QueryOperation, _>(
63
- fragmentInput,
59
+ (useBlockingPaginationFragment(
60
+ refetchableFragmentInput,
64
61
  keyNullable,
65
- ): ExpectedReturnType<QueryOperation, QueryVariables, NonNullableData>);
62
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
66
63
 
67
64
  // $FlowExpectedError: actual type of returned data is correct
68
- (useBlockingPaginationFragment<QueryOperation, _>(
69
- fragmentInput,
65
+ (useBlockingPaginationFragment(
66
+ refetchableFragmentInput,
67
+ // $FlowExpectedError[incompatible-call]
70
68
  keyAnotherNonNullable,
71
- ): ExpectedReturnType<QueryOperation, QueryVariablesSubset, NonNullableData>);
72
- // $FlowExpectedError
73
- (useBlockingPaginationFragment<QueryOperation, _>(
74
- fragmentInput,
69
+ ): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
70
+
71
+ // $FlowExpectedError[incompatible-call] `Example_user$fragmentType` is incompatible with `FragmentType`
72
+ (useBlockingPaginationFragment(
73
+ refetchableFragmentInput,
74
+ // $FlowExpectedError[incompatible-call]
75
75
  keyAnotherNullable,
76
- ): ExpectedReturnType<QueryOperation, QueryVariables, NullableData>);
76
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
77
77
 
78
78
  // $FlowExpectedError: Key should not be a user provided object
79
- useBlockingPaginationFragment<QueryOperation, _>(fragmentInput, {abc: 123});
79
+ useBlockingPaginationFragment(fragmentInput, {abc: 123});
80
80
 
81
81
  // $FlowExpectedError: Key should not be an empty object
82
- useBlockingPaginationFragment<QueryOperation, _>(fragmentInput, {});
82
+ useBlockingPaginationFragment(fragmentInput, {});
83
83
 
84
84
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
85
- useBlockingPaginationFragment<QueryOperation, _>(fragmentInput, fragmentData);
85
+ useBlockingPaginationFragment(fragmentInput, fragmentData);
86
86
 
87
87
  // Refetch function options:
88
88
  declare var variables: QueryVariables;
89
89
  declare var environment: IEnvironment;
90
90
 
91
- const {refetch} = useBlockingPaginationFragment<QueryOperation, _>(
92
- fragmentInput,
91
+ const {refetch} = useBlockingPaginationFragment(
92
+ refetchableFragmentInput,
93
93
  keyNonNullable,
94
94
  );
95
95
  // $FlowExpectedError: internal option
@@ -103,11 +103,11 @@ refetch(variables, {
103
103
  });
104
104
 
105
105
  // LoadMore options
106
- declare var extraVariables: {|nickname: string|};
107
- declare var invalidVariables: {|foo: string|};
106
+ declare var extraVariables: {nickname: string};
107
+ declare var invalidVariables: {foo: string};
108
108
 
109
- const {loadNext} = useBlockingPaginationFragment<QueryOperation, _>(
110
- fragmentInput,
109
+ const {loadNext} = useBlockingPaginationFragment(
110
+ refetchableFragmentInput,
111
111
  keyNonNullable,
112
112
  );
113
113
  // Accepts extraVariables
@@ -115,8 +115,8 @@ loadNext(10, {
115
115
  UNSTABLE_extraVariables: extraVariables,
116
116
  });
117
117
 
118
- // $FlowExpectedError: doesn't accept variables not available in the Flow type
119
118
  loadNext(10, {
119
+ // $FlowExpectedError: doesn't accept variables not available in the Flow type
120
120
  UNSTABLE_extraVariables: invalidVariables,
121
121
  });
122
122
 
@@ -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
  import type {
15
13
  useFragmentFlowtest_user$data,
16
14
  useFragmentFlowtest_user$key,
@@ -4,94 +4,93 @@
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
  import type {LoadMoreFn} from '../useLoadMoreFunction';
15
13
  import type {
16
14
  FetchFn,
17
15
  NonNullableData,
18
16
  NullableData,
19
- QueryOperation,
20
17
  QueryVariables,
21
18
  QueryVariablesSubset,
22
19
  } from './utils';
23
- import type {IEnvironment, OperationType} from 'relay-runtime';
20
+ import type {IEnvironment, Variables} from 'relay-runtime';
24
21
 
25
22
  import usePaginationFragment from '../usePaginationFragment';
26
23
  import {
27
24
  fragmentData,
28
- fragmentInput,
29
25
  keyAnotherNonNullable,
30
26
  keyAnotherNullable,
31
27
  keyNonNullable,
32
28
  keyNullable,
29
+ refetchableFragmentInput,
33
30
  } from './utils';
34
31
 
35
32
  type ExpectedReturnType<
36
- TQuery: OperationType,
37
- TQueryVariables,
33
+ TRefetchVariables: Variables,
34
+ TLoadMoreVariables: Variables,
38
35
  TFragmentData,
39
- > = {|
36
+ > = {
40
37
  data: TFragmentData,
41
- loadNext: LoadMoreFn<TQuery>,
42
- loadPrevious: LoadMoreFn<TQuery>,
38
+ loadNext: LoadMoreFn<TLoadMoreVariables>,
39
+ loadPrevious: LoadMoreFn<TLoadMoreVariables>,
43
40
  hasNext: boolean,
44
41
  hasPrevious: boolean,
45
42
  isLoadingNext: boolean,
46
43
  isLoadingPrevious: boolean,
47
- refetch: FetchFn<TQueryVariables>,
48
- |};
44
+ refetch: FetchFn<TRefetchVariables>,
45
+ };
49
46
 
50
47
  /* eslint-disable react-hooks/rules-of-hooks */
51
48
 
52
49
  // Nullability of returned data type is correct
53
- (usePaginationFragment<QueryOperation, _>(
54
- fragmentInput,
50
+ (usePaginationFragment(
51
+ refetchableFragmentInput,
55
52
  keyNonNullable,
56
- ): ExpectedReturnType<QueryOperation, QueryVariablesSubset, NonNullableData>);
53
+ ): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
57
54
 
58
- (usePaginationFragment<QueryOperation, _>(
59
- fragmentInput,
55
+ (usePaginationFragment(
56
+ refetchableFragmentInput,
60
57
  keyNullable,
61
- ): ExpectedReturnType<QueryOperation, QueryVariables, NullableData>);
58
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
62
59
 
63
60
  // $FlowExpectedError: can't cast nullable to non-nullable
64
- (usePaginationFragment<QueryOperation, _>(
65
- fragmentInput,
61
+ (usePaginationFragment(
62
+ refetchableFragmentInput,
66
63
  keyNullable,
67
- ): ExpectedReturnType<QueryOperation, QueryVariables, NonNullableData>);
64
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
68
65
 
69
66
  // $FlowExpectedError: actual type of returned data is correct
70
- (usePaginationFragment<QueryOperation, _>(
71
- fragmentInput,
67
+ (usePaginationFragment(
68
+ refetchableFragmentInput,
69
+ // $FlowFixMe[incompatible-call]
72
70
  keyAnotherNonNullable,
73
- ): ExpectedReturnType<QueryOperation, QueryVariablesSubset, NonNullableData>);
71
+ ): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
74
72
  // $FlowExpectedError
75
- (usePaginationFragment<QueryOperation, _>(
76
- fragmentInput,
73
+ (usePaginationFragment(
74
+ refetchableFragmentInput,
75
+ // $FlowFixMe[incompatible-call]
77
76
  keyAnotherNullable,
78
- ): ExpectedReturnType<QueryOperation, QueryVariables, NullableData>);
77
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
79
78
 
80
79
  // $FlowExpectedError: Key should not be a user provided object
81
- usePaginationFragment<QueryOperation, _>(fragmentInput, {abc: 123});
80
+ usePaginationFragment(refetchableFragmentInput, {abc: 123});
82
81
 
83
82
  // $FlowExpectedError: Key should not be an empty object
84
- usePaginationFragment<QueryOperation, _>(fragmentInput, {});
83
+ usePaginationFragment(refetchableFragmentInput, {});
85
84
 
86
85
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
87
- usePaginationFragment<QueryOperation, _>(fragmentInput, fragmentData);
86
+ usePaginationFragment(refetchableFragmentInput, fragmentData);
88
87
 
89
88
  // Refetch function options:
90
89
  declare var variables: QueryVariables;
91
90
  declare var environment: IEnvironment;
92
91
 
93
- const {refetch} = usePaginationFragment<QueryOperation, _>(
94
- fragmentInput,
92
+ const {refetch} = usePaginationFragment(
93
+ refetchableFragmentInput,
95
94
  keyNonNullable,
96
95
  );
97
96
  // $FlowExpectedError: internal option
@@ -105,11 +104,11 @@ refetch(variables, {
105
104
  });
106
105
 
107
106
  // LoadMore options
108
- declare var extraVariables: {|nickname: string|};
109
- declare var invalidVariables: {|foo: string|};
107
+ declare var extraVariables: {nickname: string};
108
+ declare var invalidVariables: {foo: string};
110
109
 
111
- const {loadNext} = usePaginationFragment<QueryOperation, _>(
112
- fragmentInput,
110
+ const {loadNext} = usePaginationFragment(
111
+ refetchableFragmentInput,
113
112
  keyNonNullable,
114
113
  );
115
114
  // Accepts extraVariables
@@ -117,8 +116,8 @@ loadNext(10, {
117
116
  UNSTABLE_extraVariables: extraVariables,
118
117
  });
119
118
 
120
- // $FlowExpectedError: doesn't accept variables not available in the Flow type
121
119
  loadNext(10, {
120
+ // $FlowExpectedError: doesn't accept variables not available in the Flow type
122
121
  UNSTABLE_extraVariables: invalidVariables,
123
122
  });
124
123
 
@@ -4,18 +4,15 @@
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
  import type {
15
13
  FetchFn,
16
14
  NonNullableData,
17
15
  NullableData,
18
- QueryOperation,
19
16
  QueryVariables,
20
17
  QueryVariablesSubset,
21
18
  } from './utils';
@@ -24,64 +21,65 @@ import type {IEnvironment} from 'relay-runtime';
24
21
  import useRefetchableFragment from '../useRefetchableFragment';
25
22
  import {
26
23
  fragmentData,
27
- fragmentInput,
28
24
  keyAnotherNonNullable,
29
25
  keyAnotherNullable,
30
26
  keyNonNullable,
31
27
  keyNullable,
28
+ refetchableFragmentInput,
32
29
  } from './utils';
33
30
 
34
31
  /* eslint-disable react-hooks/rules-of-hooks */
35
32
 
36
33
  // Nullability of returned data type is correct
37
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyNonNullable): [
34
+ (useRefetchableFragment(refetchableFragmentInput, keyNonNullable): [
38
35
  NonNullableData,
39
36
  FetchFn<QueryVariablesSubset>,
40
37
  ]);
41
38
 
42
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyNullable): [
39
+ (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
43
40
  NullableData,
44
41
  FetchFn<QueryVariables>,
45
42
  ]);
46
43
 
47
44
  // $FlowExpectedError: can't cast nullable to non-nullable
48
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyNullable): [
45
+ (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
49
46
  NonNullableData,
50
47
  FetchFn<QueryVariables>,
51
48
  ]);
52
49
 
53
50
  // $FlowExpectedError: refetch requires exact type if key is nullable
54
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyNullable): [
51
+ (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
55
52
  NullableData,
56
53
  FetchFn<QueryVariablesSubset>,
57
54
  ]);
58
55
 
59
56
  // $FlowExpectedError: actual type of returned data is correct
60
- (useRefetchableFragment<QueryOperation, _>(
61
- fragmentInput,
62
- keyAnotherNonNullable,
63
- ): [NonNullableData, FetchFn<QueryVariablesSubset>]);
64
- // $FlowExpectedError
65
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyAnotherNullable): [
57
+ (useRefetchableFragment(refetchableFragmentInput, keyAnotherNonNullable): [
58
+ NonNullableData,
59
+ FetchFn<QueryVariablesSubset>,
60
+ ]);
61
+
62
+ // $FlowExpectedError - incompatible key types
63
+ (useRefetchableFragment(refetchableFragmentInput, keyAnotherNullable): [
66
64
  NullableData,
67
65
  FetchFn<QueryVariables>,
68
66
  ]);
69
67
 
70
68
  // $FlowExpectedError: Key should not be a user provided object
71
- useRefetchableFragment<QueryOperation, _>(fragmentInput, {abc: 123});
69
+ useRefetchableFragment(refetchableFragmentInput, {abc: 123});
72
70
 
73
71
  // $FlowExpectedError: Key should not be an empty object
74
- useRefetchableFragment<QueryOperation, _>(fragmentInput, {});
72
+ useRefetchableFragment(refetchableFragmentInput, {});
75
73
 
76
74
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
77
- useRefetchableFragment<QueryOperation, _>(fragmentInput, fragmentData);
75
+ useRefetchableFragment(refetchableFragmentInput, fragmentData);
78
76
 
79
77
  // Refetch function options:
80
78
  declare var variables: QueryVariables;
81
79
  declare var environment: IEnvironment;
82
80
 
83
- const [_, refetch] = useRefetchableFragment<QueryOperation, _>(
84
- fragmentInput,
81
+ const [, refetch] = useRefetchableFragment(
82
+ refetchableFragmentInput,
85
83
  keyNonNullable,
86
84
  );
87
85
  // $FlowExpectedError: internal option
@@ -4,22 +4,31 @@
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
- import type {Disposable, Fragment, FragmentType} from 'relay-runtime';
14
+ import type {
15
+ Disposable,
16
+ Fragment,
17
+ FragmentType,
18
+ RefetchableFragment,
19
+ } from 'relay-runtime';
17
20
 
18
21
  declare export var fragmentInput: Fragment<
19
22
  Example_user$fragmentType,
20
23
  Example_user$data,
21
24
  >;
22
25
 
26
+ declare export var refetchableFragmentInput: RefetchableFragment<
27
+ Example_user$fragmentType,
28
+ Example_user$data,
29
+ QueryVariables,
30
+ >;
31
+
23
32
  declare export opaque type Example_user$fragmentType: FragmentType;
24
33
  export type Example_user$data = NonNullableData;
25
34
  export type Example_user$key = {
@@ -28,18 +37,18 @@ export type Example_user$key = {
28
37
  ...
29
38
  };
30
39
 
31
- export type NonNullableData = {|
40
+ export type NonNullableData = {
32
41
  +id: string,
33
42
  +count: number,
34
- |};
43
+ };
35
44
  export type NullableData = ?NonNullableData;
36
45
  export type NonNullablePluralData = $ReadOnlyArray<NonNullableData>;
37
46
  export type NullablePluralData = ?$ReadOnlyArray<NonNullableData>;
38
47
 
39
- export type AnotherNonNullableData = {|
48
+ export type AnotherNonNullableData = {
40
49
  +name: ?string,
41
50
  +friends: ?number,
42
- |};
51
+ };
43
52
 
44
53
  declare export var keyNonNullable: Example_user$key;
45
54
 
@@ -66,16 +75,16 @@ declare export var fragmentData: {
66
75
  ...
67
76
  };
68
77
 
69
- export type QueryOperation = {|
78
+ export type QueryOperation = {
70
79
  +variables: QueryVariables,
71
80
  +response: {...},
72
- |};
81
+ };
73
82
 
74
- export type QueryVariables = {|
83
+ export type QueryVariables = {
75
84
  id: string,
76
85
  nickname: ?string,
77
86
  name: string,
78
- |};
87
+ };
79
88
 
80
89
  export type QueryVariablesSubset = {
81
90
  id: string,
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
- * @emails oncall+relay
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  'use strict';
@@ -58,6 +58,7 @@ function loadEntryPoint<
58
58
  environmentProviderOptions,
59
59
  );
60
60
 
61
+ // $FlowFixMe[underconstrained-implicit-instantiation]
61
62
  preloadedQueries[queryPropName] = loadQuery(
62
63
  environment,
63
64
  parameters,
@@ -81,11 +82,15 @@ function loadEntryPoint<
81
82
  }
82
83
  const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
83
84
  entryPointDescription;
84
- preloadedEntryPoints[entryPointPropName] = loadEntryPoint(
85
- environmentProvider,
86
- nestedEntryPoint,
87
- nestedParams,
88
- );
85
+ preloadedEntryPoints[entryPointPropName] = loadEntryPoint<
86
+ _,
87
+ {...},
88
+ {...},
89
+ {...},
90
+ mixed,
91
+ EntryPointComponent<{...}, {...}, {...}, mixed>,
92
+ _,
93
+ >(environmentProvider, nestedEntryPoint, nestedParams);
89
94
  });
90
95
  }
91
96
 
@@ -6,12 +6,13 @@
6
6
  *
7
7
  * @flow strict-local
8
8
  * @format
9
- * @emails oncall+relay
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  'use strict';
13
13
 
14
14
  import type {
15
+ EnvironmentProviderOptions,
15
16
  LoadQueryOptions,
16
17
  PreloadableConcreteRequest,
17
18
  PreloadedQueryInner,
@@ -30,11 +31,11 @@ import type {
30
31
  const invariant = require('invariant');
31
32
  const React = require('react');
32
33
  const {
34
+ __internal: {fetchQueryDeduped},
33
35
  Observable,
34
36
  PreloadableQueryRegistry,
35
37
  RelayFeatureFlags,
36
38
  ReplaySubject,
37
- __internal: {fetchQueryDeduped},
38
39
  createOperationDescriptor,
39
40
  getRequest,
40
41
  getRequestIdentifier,
@@ -55,7 +56,10 @@ function useTrackLoadQueryInRender() {
55
56
  }
56
57
  }
57
58
 
58
- function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
59
+ function loadQuery<
60
+ TQuery: OperationType,
61
+ TEnvironmentProviderOptions = EnvironmentProviderOptions,
62
+ >(
59
63
  environment: IEnvironment,
60
64
  preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
61
65
  variables: TQuery['variables'],
@@ -115,8 +119,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
115
119
  // allows us to capture the events that occur during the eager execution
116
120
  // of the operation, and then replay them to the Observable we
117
121
  // ultimately return.
118
- const executionSubject = new ReplaySubject();
119
- const returnedObservable = Observable.create(sink =>
122
+ const executionSubject = new ReplaySubject<GraphQLResponse>();
123
+ const returnedObservable = Observable.create<GraphQLResponse>(sink =>
120
124
  executionSubject.subscribe(sink),
121
125
  );
122
126
 
@@ -139,7 +143,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
139
143
  didMakeNetworkRequest = true;
140
144
 
141
145
  let observable;
142
- const subject = new ReplaySubject();
146
+ const subject = new ReplaySubject<GraphQLResponse>();
143
147
  if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
144
148
  // Here, we are calling fetchQueryDeduped at the network layer level,
145
149
  // which ensures that only a single network request is active for a given
@@ -270,7 +274,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
270
274
  };
271
275
 
272
276
  let params;
273
- let cancelOnLoadCallback;
277
+ let cancelOnLoadCallback: () => void;
274
278
  let queryId;
275
279
  if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
276
280
  const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
@@ -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 {
@@ -33,7 +31,6 @@ import type {
33
31
  const {
34
32
  Observable,
35
33
  PreloadableQueryRegistry,
36
- RelayFeatureFlags,
37
34
  ReplaySubject,
38
35
  createOperationDescriptor,
39
36
  getRequest,
@@ -47,11 +44,11 @@ const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
47
44
  const STORE_OR_NETWORK_DEFAULT: PreloadFetchPolicy = 'store-or-network';
48
45
 
49
46
  const pendingQueriesByEnvironment = WEAKMAP_SUPPORTED
50
- ? new WeakMap()
51
- : new Map();
47
+ ? new WeakMap<IEnvironment, Map<string, PendingQueryEntry>>()
48
+ : new Map<IEnvironment, Map<string, PendingQueryEntry>>();
52
49
 
53
50
  type PendingQueryEntry =
54
- | $ReadOnly<{|
51
+ | $ReadOnly<{
55
52
  cacheKey: string,
56
53
  fetchKey: ?string | ?number,
57
54
  fetchPolicy: PreloadFetchPolicy,
@@ -61,8 +58,8 @@ type PendingQueryEntry =
61
58
  status: PreloadQueryStatus,
62
59
  subject: ReplaySubject<GraphQLResponse>,
63
60
  subscription: Subscription,
64
- |}>
65
- | $ReadOnly<{|
61
+ }>
62
+ | $ReadOnly<{
66
63
  cacheKey: string,
67
64
  fetchKey: ?string | ?number,
68
65
  fetchPolicy: PreloadFetchPolicy,
@@ -70,7 +67,7 @@ type PendingQueryEntry =
70
67
  id: ?string,
71
68
  name: string,
72
69
  status: PreloadQueryStatus,
73
- |}>;
70
+ }>;
74
71
 
75
72
  function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
76
73
  environment: IEnvironment,
@@ -94,7 +91,7 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
94
91
  );
95
92
  const source =
96
93
  queryEntry.kind === 'network'
97
- ? Observable.create(sink => {
94
+ ? Observable.create<GraphQLResponse>(sink => {
98
95
  let subscription;
99
96
  if (pendingQueries.get(queryEntry.cacheKey) == null) {
100
97
  const newQueryEntry = preloadQueryDeduped(
@@ -207,7 +204,7 @@ function preloadQueryDeduped<TQuery: OperationType>(
207
204
  } else if (prevQueryEntry == null || prevQueryEntry.kind !== 'network') {
208
205
  // Should fetch but we're not already fetching: fetch!
209
206
  const source = network.execute(params, variables, networkCacheConfig, null);
210
- const subject = new ReplaySubject();
207
+ const subject = new ReplaySubject<GraphQLResponse>();
211
208
  nextQueryEntry = {
212
209
  cacheKey,
213
210
  fetchKey,