react-relay 21.0.0 → 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 (62) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayPaginationContainer.js.flow +2 -2
  3. package/ReactRelayTypes.d.ts +377 -0
  4. package/ReactRelayTypes.js.flow +34 -28
  5. package/__flowtests__/RelayModern-flowtest.js.flow +8 -5
  6. package/buildReactRelayContainer.js.flow +1 -1
  7. package/hooks.d.ts +89 -0
  8. package/hooks.js +1 -1
  9. package/index.d.ts +9 -0
  10. package/index.js +1 -1
  11. package/legacy.d.ts +143 -0
  12. package/legacy.js +1 -1
  13. package/package.json +2 -2
  14. package/relay-hooks/EntryPointContainer.react.d.ts +22 -0
  15. package/relay-hooks/EntryPointTypes.flow.js.flow +62 -58
  16. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +2 -2
  17. package/relay-hooks/MatchContainer.d.ts +95 -0
  18. package/relay-hooks/MatchContainer.js.flow +8 -8
  19. package/relay-hooks/ProfilerContext.d.ts +18 -0
  20. package/relay-hooks/QueryResource.js.flow +3 -3
  21. package/relay-hooks/RelayEnvironmentProvider.d.ts +16 -0
  22. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +3 -3
  23. package/relay-hooks/__flowtests__/utils.js.flow +13 -13
  24. package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +8 -4
  25. package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +4 -4
  26. package/relay-hooks/loadEntryPoint.d.ts +14 -0
  27. package/relay-hooks/loadEntryPoint.js.flow +1 -1
  28. package/relay-hooks/loadQuery.d.ts +20 -0
  29. package/relay-hooks/loadQuery.js.flow +1 -1
  30. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +1 -1
  31. package/relay-hooks/readFragmentInternal.js.flow +2 -2
  32. package/relay-hooks/rsc/serverPreloadQuery.js.flow +7 -7
  33. package/relay-hooks/rsc/serverReadFragment.js.flow +1 -1
  34. package/relay-hooks/useClientQuery.d.ts +16 -0
  35. package/relay-hooks/useEntryPointLoader.d.ts +21 -0
  36. package/relay-hooks/useEntryPointLoader.js.flow +1 -1
  37. package/relay-hooks/useFragment.d.ts +36 -0
  38. package/relay-hooks/useFragment.js.flow +1 -1
  39. package/relay-hooks/useIsParentQueryActive.js.flow +5 -1
  40. package/relay-hooks/useLazyLoadQuery.d.ts +19 -0
  41. package/relay-hooks/useLazyLoadQuery.js.flow +4 -4
  42. package/relay-hooks/useLoadMoreFunction.d.ts +56 -0
  43. package/relay-hooks/useMutation.d.ts +36 -0
  44. package/relay-hooks/useMutation.js.flow +1 -1
  45. package/relay-hooks/usePaginationFragment.d.ts +33 -0
  46. package/relay-hooks/usePaginationFragment.js.flow +9 -5
  47. package/relay-hooks/usePrefetchableForwardPaginationFragment.js.flow +7 -3
  48. package/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js.flow +7 -3
  49. package/relay-hooks/usePreloadedQuery.d.ts +17 -0
  50. package/relay-hooks/useQueryLoader.d.ts +33 -0
  51. package/relay-hooks/useQueryLoader.js.flow +1 -1
  52. package/relay-hooks/useRefetchableFragment.d.ts +23 -0
  53. package/relay-hooks/useRefetchableFragment.js.flow +10 -6
  54. package/relay-hooks/useRefetchableFragmentInternal.js.flow +4 -4
  55. package/relay-hooks/useRelayEnvironment.d.ts +10 -0
  56. package/relay-hooks/useSubscribeToInvalidationState.d.ts +19 -0
  57. package/relay-hooks/useSubscription.d.ts +14 -0
  58. package/rsc-client_EXPERIMENTAL.d.ts +17 -0
  59. package/rsc-client_EXPERIMENTAL.js +1 -1
  60. package/rsc_EXPERIMENTAL.d.ts +48 -0
  61. package/rsc_EXPERIMENTAL.js +1 -1
  62. package/rsc_EXPERIMENTAL.js.flow +5 -5
