react-relay 14.1.0 → 16.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 (196) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -0
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -0
  4. package/ReactRelayFragmentContainer.js.flow +6 -2
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -0
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -3
  7. package/ReactRelayPaginationContainer.js.flow +21 -12
  8. package/ReactRelayQueryFetcher.js.flow +20 -10
  9. package/ReactRelayQueryRenderer.js.flow +15 -11
  10. package/ReactRelayQueryRendererContext.js.flow +1 -0
  11. package/ReactRelayRefetchContainer.js.flow +9 -5
  12. package/ReactRelayTestMocker.js.flow +3 -1
  13. package/ReactRelayTypes.js.flow +2 -0
  14. package/RelayContext.js.flow +1 -0
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
  18. package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -0
  34. package/buildReactRelayContainer.js.flow +10 -6
  35. package/getRootVariablesForFragments.js.flow +1 -1
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -0
  38. package/index.js +1 -1
  39. package/index.js.flow +4 -0
  40. package/isRelayEnvironment.js.flow +1 -0
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -0
  46. package/lib/ReactRelayContainerUtils.js +0 -11
  47. package/lib/ReactRelayContext.js +1 -12
  48. package/lib/ReactRelayFragmentContainer.js +23 -122
  49. package/lib/ReactRelayFragmentMockRenderer.js +0 -12
  50. package/lib/ReactRelayLocalQueryRenderer.js +12 -41
  51. package/lib/ReactRelayPaginationContainer.js +45 -341
  52. package/lib/ReactRelayQueryFetcher.js +36 -111
  53. package/lib/ReactRelayQueryRenderer.js +29 -137
  54. package/lib/ReactRelayQueryRendererContext.js +0 -10
  55. package/lib/ReactRelayRefetchContainer.js +33 -166
  56. package/lib/ReactRelayTestMocker.js +18 -128
  57. package/lib/ReactRelayTypes.js +0 -9
  58. package/lib/RelayContext.js +0 -23
  59. package/lib/assertFragmentMap.js +0 -16
  60. package/lib/buildReactRelayContainer.js +7 -41
  61. package/lib/getRootVariablesForFragments.js +2 -19
  62. package/lib/hooks.js +3 -30
  63. package/lib/index.js +3 -39
  64. package/lib/isRelayEnvironment.js +1 -16
  65. package/lib/jest-react/enqueueTask.js +1 -25
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +2 -51
  68. package/lib/legacy.js +0 -20
  69. package/lib/multi-actor/ActorChange.js +0 -14
  70. package/lib/multi-actor/index.js +0 -10
  71. package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
  72. package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
  74. package/lib/relay-hooks/FragmentResource.js +130 -280
  75. package/lib/relay-hooks/HooksImplementation.js +0 -14
  76. package/lib/relay-hooks/InternalLogger.js +0 -11
  77. package/lib/relay-hooks/LRUCache.js +0 -39
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
  79. package/lib/relay-hooks/MatchContainer.js +9 -111
  80. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  81. package/lib/relay-hooks/ProfilerContext.js +0 -14
  82. package/lib/relay-hooks/QueryResource.js +14 -149
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
  84. package/lib/relay-hooks/SuspenseResource.js +2 -59
  85. package/lib/relay-hooks/loadEntryPoint.js +10 -45
  86. package/lib/relay-hooks/loadQuery.js +29 -169
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
  89. package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
  90. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
  91. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
  92. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
  93. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
  94. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
  95. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
  96. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
  97. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
  98. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
  99. package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
  100. package/lib/relay-hooks/useClientQuery.js +0 -21
  101. package/lib/relay-hooks/useEntryPointLoader.js +12 -100
  102. package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
  103. package/lib/relay-hooks/useFragment.js +5 -32
  104. package/lib/relay-hooks/useFragmentNode.js +14 -55
  105. package/lib/relay-hooks/useIsMountedRef.js +2 -14
  106. package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
  107. package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
  108. package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
  109. package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
  110. package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
  111. package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
  112. package/lib/relay-hooks/useMemoVariables.js +8 -43
  113. package/lib/relay-hooks/useMutation.js +6 -34
  114. package/lib/relay-hooks/usePaginationFragment.js +49 -89
  115. package/lib/relay-hooks/usePreloadedQuery.js +10 -54
  116. package/lib/relay-hooks/useQueryLoader.js +18 -116
  117. package/lib/relay-hooks/useRefetchableFragment.js +4 -30
  118. package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
  119. package/lib/relay-hooks/useRelayEnvironment.js +2 -16
  120. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
  121. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
  122. package/lib/relay-hooks/useSubscription.js +3 -22
  123. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
  124. package/multi-actor/ActorChange.js.flow +1 -1
  125. package/multi-actor/index.js.flow +1 -1
  126. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  127. package/package.json +2 -2
  128. package/react-relay-hooks.js +2 -2
  129. package/react-relay-hooks.min.js +2 -2
  130. package/react-relay-legacy.js +2 -2
  131. package/react-relay-legacy.min.js +2 -2
  132. package/react-relay.js +2 -2
  133. package/react-relay.min.js +2 -2
  134. package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
  135. package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
  136. package/relay-hooks/FragmentResource.js.flow +148 -34
  137. package/relay-hooks/HooksImplementation.js.flow +1 -1
  138. package/relay-hooks/InternalLogger.js.flow +1 -1
  139. package/relay-hooks/LRUCache.js.flow +1 -1
  140. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
  141. package/relay-hooks/MatchContainer.js.flow +1 -1
  142. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  143. package/relay-hooks/ProfilerContext.js.flow +1 -1
  144. package/relay-hooks/QueryResource.js.flow +25 -5
  145. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  146. package/relay-hooks/SuspenseResource.js.flow +1 -1
  147. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
  149. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  150. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  151. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
  152. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  153. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
  154. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
  155. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  156. package/relay-hooks/loadEntryPoint.js.flow +15 -8
  157. package/relay-hooks/loadQuery.js.flow +32 -8
  158. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  159. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
  160. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  161. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
  163. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
  164. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
  165. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  166. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
  167. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  168. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
  169. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
  170. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
  171. package/relay-hooks/useClientQuery.js.flow +3 -3
  172. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  173. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  174. package/relay-hooks/useFragment.js.flow +2 -2
  175. package/relay-hooks/useFragmentNode.js.flow +7 -6
  176. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  177. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  178. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  179. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  180. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  181. package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
  182. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  183. package/relay-hooks/useMemoVariables.js.flow +13 -29
  184. package/relay-hooks/useMutation.js.flow +30 -13
  185. package/relay-hooks/usePaginationFragment.js.flow +55 -54
  186. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  187. package/relay-hooks/useQueryLoader.js.flow +78 -21
  188. package/relay-hooks/useRefetchableFragment.js.flow +65 -33
  189. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
  190. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  191. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  192. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  193. package/relay-hooks/useSubscription.js.flow +1 -1
  194. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  195. package/lib/readContext.js +0 -27
  196. package/readContext.js.flow +0 -29
