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.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +2 -2
- package/ReactRelayFragmentContainer.js.flow +8 -9
- package/ReactRelayLocalQueryRenderer.js.flow +11 -3
- package/ReactRelayLoggingContext.js.flow +3 -3
- package/ReactRelayPaginationContainer.js.flow +32 -25
- package/ReactRelayQueryFetcher.js.flow +1 -1
- package/ReactRelayQueryRenderer.js.flow +2 -2
- package/ReactRelayQueryRendererContext.js.flow +2 -2
- package/ReactRelayRefetchContainer.js.flow +17 -14
- package/ReactRelayTestMocker.js.flow +10 -10
- package/ReactRelayTypes.d.ts +377 -0
- package/ReactRelayTypes.js.flow +47 -43
- package/RelayContext.js.flow +3 -3
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +11 -11
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +5 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +5 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +32 -32
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +9 -10
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +4 -5
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +9 -10
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +4 -5
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +5 -6
- package/buildReactRelayContainer.js.flow +5 -5
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.d.ts +89 -0
- package/hooks.js +1 -1
- package/hooks.js.flow +23 -8
- package/index.d.ts +9 -0
- package/index.js +1 -1
- package/index.js.flow +40 -14
- package/isRelayEnvironment.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.d.ts +143 -0
- package/legacy.js +1 -1
- package/legacy.js.flow +32 -13
- package/lib/ReactRelayFragmentContainer.js +1 -1
- package/lib/ReactRelayPaginationContainer.js +8 -8
- package/lib/ReactRelayRefetchContainer.js +8 -8
- package/lib/ReactRelayTestMocker.js +5 -5
- package/lib/hooks.js +18 -8
- package/lib/index.js +30 -14
- package/lib/legacy.js +26 -13
- package/lib/relay-hooks/legacy/useBlockingPaginationFragment.js +5 -5
- package/lib/relay-hooks/legacy/useRefetchableFragmentNode.js +34 -34
- package/lib/relay-hooks/loadEntryPoint.js +2 -2
- package/lib/relay-hooks/loadQuery.js +14 -14
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -10
- package/lib/relay-hooks/readFragmentInternal.js +6 -6
- package/lib/relay-hooks/rsc/serverFetchQuery.js +20 -0
- package/lib/relay-hooks/rsc/serverPreloadQuery.js +31 -0
- package/lib/relay-hooks/rsc/serverReadFragment.js +15 -0
- package/lib/relay-hooks/rsc/useQueryFromServer.js +62 -0
- package/lib/relay-hooks/useFragmentInternal_CURRENT.js +49 -25
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +81 -44
- package/lib/relay-hooks/useLazyLoadQueryNode.js +32 -19
- package/lib/relay-hooks/useMutation.js +6 -14
- package/lib/relay-hooks/useMutationAction_EXPERIMENTAL.js +26 -0
- package/lib/relay-hooks/usePreloadedQuery.js +52 -47
- package/lib/relay-hooks/useQueryLoader.js +2 -2
- package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +2 -2
- package/lib/relay-hooks/useRefetchableFragmentInternal.js +31 -31
- package/lib/rsc-client_EXPERIMENTAL.js +7 -0
- package/lib/rsc_EXPERIMENTAL.js +43 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/package.json +3 -2
- package/relay-hooks/EntryPointContainer.react.d.ts +22 -0
- package/relay-hooks/EntryPointContainer.react.js.flow +6 -6
- package/relay-hooks/EntryPointTypes.flow.js.flow +106 -108
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +23 -21
- package/relay-hooks/MatchContainer.d.ts +95 -0
- package/relay-hooks/MatchContainer.js.flow +17 -11
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +3 -9
- package/relay-hooks/ProfilerContext.d.ts +18 -0
- package/relay-hooks/QueryResource.js.flow +9 -9
- package/relay-hooks/RelayEnvironmentProvider.d.ts +16 -0
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -6
- package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +50 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -9
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -4
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +5 -6
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +27 -32
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +25 -25
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +26 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +23 -30
- package/relay-hooks/__flowtests__/utils.js.flow +17 -17
- package/relay-hooks/getConnectionState.js.flow +2 -2
- package/relay-hooks/legacy/FragmentResource.js.flow +13 -13
- package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +28 -25
- package/relay-hooks/legacy/useFragmentNode.js.flow +4 -4
- package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +79 -81
- package/relay-hooks/loadEntryPoint.d.ts +14 -0
- package/relay-hooks/loadEntryPoint.js.flow +15 -13
- package/relay-hooks/loadQuery.d.ts +20 -0
- package/relay-hooks/loadQuery.js.flow +19 -19
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +16 -13
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -7
- package/relay-hooks/readFragmentInternal.js.flow +11 -11
- package/relay-hooks/rsc/serverFetchQuery.js.flow +31 -0
- package/relay-hooks/rsc/serverPreloadQuery.js.flow +69 -0
- package/relay-hooks/rsc/serverReadFragment.js.flow +33 -0
- package/relay-hooks/rsc/useQueryFromServer.js.flow +135 -0
- package/relay-hooks/useClientQuery.d.ts +16 -0
- package/relay-hooks/useClientQuery.js.flow +2 -2
- package/relay-hooks/useEntryPointLoader.d.ts +21 -0
- package/relay-hooks/useEntryPointLoader.js.flow +11 -11
- package/relay-hooks/useFragment.d.ts +36 -0
- package/relay-hooks/useFragment.js.flow +8 -8
- package/relay-hooks/useFragmentInternal.js.flow +1 -1
- package/relay-hooks/useFragmentInternal_CURRENT.js.flow +54 -22
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +95 -46
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +5 -1
- package/relay-hooks/useLazyLoadQuery.d.ts +19 -0
- package/relay-hooks/useLazyLoadQuery.js.flow +14 -7
- package/relay-hooks/useLazyLoadQueryNode.js.flow +67 -28
- package/relay-hooks/useLoadMoreFunction.d.ts +56 -0
- package/relay-hooks/useLoadMoreFunction.js.flow +7 -6
- package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +5 -5
- package/relay-hooks/useMemoVariables.js.flow +1 -1
- package/relay-hooks/useMutation.d.ts +36 -0
- package/relay-hooks/useMutation.js.flow +9 -17
- package/relay-hooks/useMutationAction_EXPERIMENTAL.js.flow +68 -0
- package/relay-hooks/usePaginationFragment.d.ts +33 -0
- package/relay-hooks/usePaginationFragment.js.flow +19 -11
- package/relay-hooks/usePrefetchableForwardPaginationFragment.js.flow +23 -18
- package/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js.flow +23 -18
- package/relay-hooks/usePreloadedQuery.d.ts +17 -0
- package/relay-hooks/usePreloadedQuery.js.flow +119 -85
- package/relay-hooks/useQueryLoader.d.ts +33 -0
- package/relay-hooks/useQueryLoader.js.flow +28 -24
- package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +10 -10
- package/relay-hooks/useRefetchableFragment.d.ts +23 -0
- package/relay-hooks/useRefetchableFragment.js.flow +20 -11
- package/relay-hooks/useRefetchableFragmentInternal.js.flow +77 -79
- package/relay-hooks/useRelayEnvironment.d.ts +10 -0
- package/relay-hooks/useRelayLoggingContext.js.flow +1 -1
- package/relay-hooks/useSubscribeToInvalidationState.d.ts +19 -0
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
- package/relay-hooks/useSubscription.d.ts +14 -0
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/rsc-client_EXPERIMENTAL.d.ts +17 -0
- package/rsc-client_EXPERIMENTAL.js +10 -0
- package/rsc-client_EXPERIMENTAL.js.flow +23 -0
- package/rsc_EXPERIMENTAL.d.ts +48 -0
- package/rsc_EXPERIMENTAL.js +10 -0
- 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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
readonly fetchPolicy?: ?FetchPolicy,
|
|
47
|
+
readonly networkCacheConfig?: ?CacheConfig,
|
|
48
|
+
readonly __nameForWarning?: ?string,
|
|
48
49
|
};
|
|
49
50
|
|
|
50
|
-
export type PreloadableConcreteRequest
|
|
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
|
-
|
|
59
|
+
readonly __phantom__?: ?TQuery,
|
|
59
60
|
};
|
|
60
61
|
|
|
61
|
-
export type EnvironmentProviderOptions = {
|
|
62
|
+
export type EnvironmentProviderOptions = {readonly [string]: unknown, ...};
|
|
62
63
|
|
|
63
64
|
export type PreloadedQuery<
|
|
64
|
-
|
|
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
|
-
|
|
72
|
+
out TQuery extends OperationType,
|
|
72
73
|
TEnvironmentProviderOptions = EnvironmentProviderOptions,
|
|
73
74
|
> = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
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
|
-
|
|
93
|
+
readonly dispose: () => void,
|
|
93
94
|
// Releases query data
|
|
94
|
-
|
|
95
|
+
readonly releaseQuery: () => void,
|
|
95
96
|
// Cancels network request if still in flight
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
|
140
|
-
TEntryPointParams,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
> =
|
|
152
|
+
> = Readonly<{
|
|
171
153
|
entryPoints: TPreloadedEntryPoints,
|
|
172
154
|
extraProps: TExtraProps | null,
|
|
173
155
|
props: TRuntimeProps,
|
|
174
156
|
queries: TPreloadedQueries,
|
|
175
157
|
}>;
|
|
176
158
|
|
|
177
|
-
|
|
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
|
|
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
|
|
198
|
-
TPreloadedEntryPoints
|
|
194
|
+
TPreloadedQueries extends {readonly [string]: ?PreloadedQuery<any>},
|
|
195
|
+
TPreloadedEntryPoints extends {...},
|
|
199
196
|
TExtraProps = null,
|
|
200
197
|
TEnvironmentProviderOptions = EnvironmentProviderOptions,
|
|
201
|
-
> =
|
|
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> =
|
|
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
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
223
|
+
>,
|
|
224
|
+
> =
|
|
225
|
+
TEntryPoint extends EntryPoint<
|
|
226
|
+
infer _EntryPointParams,
|
|
227
|
+
infer EntryPointComponent,
|
|
234
228
|
>
|
|
235
|
-
?
|
|
229
|
+
? ElementConfig<EntryPointComponent>['props']
|
|
236
230
|
: empty;
|
|
237
231
|
|
|
238
232
|
export type ThinQueryParams<
|
|
239
|
-
|
|
233
|
+
out TQuery extends OperationType,
|
|
240
234
|
TEnvironmentProviderOptions,
|
|
241
|
-
> =
|
|
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> = [
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
: [
|
|
269
|
-
|
|
264
|
+
: [readonly t: T] extends [
|
|
265
|
+
readonly t: PreloadedQuery<infer TQuery extends OperationType> | void,
|
|
270
266
|
]
|
|
271
267
|
? ThinQueryParams<TQuery, TEnvironmentProviderOptions> | void
|
|
272
|
-
:
|
|
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
|
|
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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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> =
|
|
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> =
|
|
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
|
-
> =
|
|
44
|
-
|
|
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:
|
|
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
|
|
68
|
-
TPreloadedEntryPoints
|
|
69
|
-
TRuntimeProps
|
|
67
|
+
TPreloadedQueries extends {readonly [string]: PreloadedQuery<any>},
|
|
68
|
+
TPreloadedEntryPoints extends {...},
|
|
69
|
+
TRuntimeProps extends {...},
|
|
70
70
|
TExtraProps,
|
|
71
|
-
TEntryPointComponent
|
|
71
|
+
TEntryPointComponent extends EntryPointComponent<
|
|
72
72
|
TPreloadedQueries,
|
|
73
73
|
TPreloadedEntryPoints,
|
|
74
74
|
TRuntimeProps,
|
|
75
75
|
TExtraProps,
|
|
76
76
|
>,
|
|
77
|
-
TEntryPoint
|
|
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
|
-
|
|
107
|
+
unknown,
|
|
108
108
|
>(
|
|
109
109
|
environment,
|
|
110
110
|
parameters,
|
|
@@ -129,14 +129,15 @@ function prepareEntryPoint<
|
|
|
129
129
|
{},
|
|
130
130
|
{...},
|
|
131
131
|
{...},
|
|
132
|
-
|
|
133
|
-
EntryPointComponent<{}, {...}, {...},
|
|
132
|
+
unknown,
|
|
133
|
+
EntryPointComponent<{}, {...}, {...}, unknown>,
|
|
134
134
|
_,
|
|
135
135
|
>(environmentProvider, nestedEntryPoint, nestedParams);
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
return {
|
|
139
|
-
|
|
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-
|
|
148
|
-
return
|
|
148
|
+
// $FlowFixMe[incompatible-type] - trust me Flow, its entryPoint component
|
|
149
|
+
return component as TEntryPointComponent;
|
|
149
150
|
},
|
|
150
|
-
|
|
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
|
|
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 = {
|
|
88
|
+
type TypenameOnlyPointer = {readonly __typename: string};
|
|
89
89
|
export type MatchPointer = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
readonly __fragmentPropName?: ?string,
|
|
91
|
+
readonly __module_component?: unknown,
|
|
92
|
+
readonly $fragmentSpreads: unknown,
|
|
93
93
|
...
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
export type MatchContainerProps<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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<
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
entryPoint:
|
|
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>;
|