package/legacy.d.ts ADDED
@@ -0,0 +1,143 @@
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 {MappedFragmentProps, RelayPaginationProp, RelayProp, RelayRefetchProp} from './ReactRelayTypes';
9
+ import * as React from 'react';
10
+ import {
11
+ _FragmentRefs,
12
+ _RefType,
13
+ CacheConfig,
14
+ FetchPolicy,
15
+ GraphQLTaggedNode,
16
+ IEnvironment,
17
+ OperationType,
18
+ PageInfo,
19
+ RelayContext,
20
+ Variables,
21
+ } from 'relay-runtime';
22
+
23
+ export { FragmentRef, RelayPaginationProp, RelayProp, RelayRefetchProp } from './ReactRelayTypes';
24
+
25
+ export {
26
+ DataID,
27
+ DeclarativeMutationConfig,
28
+ Disposable,
29
+ FetchPolicy,
30
+ GraphQLTaggedNode,
31
+ // RelayRuntime has two environment exports: one interface, one concrete.
32
+ IEnvironment as Environment,
33
+ MutationType,
34
+ NormalizationSelector,
35
+ OperationDescriptor,
36
+ RangeOperation,
37
+ ReaderSelector,
38
+ RelayContext,
39
+ Snapshot,
40
+ Variables,
41
+ } from 'relay-runtime';
42
+
43
+ /**
44
+ * Legacy react-relay exports.
45
+ * Should prefer using interface defined in ./hooks.js
46
+ */
47
+ export { ConnectionHandler } from 'relay-runtime';
48
+ export interface QueryRendererProps<TOperation extends OperationType> {
49
+ environment: IEnvironment;
50
+ query: GraphQLTaggedNode | null | undefined;
51
+ render: (renderProps: {
52
+ error: Error | null;
53
+ props: TOperation['response'] | null;
54
+ retry: (() => void) | null;
55
+ }) => React.ReactNode;
56
+ variables: TOperation['variables'];
57
+ }
58
+ declare class ReactRelayQueryRenderer<TOperation extends OperationType> extends React.Component<
59
+ {
60
+ cacheConfig?: CacheConfig | null | undefined;
61
+ fetchPolicy?: FetchPolicy | undefined;
62
+ } & QueryRendererProps<TOperation>
63
+ > {}
64
+ export { ReactRelayQueryRenderer as QueryRenderer };
65
+
66
+ declare class ReactRelayLocalQueryRenderer<TOperation extends OperationType> extends React.Component<
67
+ QueryRendererProps<TOperation>
68
+ > {}
69
+ export { ReactRelayLocalQueryRenderer as LocalQueryRenderer };
70
+
71
+ export { MutationTypes } from 'relay-runtime';
72
+ export { RangeOperations } from 'relay-runtime';
73
+
74
+ export const ReactRelayContext: React.Context<RelayContext | null>;
75
+
76
+ export { applyOptimisticMutation } from 'relay-runtime';
77
+ export { commitLocalUpdate } from 'relay-runtime';
78
+ export { commitMutation } from 'relay-runtime';
79
+
80
+ export type ContainerProps<Props> = MappedFragmentProps<Pick<Props, Exclude<keyof Props, 'relay'>>>;
81
+ export type RelayProps<Props> = ContainerProps<Props>; // TODO: validate this
82
+ export type Container<Props> = React.ComponentType<
83
+ ContainerProps<Props> & { componentRef?: ((ref: any) => void) | undefined }
84
+ >;
85
+
86
+ // TODO: validate the bellow three
87
+ export type RelayFragmentContainer<TComponent extends React.ElementType> = React.ComponentType<
88
+ ContainerProps<React.ComponentPropsWithoutRef<TComponent>>
89
+ >;
90
+
91
+ export type RelayPaginationContainer<TComponent extends React.ElementType> = React.ComponentType<
92
+ ContainerProps<React.ComponentPropsWithoutRef<TComponent>>
93
+ >;
94
+
95
+ export type RelayRefetchContainer<TComponent extends React.ElementType> = React.ComponentType<
96
+ ContainerProps<React.ComponentPropsWithoutRef<TComponent>>
97
+ >;
98
+
99
+ type PropsWithoutRelay<C extends keyof React.JSX.IntrinsicElements | React.JSXElementConstructor<any>> =
100
+ React.JSX.LibraryManagedAttributes<C, Omit<React.ComponentProps<C>, 'relay'>>;
101
+
102
+ export function createFragmentContainer<
103
+ C extends React.ComponentType<React.ComponentProps<C> & { relay?: RelayProp | undefined }>,
104
+ >(Component: C, fragmentSpec: Record<string, GraphQLTaggedNode>): Container<PropsWithoutRelay<C>>;
105
+
106
+ export { fetchQuery_DEPRECATED } from 'relay-runtime';
107
+
108
+ export { graphql } from 'relay-runtime';
109
+ export { readInlineData } from 'relay-runtime';
110
+ export { requestSubscription } from 'relay-runtime';
111
+
112
+ export function createPaginationContainer<
113
+ C extends React.ComponentType<React.ComponentProps<C> & { relay: RelayPaginationProp }>,
114
+ >(
115
+ Component: C,
116
+ fragmentSpec: Record<string, GraphQLTaggedNode>,
117
+ connectionConfig: ConnectionConfig<PropsWithoutRelay<C>>,
118
+ ): Container<PropsWithoutRelay<C>>;
119
+
120
+ export function createRefetchContainer<
121
+ C extends React.ComponentType<React.ComponentProps<C> & { relay: RelayRefetchProp }>,
122
+ >(
123
+ Component: C,
124
+ fragmentSpec: Record<string, GraphQLTaggedNode>,
125
+ refetchQuery: GraphQLTaggedNode,
126
+ ): Container<PropsWithoutRelay<C>>;
127
+
128
+ export interface ConnectionConfig<Props = object> {
129
+ direction?: 'backward' | 'forward' | undefined;
130
+ getConnectionFromProps?: ((props: Props) => ConnectionData | null | undefined) | undefined;
131
+ getFragmentVariables?: ((prevVars: Variables, totalCount: number) => Variables) | undefined;
132
+ getVariables: (
133
+ props: Props,
134
+ paginationInfo: { count: number; cursor?: string | null | undefined },
135
+ fragmentVariables: Variables,
136
+ ) => Variables;
137
+ query: GraphQLTaggedNode;
138
+ }
139
+
140
+ interface ConnectionData {
141
+ edges?: readonly any[] | null | undefined;
142
+ pageInfo?: Partial<PageInfo> | null | undefined;
143
+ }
package/legacy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v21.0.0
2
+ * Relay v21.0.1
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-relay",
3
3
  "description": "A framework for building GraphQL-driven React applications.",
