react-relay 20.1.1 → 21.0.1

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 (154) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayContext.js.flow +2 -2
  3. package/ReactRelayFragmentContainer.js.flow +8 -9
  4. package/ReactRelayLocalQueryRenderer.js.flow +11 -3
  5. package/ReactRelayLoggingContext.js.flow +3 -3
  6. package/ReactRelayPaginationContainer.js.flow +32 -25
  7. package/ReactRelayQueryFetcher.js.flow +1 -1
  8. package/ReactRelayQueryRenderer.js.flow +2 -2
  9. package/ReactRelayQueryRendererContext.js.flow +2 -2
  10. package/ReactRelayRefetchContainer.js.flow +17 -14
  11. package/ReactRelayTestMocker.js.flow +10 -10
  12. package/ReactRelayTypes.d.ts +377 -0
  13. package/ReactRelayTypes.js.flow +47 -43
  14. package/RelayContext.js.flow +3 -3
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +11 -11
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +5 -5
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +5 -5
  18. package/__flowtests__/RelayModern-flowtest.js.flow +32 -32
  19. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -1
  20. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -4
  21. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -4
  22. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +9 -10
  23. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +4 -5
  24. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +9 -10
  25. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +4 -5
  26. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
  27. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
  28. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -4
  29. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +5 -6
  30. package/buildReactRelayContainer.js.flow +5 -5
  31. package/getRootVariablesForFragments.js.flow +1 -1
  32. package/hooks.d.ts +89 -0
  33. package/hooks.js +1 -1
  34. package/hooks.js.flow +23 -8
  35. package/index.d.ts +9 -0
  36. package/index.js +1 -1
  37. package/index.js.flow +40 -14
  38. package/isRelayEnvironment.js.flow +1 -1
  39. package/jest-react/internalAct.js.flow +1 -1
  40. package/legacy.d.ts +143 -0
  41. package/legacy.js +1 -1
  42. package/legacy.js.flow +32 -13
  43. package/lib/ReactRelayFragmentContainer.js +1 -1
  44. package/lib/ReactRelayPaginationContainer.js +8 -8
  45. package/lib/ReactRelayRefetchContainer.js +8 -8
  46. package/lib/ReactRelayTestMocker.js +5 -5
  47. package/lib/hooks.js +18 -8
  48. package/lib/index.js +30 -14
  49. package/lib/legacy.js +26 -13
  50. package/lib/relay-hooks/legacy/useBlockingPaginationFragment.js +5 -5
  51. package/lib/relay-hooks/legacy/useRefetchableFragmentNode.js +34 -34
  52. package/lib/relay-hooks/loadEntryPoint.js +2 -2
  53. package/lib/relay-hooks/loadQuery.js +14 -14
  54. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -10
  55. package/lib/relay-hooks/readFragmentInternal.js +6 -6
  56. package/lib/relay-hooks/rsc/serverFetchQuery.js +20 -0
  57. package/lib/relay-hooks/rsc/serverPreloadQuery.js +31 -0
  58. package/lib/relay-hooks/rsc/serverReadFragment.js +15 -0
  59. package/lib/relay-hooks/rsc/useQueryFromServer.js +62 -0
  60. package/lib/relay-hooks/useFragmentInternal_CURRENT.js +49 -25
  61. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +81 -44
  62. package/lib/relay-hooks/useLazyLoadQueryNode.js +32 -19
  63. package/lib/relay-hooks/useMutation.js +6 -14
  64. package/lib/relay-hooks/useMutationAction_EXPERIMENTAL.js +26 -0
  65. package/lib/relay-hooks/usePreloadedQuery.js +52 -47
  66. package/lib/relay-hooks/useQueryLoader.js +2 -2
  67. package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +2 -2
  68. package/lib/relay-hooks/useRefetchableFragmentInternal.js +31 -31
  69. package/lib/rsc-client_EXPERIMENTAL.js +7 -0
  70. package/lib/rsc_EXPERIMENTAL.js +43 -0
  71. package/multi-actor/ActorChange.js.flow +1 -1
  72. package/package.json +3 -2
  73. package/relay-hooks/EntryPointContainer.react.d.ts +22 -0
  74. package/relay-hooks/EntryPointContainer.react.js.flow +6 -6
  75. package/relay-hooks/EntryPointTypes.flow.js.flow +106 -108
  76. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +23 -21
  77. package/relay-hooks/MatchContainer.d.ts +95 -0
  78. package/relay-hooks/MatchContainer.js.flow +17 -11
  79. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +3 -9
  80. package/relay-hooks/ProfilerContext.d.ts +18 -0
  81. package/relay-hooks/QueryResource.js.flow +9 -9
  82. package/relay-hooks/RelayEnvironmentProvider.d.ts +16 -0
  83. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  84. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -6
  85. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +50 -3
  86. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -9
  87. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -4
  88. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +5 -6
  89. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +27 -32
  90. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +25 -25
  91. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +26 -32
  92. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +23 -30
  93. package/relay-hooks/__flowtests__/utils.js.flow +17 -17
  94. package/relay-hooks/getConnectionState.js.flow +2 -2
  95. package/relay-hooks/legacy/FragmentResource.js.flow +13 -13
  96. package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +28 -25
  97. package/relay-hooks/legacy/useFragmentNode.js.flow +4 -4
  98. package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +79 -81
  99. package/relay-hooks/loadEntryPoint.d.ts +14 -0
  100. package/relay-hooks/loadEntryPoint.js.flow +15 -13
  101. package/relay-hooks/loadQuery.d.ts +20 -0
  102. package/relay-hooks/loadQuery.js.flow +19 -19
  103. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +16 -13
  104. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -7
  105. package/relay-hooks/readFragmentInternal.js.flow +11 -11
  106. package/relay-hooks/rsc/serverFetchQuery.js.flow +31 -0
  107. package/relay-hooks/rsc/serverPreloadQuery.js.flow +69 -0
  108. package/relay-hooks/rsc/serverReadFragment.js.flow +33 -0
  109. package/relay-hooks/rsc/useQueryFromServer.js.flow +135 -0
  110. package/relay-hooks/useClientQuery.d.ts +16 -0
  111. package/relay-hooks/useClientQuery.js.flow +2 -2
  112. package/relay-hooks/useEntryPointLoader.d.ts +21 -0
  113. package/relay-hooks/useEntryPointLoader.js.flow +11 -11
  114. package/relay-hooks/useFragment.d.ts +36 -0
  115. package/relay-hooks/useFragment.js.flow +8 -8
  116. package/relay-hooks/useFragmentInternal.js.flow +1 -1
  117. package/relay-hooks/useFragmentInternal_CURRENT.js.flow +54 -22
  118. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +95 -46
  119. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  120. package/relay-hooks/useIsParentQueryActive.js.flow +5 -1
  121. package/relay-hooks/useLazyLoadQuery.d.ts +19 -0
  122. package/relay-hooks/useLazyLoadQuery.js.flow +14 -7
  123. package/relay-hooks/useLazyLoadQueryNode.js.flow +67 -28
  124. package/relay-hooks/useLoadMoreFunction.d.ts +56 -0
  125. package/relay-hooks/useLoadMoreFunction.js.flow +7 -6
  126. package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +5 -5
  127. package/relay-hooks/useMemoVariables.js.flow +1 -1
  128. package/relay-hooks/useMutation.d.ts +36 -0
  129. package/relay-hooks/useMutation.js.flow +9 -17
  130. package/relay-hooks/useMutationAction_EXPERIMENTAL.js.flow +68 -0
  131. package/relay-hooks/usePaginationFragment.d.ts +33 -0
  132. package/relay-hooks/usePaginationFragment.js.flow +19 -11
  133. package/relay-hooks/usePrefetchableForwardPaginationFragment.js.flow +23 -18
  134. package/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js.flow +23 -18
  135. package/relay-hooks/usePreloadedQuery.d.ts +17 -0
  136. package/relay-hooks/usePreloadedQuery.js.flow +119 -85
  137. package/relay-hooks/useQueryLoader.d.ts +33 -0
  138. package/relay-hooks/useQueryLoader.js.flow +28 -24
  139. package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +10 -10
  140. package/relay-hooks/useRefetchableFragment.d.ts +23 -0
  141. package/relay-hooks/useRefetchableFragment.js.flow +20 -11
  142. package/relay-hooks/useRefetchableFragmentInternal.js.flow +77 -79
  143. package/relay-hooks/useRelayEnvironment.d.ts +10 -0
  144. package/relay-hooks/useRelayLoggingContext.js.flow +1 -1
  145. package/relay-hooks/useSubscribeToInvalidationState.d.ts +19 -0
  146. package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
  147. package/relay-hooks/useSubscription.d.ts +14 -0
  148. package/relay-hooks/useSubscription.js.flow +1 -1
  149. package/rsc-client_EXPERIMENTAL.d.ts +17 -0
  150. package/rsc-client_EXPERIMENTAL.js +10 -0
  151. package/rsc-client_EXPERIMENTAL.js.flow +23 -0
  152. package/rsc_EXPERIMENTAL.d.ts +48 -0
  153. package/rsc_EXPERIMENTAL.js +10 -0
  154. package/rsc_EXPERIMENTAL.js.flow +90 -0