@@ -4,9 +4,9 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  import type {LoadMoreFn} from '../useLoadMoreFunction';
@@ -14,80 +14,84 @@ import type {
14
14
  FetchFn,
15
15
  NonNullableData,
16
16
  NullableData,
17
- QueryOperation,
18
17
  QueryVariables,
19
18
  QueryVariablesSubset,
20
19
  } from './utils';
21
- import type {IEnvironment, OperationType} from 'relay-runtime';
20
+ import type {IEnvironment, Variables} from 'relay-runtime';
22
21
 
23
22
  import useBlockingPaginationFragment from '../useBlockingPaginationFragment';
24
23
  import {
25
24
  fragmentData,
26
- fragmentInput,
27
25
  keyAnotherNonNullable,
28
26
  keyAnotherNullable,
29
27
  keyNonNullable,
30
28
  keyNullable,
29
+ refetchableFragmentInput,
31
30
  } from './utils';
32
31
 
33
32
  type ExpectedReturnType<
34
- TQuery: OperationType,
35
- TQueryVariables,
33
+ TRefetchVariables: Variables,
34
+ TLoadMoreVariables: Variables,
36
35
  TFragmentData,
37
36
  > = {
38
37
  data: TFragmentData,
39
- loadNext: LoadMoreFn<TQuery>,
40
- loadPrevious: LoadMoreFn<TQuery>,
38
+ loadNext: LoadMoreFn<TLoadMoreVariables>,
39
+ loadPrevious: LoadMoreFn<TLoadMoreVariables>,
41
40
  hasNext: boolean,
42
41
  hasPrevious: boolean,
43
- refetch: FetchFn<TQueryVariables>,
42
+ refetch: FetchFn<TRefetchVariables>,
44
43
  };