4
- "version": "21.0.0",
4
+ "version": "21.0.1",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay",
@@ -20,7 +20,7 @@
20
20
  "fbjs": "^3.0.2",
21
21
  "invariant": "^2.2.4",
22
22
  "nullthrows": "^1.1.1",
23
- "relay-runtime": "21.0.0"
23
+ "relay-runtime": "21.0.1"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^16.9.0 || ^17 || ^18 || ^19"
@@ -0,0 +1,22 @@
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 {EntryPointComponent, PreloadedEntryPoint} from '../ReactRelayTypes';
9
+ import { ReactElement } from 'react';
10
+
11
+ type GetComponentFromPreloadedEntryPoint<T> = T extends PreloadedEntryPoint<infer C> ? C : never;
12
+ type GetRuntimePropsFromComponent<T> = T extends EntryPointComponent<any, any, infer R, any> ? R : never;
13
+
14
+ export function EntryPointContainer<TPreloadedEntryPoint extends PreloadedEntryPoint<any>>({
15
+ entryPointReference,
16
+ props,
17
+ }: Readonly<{
18
+ entryPointReference: TPreloadedEntryPoint;
19
+ props: GetRuntimePropsFromComponent<GetComponentFromPreloadedEntryPoint<TPreloadedEntryPoint>>;
20
+ }>): ReactElement;
21
+
22
+ export {};
@@ -34,21 +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
- +enableForOfflineCacheJob?: ?boolean,
41
- +prefetchExpiryInHours?: ?number,
42
- +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,
43
43
  };
44
44
 
45
45
  export type LoadQueryOptions = {
46
- +fetchPolicy?: ?FetchPolicy,
47
- +networkCacheConfig?: ?CacheConfig,
48
- +__nameForWarning?: ?string,
46
+ readonly fetchPolicy?: ?FetchPolicy,
47
+ readonly networkCacheConfig?: ?CacheConfig,
48
+ readonly __nameForWarning?: ?string,
49
49
  };