@@ -34,20 +34,21 @@ export type PreloadFetchPolicy =
34
34
  | 'network-only';
35
35
 
36
36
  export type PreloadOptions = {
37
- +fetchKey?: string | number,
38
- +fetchPolicy?: ?PreloadFetchPolicy,
39
- +includeIf?: ?boolean,
40
- +prefetchExpiryInHours?: ?number,
41
- +networkCacheConfig?: ?CacheConfig,
37
+ readonly fetchKey?: string | number,
38
+ readonly fetchPolicy?: ?PreloadFetchPolicy,
39
+ readonly includeIf?: ?boolean,
40
+ readonly enableForOfflineCacheJob?: ?boolean,
41
+ readonly prefetchExpiryInHours?: ?number,
42
+ readonly networkCacheConfig?: ?CacheConfig,
42
43
  };
43
44
 
44
45
  export type LoadQueryOptions = {
45
- +fetchPolicy?: ?FetchPolicy,
46
- +networkCacheConfig?: ?CacheConfig,
47
- +__nameForWarning?: ?string,
46
+ readonly fetchPolicy?: ?FetchPolicy,
47
+ readonly networkCacheConfig?: ?CacheConfig,
48
+ readonly __nameForWarning?: ?string,
48
49
  };
49
50
 
50
- export type PreloadableConcreteRequest<+TQuery: OperationType> = {
51
+ export type PreloadableConcreteRequest<out TQuery extends OperationType> = {
51
52
  kind: 'PreloadableConcreteRequest',
52
53
  params: RequestParameters,
53
54
  // Note: the phantom type parameter here helps ensures that the
@@ -55,63 +56,63 @@ export type PreloadableConcreteRequest<+TQuery: OperationType> = {
55
56
  // We also need to add usage of this generic here,
56
57
  // becuase not using the generic in the definition makes it
57
58
  // unconstrained in the call to a function that accepts PreloadableConcreteRequest<T>
58
- +__phantom__?: ?TQuery,
59
+ readonly __phantom__?: ?TQuery,
59
60
  };
60
61
 
61
- export type EnvironmentProviderOptions = {+[string]: mixed, ...};
62
+ export type EnvironmentProviderOptions = {readonly [string]: unknown, ...};
62
63
 
63
64
  export type PreloadedQuery<
64
- +TQuery: OperationType,
65
+ out TQuery extends OperationType,
65
66
  TEnvironmentProviderOptions = EnvironmentProviderOptions,
66
67
  > =
67
68
  | PreloadedQueryInner_DEPRECATED<TQuery, TEnvironmentProviderOptions>
68
69
  | PreloadedQueryInner<TQuery, TEnvironmentProviderOptions>;
69
70
 
70
71
  export type PreloadedQueryInner_DEPRECATED<
71
- +TQuery: OperationType,
72
+ out TQuery extends OperationType,
72
73
  TEnvironmentProviderOptions = EnvironmentProviderOptions,
73
74
  > = {
74
- +kind: 'PreloadedQuery_DEPRECATED',
75
- +environment: IEnvironment,
76
- +environmentProviderOptions: ?TEnvironmentProviderOptions,
77
- +fetchKey: ?string | ?number,
78
- +fetchPolicy: FetchPolicy,
79
- +networkCacheConfig?: ?CacheConfig,
80
- +id: ?string,
81
- +name: string,
82
- +source: ?Observable<GraphQLResponse>,
83
- +variables: TQuery['variables'],
84
- +status: PreloadQueryStatus,
75
+ readonly kind: 'PreloadedQuery_DEPRECATED',
76
+ readonly environment: IEnvironment,
77
+ readonly environmentProviderOptions: ?TEnvironmentProviderOptions,
78
+ readonly fetchKey: ?string | ?number,
79
+ readonly fetchPolicy: FetchPolicy,
80
+ readonly networkCacheConfig?: ?CacheConfig,
81
+ readonly id: ?string,
82
+ readonly name: string,
83
+ readonly source: ?Observable<GraphQLResponse>,
84
+ readonly variables: TQuery['variables'],
85
+ readonly status: PreloadQueryStatus,
85
86
  };
86
87
 
87
88
  export type PreloadedQueryInner<
88
- +TQuery: OperationType,
89
+ out TQuery extends OperationType,
89
90
  TEnvironmentProviderOptions = EnvironmentProviderOptions,
90
91
  > = {
91
92
  // Releases query data and cancels network request if still in flight
92
- +dispose: () => void,
93
+ readonly dispose: () => void,
93
94
  // Releases query data
94
- +releaseQuery: () => void,
95
+ readonly releaseQuery: () => void,
95
96
  // Cancels network request if still in flight
96
- +cancelNetworkRequest: () => void,
97
- +environment: IEnvironment,
98
- +environmentProviderOptions: ?TEnvironmentProviderOptions,
99
- +fetchKey: string | number,
100
- +fetchPolicy: FetchPolicy,
101
- +id: ?string,
102
- +isDisposed: boolean,
103
- +networkError: ?Error,
104
- +name: string,
105
- +networkCacheConfig: ?CacheConfig,
106
- +source: ?Observable<GraphQLResponse>,
107
- +kind: 'PreloadedQuery',
108
- +variables: TQuery['variables'],
97
+ readonly cancelNetworkRequest: () => void,
98
+ readonly environment: IEnvironment,
99
+ readonly environmentProviderOptions: ?TEnvironmentProviderOptions,
100
+ readonly fetchKey: string | number,
101
+ readonly fetchPolicy: FetchPolicy,
102
+ readonly id: ?string,
103
+ readonly isDisposed: boolean,
104
+ readonly networkError: ?Error,
105
+ readonly name: string,
106
+ readonly networkCacheConfig: ?CacheConfig,
107
+ readonly source: ?Observable<GraphQLResponse>,
108
+ readonly kind: 'PreloadedQuery',
109
+ readonly variables: TQuery['variables'],
109
110
  };
110
111
 
111
112
  export type PreloadQueryStatus = {
112
- +cacheConfig: ?CacheConfig,
113
- +source: 'cache' | 'network',
114
- +fetchTime: ?number,
113
+ readonly cacheConfig: ?CacheConfig,
114
+ readonly source: 'cache' | 'network',
115
+ readonly fetchTime: ?number,
115
116
  };
116
117
 
117
118
  /**
@@ -125,40 +126,21 @@ Every .entrypoint file it's an object that must have two required fields:
125
126
  TEntryPointParams - object that contains all necessary information to execute
126
127
  the preloaders (routeParams, query variables)
127
128
 
128
- TPreloadedQueries - queries, defined in the root components
129
-
130
- TPreloadedEntryPoints - nested entry points, defined in the root components
131
-
132
- TRuntimeProps - the type of additional props that you may pass to the
133
- component (like `onClick` handler, etc) during runtime. Values for them
134
- defined during component runtime
135
-
136
- TExtraProps - a bag of extra props that you may define in `entrypoint` file
137
- and they will be passed to the EntryPointComponent as `extraProps`
129
+ TEntryPointComponent - the root components
138
130
  */
139
- export type InternalEntryPointRepresentation<
140
- TEntryPointParams,
141
- TPreloadedQueries,
142
- TPreloadedEntryPoints = {...},
143
- TRuntimeProps = {...},
144
- TExtraProps = null,
145
- > = $ReadOnly<{
131
+ export type EntryPoint<
132
+ in TEntryPointParams,
133
+ // $FlowExpectedError[unclear-type] accepts any root component
134
+ out TEntryPointComponent extends EntryPointComponent<any, any, any, any, any>,
135
+ > = Readonly<{
146
136
  getPreloadProps: (
147
137
  entryPointParams: TEntryPointParams,
148
138
  ) => PreloadProps<
149
- TEntryPointParams,
150
- TPreloadedQueries,
151
- TPreloadedEntryPoints,
152
- TExtraProps,
153
- >,
154
- root: JSResourceReference<
155
- EntryPointComponent<
156
- TPreloadedQueries,
157
- TPreloadedEntryPoints,
158
- TRuntimeProps,
159
- TExtraProps,
160
- >,
139
+ ElementConfig<TEntryPointComponent>['queries'],
140
+ ElementConfig<TEntryPointComponent>['entryPoints'],
141
+ ElementConfig<TEntryPointComponent>['extraProps'],
161
142
  >,
143
+ root: JSResourceReference<TEntryPointComponent>,
162
144
  }>;
163
145
 
164
146
  // The shape of the props of the entry point `root` component
@@ -167,20 +149,36 @@ export type EntryPointProps<
167
149
  TPreloadedEntryPoints = {},
168
150
  TRuntimeProps = {},
169
151
  TExtraProps = null,
170
- > = $ReadOnly<{
152
+ > = Readonly<{
171
153
  entryPoints: TPreloadedEntryPoints,
172
154
  extraProps: TExtraProps | null,
173
155
  props: TRuntimeProps,
174
156
  queries: TPreloadedQueries,
175
157
  }>;
176
158
 
177
- // Type of the entry point `root` component
159
+ /**
160
+ Type of the entry point `root` component
161
+
162
+ TEntryPointParams - object that contains all necessary information to execute
163
+ the preloaders (routeParams, query variables)
164
+
165
+ TPreloadedQueries - queries, defined in the root components
166
+
167
+ TPreloadedEntryPoints - nested entry points, defined in the root components
168
+
169
+ TRuntimeProps - the type of additional props that you may pass to the
170
+ component (like `onClick` handler, etc) during runtime. Values for them
171
+ defined during component runtime
172
+
173
+ TExtraProps - a bag of extra props that you may define in `entrypoint` file
174
+ and they will be passed to the EntryPointComponent as `extraProps`
175
+ */
178
176
  export type EntryPointComponent<
179
177
  TPreloadedQueries,
180
178
  TPreloadedEntryPoints = {},
181
179
  TRuntimeProps = {},
182
180
  TExtraProps = null,
183
- TRenders: React.Node = React.Node,
181
+ out TRenders extends React.Node = React.Node,
184
182
  > = component(
185
183
  ...EntryPointProps<
186
184
  TPreloadedQueries,
@@ -192,13 +190,12 @@ export type EntryPointComponent<
192
190
 
193
191
  // Return type of the `getPreloadProps(...)` of the entry point
194
192
  export type PreloadProps<
195
- +TPreloadParams,
196
193
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
197
- TPreloadedQueries: {+[string]: PreloadedQuery<any>},
198
- TPreloadedEntryPoints: {...},
194
+ TPreloadedQueries extends {readonly [string]: ?PreloadedQuery<any>},
195
+ TPreloadedEntryPoints extends {...},
199
196
  TExtraProps = null,
200
197
  TEnvironmentProviderOptions = EnvironmentProviderOptions,
201
- > = $ReadOnly<{
198
+ > = Readonly<{
202
199
  entryPoints?: {
203
200
  +[K in keyof TPreloadedEntryPoints]?: ?ThinNestedEntryPointParams,
204
201
  },
@@ -207,7 +204,7 @@ export type PreloadProps<
207
204
  }>;
208
205
 
209
206
  // Return type of `loadEntryPoint(...)`
210
- export type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{
207
+ export type PreloadedEntryPoint<TEntryPointComponent> = Readonly<{
211
208
  dispose: () => void,
212
209
  entryPoints: ElementConfig<TEntryPointComponent>['entryPoints'],
213
210
  extraProps: ElementConfig<TEntryPointComponent>['extraProps'],
@@ -218,27 +215,24 @@ export type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{
218
215
  }>;
219
216
 
220
217
  export type EntryPointElementConfig<
221
- // $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
222
- +TEntryPoint: InternalEntryPointRepresentation<any, any, any, any, any>,
223
- > =
224
- TEntryPoint extends InternalEntryPointRepresentation<
225
- // $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
226
- any,
218
+ out TEntryPoint extends EntryPoint<
227
219
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
228
220
  any,
229
221
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
230
222
  any,
231
- infer Props,
232
- // $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
233
- any,
223
+ >,
224
+ > =
225
+ TEntryPoint extends EntryPoint<
226
+ infer _EntryPointParams,
227
+ infer EntryPointComponent,
234
228
  >
235
- ? Props
229
+ ? ElementConfig<EntryPointComponent>['props']
236
230
  : empty;
237
231
 
238
232
  export type ThinQueryParams<
239
- +TQuery: OperationType,
233
+ out TQuery extends OperationType,
240
234
  TEnvironmentProviderOptions,
241
- > = $ReadOnly<{
235
+ > = Readonly<{
242
236
  environmentProviderOptions?: ?TEnvironmentProviderOptions,
243
237
  options?: ?PreloadOptions,
244
238
  parameters: PreloadableConcreteRequest<TQuery>,
@@ -260,21 +254,29 @@ export type ExtractQueryTypeHelper<TEnvironmentProviderOptions> = <TQuery>(
260
254
  // We need to match both cases without using distributive conditional types,
261
255
  // because PreloadedQuery's TQuery parameter is almost phantom, and breaking
262
256
  // up the union type would cause us to lose track of TQuery.
263
- type ExtractThinQueryParams<T, TEnvironmentProviderOptions> = [+t: T] extends [
264
- // $FlowFixMe[incompatible-type-arg]
265
- +t: PreloadedQuery<infer TQuery>,
257
+ type ExtractThinQueryParams<T, TEnvironmentProviderOptions> = [
258
+ readonly t: T,
259
+ ] extends [
260
+ // $FlowFixMe[incompatible-type]
261
+ readonly t: PreloadedQuery<infer TQuery extends OperationType>,
266
262
  ]
267
263
  ? ThinQueryParams<TQuery, TEnvironmentProviderOptions>
268
- : [+t: T] extends [
269
- +t: PreloadedQuery<infer TQuery extends OperationType> | void,
264
+ : [readonly t: T] extends [
265
+ readonly t: PreloadedQuery<infer TQuery extends OperationType> | void,
270
266
  ]
271
267
  ? ThinQueryParams<TQuery, TEnvironmentProviderOptions> | void
272
- : empty;
268
+ : [readonly t: T] extends [
269
+ readonly t: PreloadedQuery<
270
+ infer TQuery extends OperationType,
271
+ > | null | void,
272
+ ]
273
+ ? ThinQueryParams<TQuery, TEnvironmentProviderOptions> | null | void
274
+ : empty;
273
275
 
274
276
  export type ExtractQueryTypes<
275
277
  TEnvironmentProviderOptions,
276
278
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
277
- PreloadedQueries: {+[string]: PreloadedQuery<any>} | void,
279
+ PreloadedQueries extends {readonly [string]: ?PreloadedQuery<any>} | void,
278
280
  > = {
279
281
  [K in keyof PreloadedQueries]: ExtractThinQueryParams<
280
282
  PreloadedQueries[K],
@@ -282,17 +284,13 @@ export type ExtractQueryTypes<
282
284
  >,
283
285
  };
284
286
 
285
- export type EntryPoint<TEntryPointParams, +TEntryPointComponent> =
286
- InternalEntryPointRepresentation<
287
- TEntryPointParams,
288
- ElementConfig<TEntryPointComponent>['queries'],
289
- ElementConfig<TEntryPointComponent>['entryPoints'],
290
- ElementConfig<TEntryPointComponent>['props'],
291
- ElementConfig<TEntryPointComponent>['extraProps'],
292
- >;
287
+ // $FlowFixMe[unclear-type]: we don't care about the props
288
+ export type RootComponentRenders<out C extends component(...any)> =
289
+ // $FlowFixMe[unclear-type]: we don't care about the props
290
+ C extends component(...any) renders infer R extends React.Node ? R : empty;
293
291
 
294
292
  export type PreloadParamsOf<T> = Parameters<T['getPreloadProps']>[0];
295
293
 
296
- export type IEnvironmentProvider<TOptions> = $ReadOnly<{
294
+ export type IEnvironmentProvider<TOptions> = Readonly<{
297
295
  getEnvironment: (options: ?TOptions) => IEnvironment,
298
296
  }>;
@@ -26,7 +26,7 @@ const React = require('react');
26
26
  const {useContext, useEffect, useMemo} = require('react');
27
27
  const {stableCopy} = require('relay-runtime');
28
28
 
29
- type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{
29
+ type PreloadedEntryPoint<TEntryPointComponent> = Readonly<{
30
30
  entryPoints: React.ElementConfig<TEntryPointComponent>['entryPoints'],
31
31
  extraProps: React.ElementConfig<TEntryPointComponent>['extraProps'],
32
32
  getComponent: () => TEntryPointComponent,
@@ -40,8 +40,8 @@ type EntryPointContainerProps<
40
40
  TPreloadedEntryPoints,
41
41
  TRuntimeProps,
42
42
  TExtraProps,
43
- > = $ReadOnly<
44
- $ReadOnly<{
43
+ > = Readonly<
44
+ Readonly<{
45
45
  entryPoint: EntryPoint<
46
46
  TEntryPointParams,
47
47
  EntryPointComponent<
@@ -57,24 +57,24 @@ type EntryPointContainerProps<
57
57
  }>,
58
58
  >;
59
59
 
60
- function stableStringify(value: mixed): string {
60
+ function stableStringify(value: unknown): string {
61
61
  return JSON.stringify(stableCopy(value)) ?? 'null';
62
62
  }
63
63
 
64
64
  function prepareEntryPoint<
65
- TEntryPointParams: {...},
65
+ TEntryPointParams extends {...},
66
66
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
67
- TPreloadedQueries: {+[string]: PreloadedQuery<any>},
68
- TPreloadedEntryPoints: {...},
69
- TRuntimeProps: {...},
67
+ TPreloadedQueries extends {readonly [string]: PreloadedQuery<any>},
68
+ TPreloadedEntryPoints extends {...},
69
+ TRuntimeProps extends {...},
70
70
  TExtraProps,
71
- TEntryPointComponent: EntryPointComponent<
71
+ TEntryPointComponent extends EntryPointComponent<
72
72
  TPreloadedQueries,
73
73
  TPreloadedEntryPoints,
74
74
  TRuntimeProps,
75
75
  TExtraProps,
76
76
  >,
77
- TEntryPoint: EntryPoint<TEntryPointParams, TEntryPointComponent>,
77
+ TEntryPoint extends EntryPoint<TEntryPointParams, TEntryPointComponent>,
78
78
  >(
79
79
  environmentProvider: IEnvironmentProvider<EnvironmentProviderOptions>,
80
80
  entryPoint: TEntryPoint,
@@ -104,7 +104,7 @@ function prepareEntryPoint<
104
104
  // $FlowFixMe[incompatible-type]
105
105
  preloadedQueries[queryPropName] = preloadQuery_DEPRECATED<
106
106
  OperationType,
107
- mixed,
107
+ unknown,
108
108
  >(
109
109
  environment,
110
110
  parameters,
@@ -129,14 +129,15 @@ function prepareEntryPoint<
129
129
  {},
130
130
  {...},
131
131
  {...},
132
- mixed,
133
- EntryPointComponent<{}, {...}, {...}, mixed>,
132
+ unknown,
133
+ EntryPointComponent<{}, {...}, {...}, unknown>,
134
134
  _,
135
135
  >(environmentProvider, nestedEntryPoint, nestedParams);
136
136
  });
137
137
  }
138
138
  return {
139
- entryPoints: (preloadedEntryPoints: TPreloadedEntryPoints),
139
+ // $FlowFixMe[incompatible-type]
140
+ entryPoints: preloadedEntryPoints as TPreloadedEntryPoints,
140
141
  extraProps: extraProps ?? null,
141
142
  getComponent: () => {
142
143
  const component = entryPoint.root.getModuleIfRequired();
@@ -144,20 +145,21 @@ function prepareEntryPoint<
144
145
  loadingPromise = loadingPromise ?? entryPoint.root.load();
145
146
  throw loadingPromise;
146
147
  }
147
- // $FlowFixMe[incompatible-cast] - trust me Flow, its entryPoint component
148
- return (component: TEntryPointComponent);
148
+ // $FlowFixMe[incompatible-type] - trust me Flow, its entryPoint component
149
+ return component as TEntryPointComponent;
149
150
  },
150
- queries: (preloadedQueries: TPreloadedQueries),
151
+ // $FlowFixMe[incompatible-type]
152
+ queries: preloadedQueries as TPreloadedQueries,
151
153
  rootModuleID: entryPoint.root.getModuleId(),
152
154
  };
153
155
  }
154
156
 
155
157
  function LazyLoadEntryPointContainer_DEPRECATED<
156
- TEntryPointParams: {...},
158
+ TEntryPointParams extends {...},
157
159
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
158
- TPreloadedQueries: {+[string]: PreloadedQuery<any>},
159
- TPreloadedEntryPoints: {...},
160
- TRuntimeProps: {...},
160
+ TPreloadedQueries extends {readonly [string]: PreloadedQuery<any>},
161
+ TPreloadedEntryPoints extends {...},
162
+ TRuntimeProps extends {...},
161
163
  TExtraProps,
162
164
  >({
163
165
  entryPoint,
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {ComponentType, ElementType, ReactNode} from 'react';
9
+
10
+ /**
11
+ * Renders the results of a data-driven dependency fetched with the `@match`
12
+ * directive. The `@match` directive can be used to specify a mapping of
13
+ * result types to the containers used to render those types. The result
14
+ * value is an opaque object that described which component was selected
15
+ * and a reference to its data. Use <MatchContainer/> to render these
16
+ * values.
17
+ *
18
+ * ## Example
19
+ *
20
+ * For example, consider a piece of media content that might be text or
21
+ * an image, where for clients that don't support images the application
22
+ * should fall back to rendering the image caption as text. @match can be
23
+ * used to dynamically select whether to render a given media item as
24
+ * an image or text (on the server) and then fetch the corresponding
25
+ * React component and its data dependencies (information about the
26
+ * image or about the text).
27
+ *
28
+ * ```
29
+ * // Media.react.js
30
+ *
31
+ * // Define a React component that uses <MatchContainer /> to render the
32
+ * // results of a @module selection
33
+ * function Media(props) {
34
+ * const {media, ...restProps} = props;
35
+ *
36
+ * const loader = moduleReference => {
37
+ * // given the data returned by your server for the @module directive,
38
+ * // return the React component (or throw a Suspense promise if
39
+ * // it is loading asynchronously).
40
+ * todo_returnModuleOrThrowPromise(moduleReference);
41
+ * };
42
+ * return <MatchContainer
43
+ * loader={loader}
44
+ * match={media.mediaAttachment}
45
+ * props={restProps}
46
+ * />;
47
+ * }
48
+ *
49
+ * module.exports = createSuspenseFragmentContainer(
50
+ * Media,
51
+ * {
52
+ * media: graphql`
53
+ * fragment Media_media on Media {
54
+ * # ...
55
+ * mediaAttachment @match {
56
+ * ...ImageContainer_image @module(name: "ImageContainer.react")
57
+ * ...TextContainer_text @module(name: "TextContainer.react")
58
+ * }
59
+ * }
60
+ * `
61
+ * },
62
+ * );
63
+ * ```
64
+ *
65
+ * ## API
66
+ *
67
+ * MatchContainer accepts the following props:
68
+ * - `match`: The results (an opaque object) of a `@match` field.
69
+ * - `props`: Props that should be passed through to the dynamically
70
+ * selected component. Note that any of the components listed in
71
+ * `@module()` could be selected, so all components should accept
72
+ * the value passed here.
73
+ * - `loader`: A function to load a module given a reference (whatever
74
+ * your server returns for the `js(moduleName: String)` field).
75
+ */
76
+
77
+ type TypenameOnlyPointer = Readonly<{ __typename: string }>;
78
+ export type MatchPointer = Readonly<{
79
+ __fragmentPropName?: string | null | undefined;
80
+ __module_component?: unknown | undefined;
81
+ ' $fragmentSpreads': unknown;
82
+ }>;
83
+
84
+ export type MatchContainerProps<TProps = Record<string, unknown>, TFallback = ReactNode> = Readonly<{
85
+ fallback?: TFallback | null | undefined;
86
+ loader: (module: unknown) => ComponentType<TProps>;
87
+ match?: MatchPointer | TypenameOnlyPointer | null | undefined;
88
+ props?: TProps | undefined;
89
+ }>;
90
+
91
+ export function MatchContainer<TProps = Record<string, unknown>, TFallback = ReactNode>(
92
+ props: MatchContainerProps<TProps, TFallback>,
93
+ ): ElementType<TProps> | TFallback | null;
94
+
95
+ export {};
@@ -85,22 +85,28 @@ const {useMemo} = React;
85
85
 
86
86
  // Note: this type is intentionally non-exact, it is expected that the
87
87
  // object may contain sibling fields.
88
- type TypenameOnlyPointer = {+__typename: string};
88
+ type TypenameOnlyPointer = {readonly __typename: string};
89
89
  export type MatchPointer = {
90
- +__fragmentPropName?: ?string,
91
- +__module_component?: mixed,
92
- +$fragmentSpreads: mixed,
90
+ readonly __fragmentPropName?: ?string,
91
+ readonly __module_component?: unknown,
92
+ readonly $fragmentSpreads: unknown,
93
93
  ...
94
94
  };
95
95
 
96
- export type MatchContainerProps<TProps: {...}, TFallback: React.Node> = {
97
- +fallback?: ?TFallback,
98
- +loader: (module: mixed) => component(...TProps),
99
- +match: ?MatchPointer | ?TypenameOnlyPointer,
100
- +props?: TProps,
96
+ export type MatchContainerProps<
97
+ TProps extends {...},
98
+ TFallback extends React.Node,
99
+ > = {
100
+ readonly fallback?: ?TFallback,
101
+ readonly loader: (module: unknown) => component(...TProps),
102
+ readonly match: ?MatchPointer | ?TypenameOnlyPointer,
103
+ readonly props?: TProps,
101
104
  };
102
105
 
103
- function MatchContainer<TProps: {...}, TFallback: React.Node | null>({
106
+ function MatchContainer<
107
+ TProps extends {...},
108
+ TFallback extends React.Node | null,
109
+ >({
104
110
  fallback,
105
111
  loader,
106
112
  match,
@@ -127,7 +133,7 @@ function MatchContainer<TProps: {...}, TFallback: React.Node | null>({
127
133
  __fragmentOwner,
128
134
  __fragmentPropName,
129
135
  __module_component,
130
- } = (match: $FlowFixMe) ?? {};
136
+ } = (match as $FlowFixMe) ?? {};
131
137
  if (
132
138
  (__fragmentOwner != null && typeof __fragmentOwner !== 'object') ||
133
139
  (__fragmentPropName != null && typeof __fragmentPropName !== 'string') ||
@@ -12,7 +12,7 @@
12
12
  'use strict';
13
13
 
14
14
  import type {
15
- InternalEntryPointRepresentation,
15
+ EntryPoint,
16
16
  ThinNestedEntryPointParams,
17
17
  } from './EntryPointTypes.flow';
18
18
 
@@ -25,14 +25,8 @@ import type {
25
25
  * to construct a `ThinNestedEntryPointParams` is by calling this function.
26
26
  */
27
27
  declare function NestedRelayEntryPoint<TEntryPointParams>(
28
- $ReadOnly<{
29
- entryPoint: InternalEntryPointRepresentation<
30
- TEntryPointParams,
31
- $FlowFixMe,
32
- $FlowFixMe,
33
- $FlowFixMe,
34
- $FlowFixMe,
35
- >,
28
+ params: Readonly<{
29
+ entryPoint: EntryPoint<TEntryPointParams, $FlowFixMe>,
36
30
  entryPointParams: TEntryPointParams,
37
31
  }>,
38
32
  ): ThinNestedEntryPointParams;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ // This contextual profiler can be used to wrap a react sub-tree. It will bind
9
+ // the RelayProfiler during the render phase of these components. Allows
10
+ // collecting metrics for a specific part of your application.
11
+
12
+ import { Context } from 'react';
13
+
14
+ export interface ProfilerContextType {
15
+ wrapPrepareQueryResource: <T>(cb: () => T) => T;
16
+ }
17
+
18
+ export const ProfilerContext: Context<ProfilerContextType>;