45
44
 
46
45
  /* eslint-disable react-hooks/rules-of-hooks */
47
46
 
48
47
  // Nullability of returned data type is correct
49
- (useBlockingPaginationFragment<QueryOperation, _>(
50
- fragmentInput,
48
+ // $FlowFixMe[prop-missing]
49
+ // $FlowFixMe[incompatible-cast]
50
+ (useBlockingPaginationFragment(
51
+ refetchableFragmentInput,
51
52
  keyNonNullable,
52
- ): ExpectedReturnType<QueryOperation, QueryVariablesSubset, NonNullableData>);
53
+ ): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
53
54
 
54
- (useBlockingPaginationFragment<QueryOperation, _>(
55
- fragmentInput,
55
+ (useBlockingPaginationFragment(
56
+ refetchableFragmentInput,
56
57
  keyNullable,
57
- ): ExpectedReturnType<QueryOperation, QueryVariables, NullableData>);
58
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
58
59
 
59
60
  // $FlowExpectedError: can't cast nullable to non-nullable
60
- (useBlockingPaginationFragment<QueryOperation, _>(
61
- fragmentInput,
61
+ (useBlockingPaginationFragment(
62
+ refetchableFragmentInput,
62
63
  keyNullable,
63
- ): ExpectedReturnType<QueryOperation, QueryVariables, NonNullableData>);
64
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
64
65
 
65
66
  // $FlowExpectedError: actual type of returned data is correct
66
- (useBlockingPaginationFragment<QueryOperation, _>(
67
- fragmentInput,
67
+ (useBlockingPaginationFragment(
68
+ refetchableFragmentInput,
69
+ // $FlowExpectedError[incompatible-call]
68
70
  keyAnotherNonNullable,
69
- ): ExpectedReturnType<QueryOperation, QueryVariablesSubset, NonNullableData>);
70
- // $FlowExpectedError
71
- (useBlockingPaginationFragment<QueryOperation, _>(
72
- fragmentInput,
71
+ ): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
72
+
73
+ // $FlowExpectedError[incompatible-call] `Example_user$fragmentType` is incompatible with `FragmentType`
74
+ (useBlockingPaginationFragment(
75
+ refetchableFragmentInput,
76
+ // $FlowExpectedError[incompatible-call]
73
77
  keyAnotherNullable,
74
- ): ExpectedReturnType<QueryOperation, QueryVariables, NullableData>);
78
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
75
79
 
76
80
  // $FlowExpectedError: Key should not be a user provided object
77
- useBlockingPaginationFragment<QueryOperation, _>(fragmentInput, {abc: 123});
81
+ useBlockingPaginationFragment(fragmentInput, {abc: 123});
78
82
 
79
83
  // $FlowExpectedError: Key should not be an empty object
80
- useBlockingPaginationFragment<QueryOperation, _>(fragmentInput, {});
84
+ useBlockingPaginationFragment(fragmentInput, {});
81
85
 
82
86
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
83
- useBlockingPaginationFragment<QueryOperation, _>(fragmentInput, fragmentData);
87
+ useBlockingPaginationFragment(fragmentInput, fragmentData);
84
88
 
85
89
  // Refetch function options:
86
90
  declare var variables: QueryVariables;
87
91
  declare var environment: IEnvironment;
88
92
 
89
- const {refetch} = useBlockingPaginationFragment<QueryOperation, _>(
90
- fragmentInput,
93
+ const {refetch} = useBlockingPaginationFragment(
94
+ refetchableFragmentInput,
91
95
  keyNonNullable,
92
96
  );
93
97
  // $FlowExpectedError: internal option
@@ -104,17 +108,20 @@ refetch(variables, {
104
108
  declare var extraVariables: {nickname: string};
105
109
  declare var invalidVariables: {foo: string};
106
110
 
107
- const {loadNext} = useBlockingPaginationFragment<QueryOperation, _>(
108
- fragmentInput,
111
+ const {loadNext} = useBlockingPaginationFragment(
112
+ refetchableFragmentInput,
109
113
  keyNonNullable,
110
114
  );
111
115
  // Accepts extraVariables
112
116
  loadNext(10, {
117
+ // $FlowFixMe[prop-missing]
118
+ // $FlowFixMe[incompatible-call]
113
119
  UNSTABLE_extraVariables: extraVariables,
114
120
  });
115
121
 
116
- // $FlowExpectedError: doesn't accept variables not available in the Flow type
122
+ // $FlowFixMe[prop-missing]
117
123
  loadNext(10, {
124
+ // $FlowExpectedError: doesn't accept variables not available in the Flow type
118
125
  UNSTABLE_extraVariables: invalidVariables,
119
126
  });
120
127
 
@@ -4,9 +4,9 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  import type {
@@ -4,9 +4,9 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  import type {LoadMoreFn} from '../useLoadMoreFunction';
@@ -14,82 +14,85 @@ import type {
14
14
  FetchFn,
15
15
  NonNullableData,
16
16
  NullableData,
17
- QueryOperation,
18
17
  QueryVariables,
19
18
  QueryVariablesSubset,
20
19
  } from './utils';
21
- import type {IEnvironment, OperationType} from 'relay-runtime';
20
+ import type {IEnvironment, Variables} from 'relay-runtime';
22
21
 
23
22
  import usePaginationFragment from '../usePaginationFragment';
24
23
  import {
25
24
  fragmentData,
26
- fragmentInput,
27
25
  keyAnotherNonNullable,
28
26
  keyAnotherNullable,
29
27
  keyNonNullable,
30
28
  keyNullable,
29
+ refetchableFragmentInput,
31
30
  } from './utils';
32
31
 
33
32
  type ExpectedReturnType<
34
- TQuery: OperationType,
35
- TQueryVariables,
33
+ TRefetchVariables: Variables,
34
+ TLoadMoreVariables: Variables,
36
35
  TFragmentData,
37
36
  > = {
38
37
  data: TFragmentData,
39
- loadNext: LoadMoreFn<TQuery>,
40
- loadPrevious: LoadMoreFn<TQuery>,
38
+ loadNext: LoadMoreFn<TLoadMoreVariables>,
39
+ loadPrevious: LoadMoreFn<TLoadMoreVariables>,
41
40
  hasNext: boolean,
42
41
  hasPrevious: boolean,
43
42
  isLoadingNext: boolean,
44
43
  isLoadingPrevious: boolean,
45
- refetch: FetchFn<TQueryVariables>,
44
+ refetch: FetchFn<TRefetchVariables>,
46
45
  };
47
46
 
48
47
  /* eslint-disable react-hooks/rules-of-hooks */
49
48
 
50
49
  // Nullability of returned data type is correct
51
- (usePaginationFragment<QueryOperation, _>(
52
- fragmentInput,
50
+ // $FlowFixMe[prop-missing]
51
+ // $FlowFixMe[incompatible-cast]
52
+ (usePaginationFragment(
53
+ refetchableFragmentInput,
53
54
  keyNonNullable,
54
- ): ExpectedReturnType<QueryOperation, QueryVariablesSubset, NonNullableData>);
55
+ ): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
55
56
 
56
- (usePaginationFragment<QueryOperation, _>(
57
- fragmentInput,
57
+ (usePaginationFragment(
58
+ refetchableFragmentInput,
58
59
  keyNullable,
59
- ): ExpectedReturnType<QueryOperation, QueryVariables, NullableData>);
60
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
60
61
 
61
62
  // $FlowExpectedError: can't cast nullable to non-nullable
62
- (usePaginationFragment<QueryOperation, _>(
63
- fragmentInput,
63
+ (usePaginationFragment(
64
+ refetchableFragmentInput,
64
65
  keyNullable,
65
- ): ExpectedReturnType<QueryOperation, QueryVariables, NonNullableData>);
66
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
66
67
 
67
68
  // $FlowExpectedError: actual type of returned data is correct
68
- (usePaginationFragment<QueryOperation, _>(
69
- fragmentInput,
69
+ (usePaginationFragment(
70
+ refetchableFragmentInput,
71
+ // $FlowFixMe[incompatible-call]
70
72
  keyAnotherNonNullable,
71
- ): ExpectedReturnType<QueryOperation, QueryVariablesSubset, NonNullableData>);
73
+ ): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
72
74
  // $FlowExpectedError
73
- (usePaginationFragment<QueryOperation, _>(
74
- fragmentInput,
75
+ (usePaginationFragment(
76
+ refetchableFragmentInput,
77
+ // $FlowFixMe[incompatible-call]
75
78
  keyAnotherNullable,
76
- ): ExpectedReturnType<QueryOperation, QueryVariables, NullableData>);
79
+ ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
77
80
 
78
81
  // $FlowExpectedError: Key should not be a user provided object
79
- usePaginationFragment<QueryOperation, _>(fragmentInput, {abc: 123});
82
+ usePaginationFragment(refetchableFragmentInput, {abc: 123});
80
83
 
81
84
  // $FlowExpectedError: Key should not be an empty object
82
- usePaginationFragment<QueryOperation, _>(fragmentInput, {});
85
+ usePaginationFragment(refetchableFragmentInput, {});
83
86
 
84
87
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
85
- usePaginationFragment<QueryOperation, _>(fragmentInput, fragmentData);
88
+ usePaginationFragment(refetchableFragmentInput, fragmentData);
86
89
 
87
90
  // Refetch function options:
88
91
  declare var variables: QueryVariables;
89
92
  declare var environment: IEnvironment;
90
93
 
91
- const {refetch} = usePaginationFragment<QueryOperation, _>(
92
- fragmentInput,
94
+ const {refetch} = usePaginationFragment(
95
+ refetchableFragmentInput,
93
96
  keyNonNullable,
94
97
  );
95
98
  // $FlowExpectedError: internal option
@@ -106,17 +109,20 @@ refetch(variables, {
106
109
  declare var extraVariables: {nickname: string};
107
110
  declare var invalidVariables: {foo: string};
108
111
 
109
- const {loadNext} = usePaginationFragment<QueryOperation, _>(
110
- fragmentInput,
112
+ const {loadNext} = usePaginationFragment(
113
+ refetchableFragmentInput,
111
114
  keyNonNullable,
112
115
  );
113
116
  // Accepts extraVariables
114
117
  loadNext(10, {
118
+ // $FlowFixMe[prop-missing]
119
+ // $FlowFixMe[incompatible-call]
115
120
  UNSTABLE_extraVariables: extraVariables,
116
121
  });
117
122
 
118
- // $FlowExpectedError: doesn't accept variables not available in the Flow type
123
+ // $FlowFixMe[prop-missing]
119
124
  loadNext(10, {
125
+ // $FlowExpectedError: doesn't accept variables not available in the Flow type
120
126
  UNSTABLE_extraVariables: invalidVariables,
121
127
  });
122
128
 
@@ -4,16 +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
12
  import type {
13
13
  FetchFn,
14
14
  NonNullableData,
15
15
  NullableData,
16
- QueryOperation,
17
16
  QueryVariables,
18
17
  QueryVariablesSubset,
19
18
  } from './utils';
@@ -22,64 +21,67 @@ import type {IEnvironment} from 'relay-runtime';
22
21
  import useRefetchableFragment from '../useRefetchableFragment';
23
22
  import {
24
23
  fragmentData,
25
- fragmentInput,
26
24
  keyAnotherNonNullable,
27
25
  keyAnotherNullable,
28
26
  keyNonNullable,
29
27
  keyNullable,
28
+ refetchableFragmentInput,
30
29
  } from './utils';
31
30
 
32
31
  /* eslint-disable react-hooks/rules-of-hooks */
33
32
 
34
33
  // Nullability of returned data type is correct
35
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyNonNullable): [
34
+ // $FlowFixMe[prop-missing]
35
+ // $FlowFixMe[incompatible-cast]
36
+ (useRefetchableFragment(refetchableFragmentInput, keyNonNullable): [
36
37
  NonNullableData,
37
38
  FetchFn<QueryVariablesSubset>,
38
39
  ]);
39
40
 
40
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyNullable): [
41
+ (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
41
42
  NullableData,
42
43
  FetchFn<QueryVariables>,
43
44
  ]);
44
45
 
45
46
  // $FlowExpectedError: can't cast nullable to non-nullable
46
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyNullable): [
47
+ (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
47
48
  NonNullableData,
48
49
  FetchFn<QueryVariables>,
49
50
  ]);
50
51
 
51
52
  // $FlowExpectedError: refetch requires exact type if key is nullable
52
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyNullable): [
53
+ (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
53
54
  NullableData,
54
55
  FetchFn<QueryVariablesSubset>,
55
56
  ]);
56
57
 
57
58
  // $FlowExpectedError: actual type of returned data is correct
58
- (useRefetchableFragment<QueryOperation, _>(
59
- fragmentInput,
60
- keyAnotherNonNullable,
61
- ): [NonNullableData, FetchFn<QueryVariablesSubset>]);
62
- // $FlowExpectedError
63
- (useRefetchableFragment<QueryOperation, _>(fragmentInput, keyAnotherNullable): [
59
+ (useRefetchableFragment(refetchableFragmentInput, keyAnotherNonNullable): [
60
+ NonNullableData,
61
+ FetchFn<QueryVariablesSubset>,
62
+ ]);
63
+
64
+ // $FlowExpectedError - incompatible key types
65
+ (useRefetchableFragment(refetchableFragmentInput, keyAnotherNullable): [
64
66
  NullableData,
65
67
  FetchFn<QueryVariables>,
66
68
  ]);
67
69
 
68
70
  // $FlowExpectedError: Key should not be a user provided object
69
- useRefetchableFragment<QueryOperation, _>(fragmentInput, {abc: 123});
71
+ useRefetchableFragment(refetchableFragmentInput, {abc: 123});
70
72
 
71
73
  // $FlowExpectedError: Key should not be an empty object
72
- useRefetchableFragment<QueryOperation, _>(fragmentInput, {});
74
+ useRefetchableFragment(refetchableFragmentInput, {});
73
75
 
74
76
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
75
- useRefetchableFragment<QueryOperation, _>(fragmentInput, fragmentData);
77
+ useRefetchableFragment(refetchableFragmentInput, fragmentData);
76
78
 
77
79
  // Refetch function options:
78
80
  declare var variables: QueryVariables;
79
81
  declare var environment: IEnvironment;
80
82
 
81
- const [_, refetch] = useRefetchableFragment<QueryOperation, _>(
82
- fragmentInput,
83
+ const [, refetch] = useRefetchableFragment(
84
+ refetchableFragmentInput,
83
85
  keyNonNullable,
84
86
  );
85
87
  // $FlowExpectedError: internal option
@@ -4,20 +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
12
  'use strict';
13
13
 
14
- import type {Disposable, Fragment, FragmentType} from 'relay-runtime';
14
+ import type {
15
+ Disposable,
16
+ Fragment,
17
+ FragmentType,
18
+ RefetchableFragment,
19
+ } from 'relay-runtime';
15
20
 
16
21
  declare export var fragmentInput: Fragment<
17
22
  Example_user$fragmentType,
18
23
  Example_user$data,
19
24
  >;
20
25
 
26
+ declare export var refetchableFragmentInput: RefetchableFragment<
27
+ Example_user$fragmentType,
28
+ Example_user$data,
29
+ QueryVariables,
30
+ >;
31
+
21
32
  declare export opaque type Example_user$fragmentType: FragmentType;
22
33
  export type Example_user$data = NonNullableData;
23
34
  export type Example_user$key = {
@@ -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';
@@ -46,8 +46,10 @@ function loadEntryPoint<
46
46
  }
47
47
  const preloadProps = entryPoint.getPreloadProps(entryPointParams);
48
48
  const {queries, entryPoints, extraProps} = preloadProps;
49
- const preloadedQueries: $Shape<TPreloadedQueries> = {};
50
- const preloadedEntryPoints: $Shape<TPreloadedEntryPoints> = {};
49
+ // $FlowFixMe[incompatible-type]
50
+ const preloadedQueries: Partial<TPreloadedQueries> = {};
51
+ // $FlowFixMe[incompatible-type]
52
+ const preloadedEntryPoints: Partial<TPreloadedEntryPoints> = {};
51
53
  if (queries != null) {
52
54
  const queriesPropNames = Object.keys(queries);
53
55
  queriesPropNames.forEach(queryPropName => {
@@ -58,6 +60,7 @@ function loadEntryPoint<
58
60
  environmentProviderOptions,
59
61
  );
60
62
 
63
+ // $FlowFixMe[underconstrained-implicit-instantiation]
61
64
  preloadedQueries[queryPropName] = loadQuery(
62
65
  environment,
63
66
  parameters,
@@ -81,11 +84,15 @@ function loadEntryPoint<
81
84
  }
82
85
  const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
83
86
  entryPointDescription;
84
- preloadedEntryPoints[entryPointPropName] = loadEntryPoint(
85
- environmentProvider,
86
- nestedEntryPoint,
87
- nestedParams,
88
- );
87
+ preloadedEntryPoints[entryPointPropName] = loadEntryPoint<
88
+ _,
89
+ {...},
90
+ {...},
91
+ {...},
92
+ mixed,
93
+ EntryPointComponent<{...}, {...}, {...}, mixed>,
94
+ _,
95
+ >(environmentProvider, nestedEntryPoint, nestedParams);
89
96
  });
90
97
  }
91
98
 
@@ -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,
@@ -23,6 +24,7 @@ import type {
23
24
  IEnvironment,
24
25
  OperationDescriptor,
25
26
  OperationType,
27
+ Query,
26
28
  RequestIdentifier,
27
29
  RequestParameters,
28
30
  } from 'relay-runtime';
@@ -30,11 +32,11 @@ import type {
30
32
  const invariant = require('invariant');
31
33
  const React = require('react');
32
34
  const {
35
+ __internal: {fetchQueryDeduped},
33
36
  Observable,
34
37
  PreloadableQueryRegistry,
35
38
  RelayFeatureFlags,
36
39
  ReplaySubject,
37
- __internal: {fetchQueryDeduped},
38
40
  createOperationDescriptor,
39
41
  getRequest,
40
42
  getRequestIdentifier,
@@ -55,9 +57,31 @@ function useTrackLoadQueryInRender() {
55
57
  }
56
58
  }
57
59
 
58
- function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
60
+ type QueryType<T> = T extends Query<infer V, infer D, infer RR>
61
+ ? {
62
+ variables: V,
63
+ response: D,
64
+ rawResponse?: $NonMaybeType<RR>,
65
+ }
66
+ : $Call<<T>(PreloadableConcreteRequest<T>) => T, T>;
67
+
68
+ declare function loadQuery<
69
+ T,
70
+ TEnvironmentProviderOptions = EnvironmentProviderOptions,
71
+ >(
72
+ environment: IEnvironment,
73
+ preloadableRequest: T,
74
+ variables: QueryType<T>['variables'],
75
+ options?: ?LoadQueryOptions,
76
+ environmentProviderOptions?: ?TEnvironmentProviderOptions,
77
+ ): PreloadedQueryInner<QueryType<T>, TEnvironmentProviderOptions>;
78
+
79
+ function loadQuery<
80
+ TQuery: OperationType,
81
+ TEnvironmentProviderOptions = EnvironmentProviderOptions,
82
+ >(
59
83
  environment: IEnvironment,
60
- preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
84
+ preloadableRequest: PreloadableConcreteRequest<TQuery>,
61
85
  variables: TQuery['variables'],
62
86
  options?: ?LoadQueryOptions,
63
87
  environmentProviderOptions?: ?TEnvironmentProviderOptions,
@@ -115,8 +139,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
115
139
  // allows us to capture the events that occur during the eager execution
116
140
  // of the operation, and then replay them to the Observable we
117
141
  // ultimately return.
118
- const executionSubject = new ReplaySubject();
119
- const returnedObservable = Observable.create(sink =>
142
+ const executionSubject = new ReplaySubject<GraphQLResponse>();
143
+ const returnedObservable = Observable.create<GraphQLResponse>(sink =>
120
144
  executionSubject.subscribe(sink),
121
145
  );
122
146
 
@@ -139,7 +163,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
139
163
  didMakeNetworkRequest = true;
140
164
 
141
165
  let observable;
142
- const subject = new ReplaySubject();
166
+ const subject = new ReplaySubject<GraphQLResponse>();
143
167
  if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
144
168
  // Here, we are calling fetchQueryDeduped at the network layer level,
145
169
  // which ensures that only a single network request is active for a given
@@ -270,7 +294,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
270
294
  };
271
295
 
272
296
  let params;
273
- let cancelOnLoadCallback;
297
+ let cancelOnLoadCallback: () => void;
274
298
  let queryId;
275
299
  if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
276
300
  const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
@@ -4,9 +4,9 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @emails oncall+relay
8
7
  * @flow strict-local
9
8
  * @format
9
+ * @oncall relay
10
10
  */
11
11
 
12
12
  'use strict';
@@ -31,7 +31,6 @@ import type {
31
31
  const {
32
32
  Observable,
33
33
  PreloadableQueryRegistry,
34
- RelayFeatureFlags,
35
34
  ReplaySubject,
36
35
  createOperationDescriptor,
37
36
  getRequest,
@@ -45,8 +44,8 @@ const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
45
44
  const STORE_OR_NETWORK_DEFAULT: PreloadFetchPolicy = 'store-or-network';
46
45
 
47
46
  const pendingQueriesByEnvironment = WEAKMAP_SUPPORTED
48
- ? new WeakMap()
49
- : new Map();
47
+ ? new WeakMap<IEnvironment, Map<string, PendingQueryEntry>>()
48
+ : new Map<IEnvironment, Map<string, PendingQueryEntry>>();
50
49
 
51
50
  type PendingQueryEntry =
52
51
  | $ReadOnly<{
@@ -92,7 +91,7 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
92
91
  );
93
92
  const source =
94
93
  queryEntry.kind === 'network'
95
- ? Observable.create(sink => {
94
+ ? Observable.create<GraphQLResponse>(sink => {
96
95
  let subscription;
97
96
  if (pendingQueries.get(queryEntry.cacheKey) == null) {
98
97
  const newQueryEntry = preloadQueryDeduped(
@@ -205,7 +204,7 @@ function preloadQueryDeduped<TQuery: OperationType>(
205
204
  } else if (prevQueryEntry == null || prevQueryEntry.kind !== 'network') {
206
205
  // Should fetch but we're not already fetching: fetch!
207
206
  const source = network.execute(params, variables, networkCacheConfig, null);
208
- const subject = new ReplaySubject();
207
+ const subject = new ReplaySubject<GraphQLResponse>();
209
208
  nextQueryEntry = {
210
209
  cacheKey,
211
210
  fetchKey,