50
50
 
51
- export type PreloadableConcreteRequest<+TQuery extends OperationType> = {
51
+ export type PreloadableConcreteRequest<out TQuery extends OperationType> = {
52
52
  kind: 'PreloadableConcreteRequest',
53
53
  params: RequestParameters,
54
54
  // Note: the phantom type parameter here helps ensures that the
@@ -56,63 +56,63 @@ export type PreloadableConcreteRequest<+TQuery extends OperationType> = {
56
56
  // We also need to add usage of this generic here,
57
57
  // becuase not using the generic in the definition makes it
58
58
  // unconstrained in the call to a function that accepts PreloadableConcreteRequest<T>
59
- +__phantom__?: ?TQuery,
59
+ readonly __phantom__?: ?TQuery,
60
60
  };
61
61
 
62
- export type EnvironmentProviderOptions = {+[string]: unknown, ...};
62
+ export type EnvironmentProviderOptions = {readonly [string]: unknown, ...};
63
63
 
64
64
  export type PreloadedQuery<
65
- +TQuery extends OperationType,
65
+ out TQuery extends OperationType,
66
66
  TEnvironmentProviderOptions = EnvironmentProviderOptions,
67
67
  > =
68
68
  | PreloadedQueryInner_DEPRECATED<TQuery, TEnvironmentProviderOptions>
69
69
  | PreloadedQueryInner<TQuery, TEnvironmentProviderOptions>;
70
70
 
71
71
  export type PreloadedQueryInner_DEPRECATED<
72
- +TQuery extends OperationType,
72
+ out TQuery extends OperationType,
73
73
  TEnvironmentProviderOptions = EnvironmentProviderOptions,
74
74
  > = {
75
- +kind: 'PreloadedQuery_DEPRECATED',
76
- +environment: IEnvironment,
77
- +environmentProviderOptions: ?TEnvironmentProviderOptions,
78
- +fetchKey: ?string | ?number,
79
- +fetchPolicy: FetchPolicy,
80
- +networkCacheConfig?: ?CacheConfig,
81
- +id: ?string,
82
- +name: string,
83
- +source: ?Observable<GraphQLResponse>,
84
- +variables: TQuery['variables'],
85
- +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,
86
86
  };
87
87
 
88
88
  export type PreloadedQueryInner<
89
- +TQuery extends OperationType,
89
+ out TQuery extends OperationType,
90
90
  TEnvironmentProviderOptions = EnvironmentProviderOptions,
91
91
  > = {
92
92
  // Releases query data and cancels network request if still in flight
93
- +dispose: () => void,
93
+ readonly dispose: () => void,
94
94
  // Releases query data
95
- +releaseQuery: () => void,
95
+ readonly releaseQuery: () => void,
96
96
  // Cancels network request if still in flight
97
- +cancelNetworkRequest: () => void,
98
- +environment: IEnvironment,
99
- +environmentProviderOptions: ?TEnvironmentProviderOptions,
100
- +fetchKey: string | number,
101
- +fetchPolicy: FetchPolicy,
102
- +id: ?string,
103
- +isDisposed: boolean,
104
- +networkError: ?Error,
105
- +name: string,
106
- +networkCacheConfig: ?CacheConfig,
107
- +source: ?Observable<GraphQLResponse>,
108
- +kind: 'PreloadedQuery',
109
- +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'],
110
110
  };
111
111
 
112
112
  export type PreloadQueryStatus = {
113
- +cacheConfig: ?CacheConfig,
114
- +source: 'cache' | 'network',
115
- +fetchTime: ?number,
113
+ readonly cacheConfig: ?CacheConfig,
114
+ readonly source: 'cache' | 'network',
115
+ readonly fetchTime: ?number,
116
116
  };
117
117
 
118
118
  /**
@@ -129,9 +129,9 @@ the preloaders (routeParams, query variables)
129
129
  TEntryPointComponent - the root components
130
130
  */
131
131
  export type EntryPoint<
132
- -TEntryPointParams,
132
+ in TEntryPointParams,
133
133
  // $FlowExpectedError[unclear-type] accepts any root component
134
- +TEntryPointComponent extends EntryPointComponent<any, any, any, any, any>,
134
+ out TEntryPointComponent extends EntryPointComponent<any, any, any, any, any>,
135
135
  > = Readonly<{
136
136
  getPreloadProps: (
137
137
  entryPointParams: TEntryPointParams,
@@ -178,7 +178,7 @@ export type EntryPointComponent<
178
178
  TPreloadedEntryPoints = {},
179
179
  TRuntimeProps = {},
180
180
  TExtraProps = null,
181
- +TRenders extends React.Node = React.Node,
181
+ out TRenders extends React.Node = React.Node,
182
182
  > = component(
183
183
  ...EntryPointProps<
184
184
  TPreloadedQueries,
@@ -191,7 +191,7 @@ export type EntryPointComponent<
191
191
  // Return type of the `getPreloadProps(...)` of the entry point
192
192
  export type PreloadProps<
193
193
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
194
- TPreloadedQueries extends {+[string]: ?PreloadedQuery<any>},
194
+ TPreloadedQueries extends {readonly [string]: ?PreloadedQuery<any>},
195
195
  TPreloadedEntryPoints extends {...},
196
196
  TExtraProps = null,
197
197
  TEnvironmentProviderOptions = EnvironmentProviderOptions,
@@ -215,7 +215,7 @@ export type PreloadedEntryPoint<TEntryPointComponent> = Readonly<{
215
215
  }>;
216
216
 
217
217
  export type EntryPointElementConfig<
218
- +TEntryPoint extends EntryPoint<
218
+ out TEntryPoint extends EntryPoint<
219
219
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
220
220
  any,
221
221
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
@@ -230,7 +230,7 @@ export type EntryPointElementConfig<
230
230
  : empty;
231
231
 
232
232
  export type ThinQueryParams<
233
- +TQuery extends OperationType,
233
+ out TQuery extends OperationType,
234
234
  TEnvironmentProviderOptions,
235
235
  > = Readonly<{
236
236
  environmentProviderOptions?: ?TEnvironmentProviderOptions,
@@ -254,17 +254,21 @@ export type ExtractQueryTypeHelper<TEnvironmentProviderOptions> = <TQuery>(
254
254
  // We need to match both cases without using distributive conditional types,
255
255
  // because PreloadedQuery's TQuery parameter is almost phantom, and breaking
256
256
  // up the union type would cause us to lose track of TQuery.
257
- type ExtractThinQueryParams<T, TEnvironmentProviderOptions> = [+t: T] extends [
257
+ type ExtractThinQueryParams<T, TEnvironmentProviderOptions> = [
258
+ readonly t: T,
259
+ ] extends [
258
260
  // $FlowFixMe[incompatible-type]
259
- +t: PreloadedQuery<infer TQuery extends OperationType>,
261
+ readonly t: PreloadedQuery<infer TQuery extends OperationType>,
260
262
  ]
261
263
  ? ThinQueryParams<TQuery, TEnvironmentProviderOptions>
262
- : [+t: T] extends [
263
- +t: PreloadedQuery<infer TQuery extends OperationType> | void,
264
+ : [readonly t: T] extends [
265
+ readonly t: PreloadedQuery<infer TQuery extends OperationType> | void,
264
266
  ]
265
267
  ? ThinQueryParams<TQuery, TEnvironmentProviderOptions> | void
266
- : [+t: T] extends [
267
- +t: PreloadedQuery<infer TQuery extends OperationType> | null | void,
268
+ : [readonly t: T] extends [
269
+ readonly t: PreloadedQuery<
270
+ infer TQuery extends OperationType,
271
+ > | null | void,
268
272
  ]
269
273
  ? ThinQueryParams<TQuery, TEnvironmentProviderOptions> | null | void
270
274
  : empty;
@@ -272,7 +276,7 @@ type ExtractThinQueryParams<T, TEnvironmentProviderOptions> = [+t: T] extends [
272
276
  export type ExtractQueryTypes<
273
277
  TEnvironmentProviderOptions,
274
278
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
275
- PreloadedQueries extends {+[string]: ?PreloadedQuery<any>} | void,
279
+ PreloadedQueries extends {readonly [string]: ?PreloadedQuery<any>} | void,
276
280
  > = {
277
281
  [K in keyof PreloadedQueries]: ExtractThinQueryParams<
278
282
  PreloadedQueries[K],
@@ -281,7 +285,7 @@ export type ExtractQueryTypes<
281
285
  };
282
286
 
283
287
  // $FlowFixMe[unclear-type]: we don't care about the props
284
- export type RootComponentRenders<+C extends component(...any)> =
288
+ export type RootComponentRenders<out C extends component(...any)> =
285
289
  // $FlowFixMe[unclear-type]: we don't care about the props
286
290
  C extends component(...any) renders infer R extends React.Node ? R : empty;
287
291
 
@@ -64,7 +64,7 @@ function stableStringify(value: unknown): string {
64
64
  function prepareEntryPoint<
65
65
  TEntryPointParams extends {...},
66
66
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
67
- TPreloadedQueries extends {+[string]: PreloadedQuery<any>},
67
+ TPreloadedQueries extends {readonly [string]: PreloadedQuery<any>},
68
68
  TPreloadedEntryPoints extends {...},
69
69
  TRuntimeProps extends {...},
70
70
  TExtraProps,
@@ -157,7 +157,7 @@ function prepareEntryPoint<
157
157
  function LazyLoadEntryPointContainer_DEPRECATED<
158
158
  TEntryPointParams extends {...},
159
159
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
160
- TPreloadedQueries extends {+[string]: PreloadedQuery<any>},
160
+ TPreloadedQueries extends {readonly [string]: PreloadedQuery<any>},
161
161
  TPreloadedEntryPoints extends {...},
162
162
  TRuntimeProps extends {...},
163
163
  TExtraProps,
@@ -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,11 +85,11 @@ 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?: unknown,
92
- +$fragmentSpreads: unknown,
90
+ readonly __fragmentPropName?: ?string,
91
+ readonly __module_component?: unknown,
92
+ readonly $fragmentSpreads: unknown,
93
93
  ...
94
94
  };
95
95
 
@@ -97,10 +97,10 @@ export type MatchContainerProps<
97
97
  TProps extends {...},
98
98
  TFallback extends React.Node,
99
99
  > = {
100
- +fallback?: ?TFallback,
101
- +loader: (module: unknown) => component(...TProps),
102
- +match: ?MatchPointer | ?TypenameOnlyPointer,
103
- +props?: TProps,
100
+ readonly fallback?: ?TFallback,
101
+ readonly loader: (module: unknown) => component(...TProps),
102
+ readonly match: ?MatchPointer | ?TypenameOnlyPointer,
103
+ readonly props?: TProps,
104
104
  };
105
105
 
106
106
  function MatchContainer<
@@ -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>;
@@ -41,9 +41,9 @@ export type QueryResource = QueryResourceImpl;
41
41
 
42
42
  type QueryResourceCache = Cache<QueryResourceCacheEntry>;
43
43
  type QueryResourceCacheEntry = {
44
- +id: number,
45
- +cacheIdentifier: string,
46
- +operationAvailability: ?OperationAvailability,
44
+ readonly id: number,
45
+ readonly cacheIdentifier: string,
46
+ readonly operationAvailability: ?OperationAvailability,
47
47
  // The number of received payloads for the operation.
48
48
  // We want to differentiate the initial graphql response for the operation
49
49
  // from the incremental responses, so later we can choose how to handle errors
@@ -0,0 +1,16 @@
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 {ProviderProps, ReactElement, ReactNode} from 'react';
9
+ import {IEnvironment, RelayContext} from 'relay-runtime';
10
+
11
+ export interface Props {
12
+ children: ReactNode;
13
+ environment: IEnvironment;
14
+ }
15
+
16
+ export function RelayEnvironmentProvider(props: Props): ReactElement<ProviderProps<RelayContext>>;
@@ -20,9 +20,9 @@ import type {
20
20
  import type {OperationType} from 'relay-runtime';
21
21
 
22
22
  type Query = {
23
- +variables: {foo: string, bar: number},
24
- +response: unknown,
25
- +rawResponse?: {...},
23
+ readonly variables: {foo: string, bar: number},
24
+ readonly response: unknown,
25
+ readonly rawResponse?: {...},
26
26
  };
27
27
 
28
28
  const _good: ExtractQueryTypes<