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
@@ -32,22 +32,22 @@ declare export var refetchableFragmentInput: RefetchableFragment<
32
32
  declare export opaque type Example_user$fragmentType: FragmentType;
33
33
  export type Example_user$data = NonNullableData;
34
34
  export type Example_user$key = {
35
- +$data?: Example_user$data,
36
- +$fragmentSpreads: Example_user$fragmentType,
35
+ readonly $data?: Example_user$data,
36
+ readonly $fragmentSpreads: Example_user$fragmentType,
37
37
  ...
38
38
  };
39
39
 
40
40
  export type NonNullableData = {
41
- +id: string,
42
- +count: number,
41
+ readonly id: string,
42
+ readonly count: number,
43
43
  };
44
44
  export type NullableData = ?NonNullableData;
45
45
  export type NonNullablePluralData = ReadonlyArray<NonNullableData>;
46
46
  export type NullablePluralData = ?ReadonlyArray<NonNullableData>;
47
47
 
48
48
  export type AnotherNonNullableData = {
49
- +name: ?string,
50
- +friends: ?number,
49
+ readonly name: ?string,
50
+ readonly friends: ?number,
51
51
  };
52
52
 
53
53
  declare export var keyNonNullable: Example_user$key;
@@ -59,25 +59,25 @@ declare export var keyNullablePlural: ?ReadonlyArray<Example_user$key>;
59
59
  declare export var keyNullable: ?Example_user$key;
60
60
 
61
61
  declare export var keyAnotherNonNullable: {
62
- +$data: AnotherNonNullableData,
63
- +$fragmentSpreads: FragmentType,
62
+ readonly $data: AnotherNonNullableData,
63
+ readonly $fragmentSpreads: FragmentType,
64
64
  ...
65
65
  };
66
66
 
67
67
  declare export var keyAnotherNullable: ?{
68
- +$data: AnotherNonNullableData,
69
- +$fragmentSpreads: FragmentType,
68
+ readonly $data: AnotherNonNullableData,
69
+ readonly $fragmentSpreads: FragmentType,
70
70
  ...
71
71
  };
72
72
 
73
73
  declare export var fragmentData: {
74
- +$fragmentType: FragmentType,
74
+ readonly $fragmentType: FragmentType,
75
75
  ...
76
76
  };
77
77
 
78
78
  export type QueryOperation = {
79
- +variables: QueryVariables,
80
- +response: {...},
79
+ readonly variables: QueryVariables,
80
+ readonly response: {...},
81
81
  };
82
82
 
83
83
  export type QueryVariables = {
@@ -31,7 +31,9 @@ type RefetchVariables<TVariables, TKey> =
31
31
  // NOTE: This type ensures that the type of the variables is either:
32
32
  // - nullable if the provided ref type is non-nullable
33
33
  // - non-nullable if the provided ref type is nullable, and the caller need to provide the full set of variables
34
- [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
34
+ [readonly key: TKey] extends [
35
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
36
+ ]
35
37
  ? Partial<TVariables>
36
38
  : TVariables;
37
39
 
@@ -49,7 +51,9 @@ type ReturnType<TVariables, TData, TKey> = {
49
51
  // NOTE: This rtpw ensures that the type of the returned data is either:
50
52
  // - nullable if the provided ref type is nullable
51
53
  // - non-nullable if the provided ref type is non-nullable
52
- data: [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
54
+ data: [readonly key: TKey] extends [
55
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
56
+ ]
53
57
  ? TData
54
58
  : ?TData,
55
59
  loadNext: LoadMoreFn<TVariables>,
@@ -63,7 +67,7 @@ hook useBlockingPaginationFragment<
63
67
  TFragmentType extends FragmentType,
64
68
  TVariables extends Variables,
65
69
  TData,
66
- TKey extends ?{+$fragmentSpreads: TFragmentType, ...},
70
+ TKey extends ?{readonly $fragmentSpreads: TFragmentType, ...},
67
71
  >(
68
72
  fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
69
73
  parentFragmentRef: TKey,
@@ -99,7 +103,7 @@ hook useBlockingPaginationFragment<
99
103
  variables: TVariables,
100
104
  },
101
105
  {
102
- +$data: unknown,
106
+ readonly $data: unknown,
103
107
  ...
104
108
  },
105
109
  >(fragmentNode, parentFragmentRef, componentDisplayName);
@@ -57,15 +57,15 @@ export type RefetchFn<
57
57
  // /non-null/.
58
58
  export type RefetchFnDynamic<
59
59
  TQuery extends OperationType,
60
- TKey extends ?{+$data?: unknown, ...},
60
+ TKey extends ?{readonly $data?: unknown, ...},
61
61
  TOptions = Options,
62
- > = [TKey] extends [{+$data?: unknown, ...}]
62
+ > = [TKey] extends [{readonly $data?: unknown, ...}]
63
63
  ? RefetchFnInexact<TQuery, TOptions>
64
64
  : RefetchFnExact<TQuery, TOptions>;
65
65
 
66
66
  export type ReturnType<
67
67
  TQuery extends OperationType,
68
- TKey extends ?{+$data?: unknown, ...},
68
+ TKey extends ?{readonly $data?: unknown, ...},
69
69
  TOptions = Options,
70
70
  > = {
71
71
  fragmentData: unknown,
@@ -164,7 +164,7 @@ function reducer(state: RefetchState, action: Action): RefetchState {
164
164
 
165
165
  hook useRefetchableFragmentNode<
166
166
  TQuery extends OperationType,
167
- TKey extends ?{+$data?: unknown, ...},
167
+ TKey extends ?{readonly $data?: unknown, ...},
168
168
  >(
169
169
  fragmentNode: ReaderFragment,
170
170
  parentFragmentRef: unknown,
@@ -0,0 +1,14 @@
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 {EnvironmentProviderOptions, GetEntryPointComponentFromEntryPoint, GetEntryPointParamsFromEntryPoint, IEnvironmentProvider, PreloadedEntryPoint} from '../ReactRelayTypes';
9
+
10
+ export function loadEntryPoint<TEntryPoint>(
11
+ environmentProvider: IEnvironmentProvider<EnvironmentProviderOptions>,
12
+ entryPoint: TEntryPoint,
13
+ entryPointParams: GetEntryPointParamsFromEntryPoint<TEntryPoint>,
14
+ ): PreloadedEntryPoint<GetEntryPointComponentFromEntryPoint<TEntryPoint>>;
@@ -25,7 +25,7 @@ const {loadQuery} = require('./loadQuery');
25
25
  function loadEntryPoint<
26
26
  TEntryPointParams extends {...},
27
27
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
28
- TPreloadedQueries extends {+[string]: PreloadedQuery<any>},
28
+ TPreloadedQueries extends {readonly [string]: PreloadedQuery<any>},
29
29
  TPreloadedEntryPoints extends {...},
30
30
  TRuntimeProps extends {...},
31
31
  TExtraProps,
@@ -0,0 +1,20 @@
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 {EnvironmentProviderOptions, LoadQueryOptions, PreloadedQuery} from '../ReactRelayTypes';
9
+ import {GraphQLTaggedNode, IEnvironment, OperationType, PreloadableConcreteRequest, VariablesOf} from 'relay-runtime';
10
+
11
+ export function loadQuery<
12
+ TQuery extends OperationType,
13
+ TEnvironmentProviderOptions extends EnvironmentProviderOptions = Record<string, unknown>,
14
+ >(
15
+ environment: IEnvironment,
16
+ preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
17
+ variables: VariablesOf<TQuery>,
18
+ options?: LoadQueryOptions,
19
+ environmentProviderOptions?: TEnvironmentProviderOptions,
20
+ ): PreloadedQuery<TQuery, TEnvironmentProviderOptions>;
@@ -50,7 +50,7 @@ export type QueryType<T> =
50
50
  response: D,
51
51
  rawResponse?: NonNullable<RR>,
52
52
  }
53
- : [+t: T] extends [+t: PreloadableConcreteRequest<infer V>]
53
+ : [readonly t: T] extends [readonly t: PreloadableConcreteRequest<infer V>]
54
54
  ? V
55
55
  : empty;
56
56
 
@@ -24,7 +24,7 @@ const preloadQuery = require('./preloadQuery_DEPRECATED');
24
24
  function prepareEntryPoint<
25
25
  TEntryPointParams extends {...},
26
26
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
27
- TPreloadedQueries extends {+[string]: PreloadedQuery<any>},
27
+ TPreloadedQueries extends {readonly [string]: PreloadedQuery<any>},
28
28
  TPreloadedEntryPoints extends {...},
29
29
  TRuntimeProps extends {...},
30
30
  TExtraProps,
@@ -157,8 +157,8 @@ function readFragmentInternal(
157
157
  queryOptions?: FragmentQueryOptions,
158
158
  fragmentKey?: string,
159
159
  ): {
160
- +data: ?SelectorData | Array<?SelectorData>,
161
- +clientEdgeQueries: ?Array<QueryResult>,
160
+ readonly data: ?SelectorData | Array<?SelectorData>,
161
+ readonly clientEdgeQueries: ?Array<QueryResult>,
162
162
  } {
163
163
  const fragmentSelector = getSelector(fragmentNode, fragmentRef);
164
164
  const isPlural = fragmentNode?.metadata?.plural === true;
@@ -17,16 +17,16 @@ const invariant = require('invariant');
17
17
  const {createOperationDescriptor, getRequest} = require('relay-runtime');
18
18
 
19
19
  export type PreloadedQueryResponse<TData> = {
20
- +data: TData,
21
- +errors?: ReadonlyArray<PayloadError>,
20
+ readonly data: TData,
21
+ readonly errors?: ReadonlyArray<PayloadError>,
22
22
  };
23
23
 
24
24
  export type PreloadedQueryRef<TVariables, TData> = {
25
- +kind: 'PreloadedQueryRef',
26
- +queryId: string,
27
- +variables: TVariables,
28
- +_response: Promise<PreloadedQueryResponse<TData>>,
29
- +fetchedAt: number,
25
+ readonly kind: 'PreloadedQueryRef',
26
+ readonly queryId: string,
27
+ readonly variables: TVariables,
28
+ readonly _response: Promise<PreloadedQueryResponse<TData>>,
29
+ readonly fetchedAt: number,
30
30
  };
31
31
 
32
32
  function serverPreloadQuery<TVariables extends Variables, TData>(
@@ -16,7 +16,7 @@ import type {Fragment, FragmentType, IEnvironment} from 'relay-runtime';
16
16
  const {waitForFragmentData} = require('relay-runtime/experimental');
17
17
 
18
18
  type HasSpread<TFragmentType> = {
19
- +$fragmentSpreads: TFragmentType,
19
+ readonly $fragmentSpreads: TFragmentType,
20
20
  ...
21
21
  };
22
22
 
@@ -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 {GraphQLTaggedNode, OperationType, RenderPolicy, VariablesOf} from 'relay-runtime';
9
+
10
+ export function useClientQuery<TQuery extends OperationType>(
11
+ gqlQuery: GraphQLTaggedNode,
12
+ variables: VariablesOf<TQuery>,
13
+ options?: {
14
+ UNSTABLE_renderPolicy?: RenderPolicy | undefined;
15
+ },
16
+ ): TQuery['response'];
@@ -0,0 +1,21 @@
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 {EnvironmentProviderOptions, GetEntryPointComponentFromEntryPoint, GetEntryPointParamsFromEntryPoint, IEnvironmentProvider, PreloadedEntryPoint} from '../ReactRelayTypes';
9
+ import { DisposeFn } from 'relay-runtime';
10
+
11
+ export type UseEntryPointLoaderHookType<TEntryPoint> = [
12
+ PreloadedEntryPoint<GetEntryPointComponentFromEntryPoint<TEntryPoint>> | null | undefined,
13
+ (entryPointParams: GetEntryPointParamsFromEntryPoint<TEntryPoint>) => void,
14
+ DisposeFn,
15
+ ];
16
+
17
+ export function useEntryPointLoader<TEntryPoint>(
18
+ environmentProvider: IEnvironmentProvider<EnvironmentProviderOptions>,
19
+ entryPoint: TEntryPoint,
20
+ // Have opted to not include the TEST_ONLY__initialEntryPointData object here—as is FB internal
21
+ ): UseEntryPointLoaderHookType<TEntryPoint>;
@@ -55,7 +55,7 @@ const initialNullEntryPointReferenceState: NullEntryPointReference = {
55
55
  hook useLoadEntryPoint<
56
56
  TEntryPointParams extends {...},
57
57
  // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
58
- TPreloadedQueries extends {+[string]: PreloadedQuery<any>},
58
+ TPreloadedQueries extends {readonly [string]: PreloadedQuery<any>},
59
59
  TPreloadedEntryPoints extends {...},
60
60
  TRuntimeProps extends {...},
61
61
  TExtraProps,
@@ -0,0 +1,36 @@
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 {ArrayKeyType, ArrayKeyTypeData, KeyType, KeyTypeData} from '../ReactRelayTypes';
9
+ import { GraphQLTaggedNode } from 'relay-runtime';
10
+
11
+ // NOTE: These declares ensure that the type of the returned data is:
12
+ // - non-nullable if the provided ref type is non-nullable
13
+ // - nullable if the provided ref type is nullable
14
+ // - array of non-nullable if the provided ref type is an array of
15
+ // non-nullable refs
16
+ // - array of nullable if the provided ref type is an array of nullable refs
17
+
18
+ export function useFragment<TKey extends KeyType>(
19
+ fragmentInput: GraphQLTaggedNode,
20
+ fragmentRef: TKey,
21
+ ): KeyTypeData<TKey>;
22
+
23
+ export function useFragment<TKey extends KeyType>(
24
+ fragmentInput: GraphQLTaggedNode,
25
+ fragmentRef: TKey | null | undefined,
26
+ ): KeyTypeData<TKey> | null | undefined;
27
+
28
+ export function useFragment<TKey extends ArrayKeyType>(
29
+ fragmentInput: GraphQLTaggedNode,
30
+ fragmentRef: TKey,
31
+ ): ArrayKeyTypeData<TKey>;
32
+
33
+ export function useFragment<TKey extends ArrayKeyType>(
34
+ fragmentInput: GraphQLTaggedNode,
35
+ fragmentRef: TKey | null | undefined,
36
+ ): ArrayKeyTypeData<TKey> | null | undefined;
@@ -19,7 +19,7 @@ const {useDebugValue} = require('react');
19
19
  const {getFragment} = require('relay-runtime');
20
20
 
21
21
  type HasSpread<TFragmentType> = {
22
- +$fragmentSpreads: TFragmentType,
22
+ readonly $fragmentSpreads: TFragmentType,
23
23
  ...
24
24
  };
25
25
 
@@ -18,7 +18,11 @@ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
18
18
  const {getFragment} = require('relay-runtime');
19
19
 
20
20
  hook useIsParentQueryActive<
21
- TKey extends ?{+$data?: unknown, +$fragmentSpreads: FragmentType, ...},
21
+ TKey extends ?{
22
+ readonly $data?: unknown,
23
+ readonly $fragmentSpreads: FragmentType,
24
+ ...
25
+ },
22
26
  >(
23
27
  fragmentInput: GraphQLTaggedNode,
24
28
  fragmentRef: TKey,
@@ -0,0 +1,19 @@
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 {CacheConfig, FetchPolicy, GraphQLTaggedNode, OperationType, RenderPolicy, VariablesOf} from 'relay-runtime';
9
+
10
+ export function useLazyLoadQuery<TQuery extends OperationType>(
11
+ gqlQuery: GraphQLTaggedNode,
12
+ variables: VariablesOf<TQuery>,
13
+ options?: {
14
+ fetchKey?: string | number | undefined;
15
+ fetchPolicy?: FetchPolicy | undefined;
16
+ networkCacheConfig?: CacheConfig | undefined;
17
+ UNSTABLE_renderPolicy?: RenderPolicy | undefined;
18
+ },
19
+ ): TQuery['response'];
@@ -47,19 +47,19 @@ type Options = {
47
47
  * * "network-only": *will* *not* reuse locally cached data, and will *always* send a network request to fetch the query, ignoring any data that might be locally cached in Relay.
48
48
  * * "store-only": *will* *only* reuse locally cached data, and will *never* send a network request to fetch the query. In this case, the responsibility of fetching the query falls to the caller, but this policy could also be used to read and operate on data that is entirely [local](../../guided-tour/updating-data/local-data-updates).
49
49
  */
50
- +fetchPolicy?: FetchPolicy,
50
+ readonly fetchPolicy?: FetchPolicy,
51
51
  /**
52
52
  * A `fetchKey` can be passed to force a re-evaluation of the current query and variables when the component re-renders, even if the variables didn't change, or even if the component isn't remounted (similarly to how passing a different `key` to a React component will cause it to remount). If the `fetchKey` is different from the one used in the previous render, the current query will be re-evaluated against the store, and it might be refetched depending on the current `fetchPolicy` and the state of the cache.
53
53
  */
54
- +fetchKey?: string | number,
54
+ readonly fetchKey?: string | number,
55
55
  /**
56
56
  * Default value: `{force: true}`. Object containing cache config options for the *network layer*. Note that the network layer may contain an *additional* query response cache which will reuse network responses for identical queries. If you want to bypass this cache completely (which is the default behavior), pass `{force: true}` as the value for this option.
57
57
  */
58
- +networkCacheConfig?: CacheConfig,
58
+ readonly networkCacheConfig?: CacheConfig,
59
59
  /**
60
60
  * Undocumented option.
61
61
  */
62
- +UNSTABLE_renderPolicy?: RenderPolicy,
62
+ readonly UNSTABLE_renderPolicy?: RenderPolicy,
63
63
  };
64
64
 
65
65
  /**
@@ -0,0 +1,56 @@
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 {
9
+ ConcreteRequest,
10
+ Disposable,
11
+ DisposeFn,
12
+ GraphQLResponse,
13
+ Observer,
14
+ OperationType,
15
+ ReaderFragment,
16
+ ReaderPaginationMetadata,
17
+ VariablesOf,
18
+ } from 'relay-runtime';
19
+
20
+ export type Direction = 'forward' | 'backward';
21
+
22
+ export type LoadMoreFn<TQuery extends OperationType> = (
23
+ count: number,
24
+ options?: {
25
+ onComplete?: ((arg: Error | null) => void) | undefined;
26
+ UNSTABLE_extraVariables?: Partial<VariablesOf<TQuery>> | undefined;
27
+ },
28
+ ) => Disposable;
29
+
30
+ export interface UseLoadMoreFunctionArgs {
31
+ direction: Direction;
32
+ fragmentNode: ReaderFragment;
33
+ fragmentRef: unknown;
34
+ fragmentIdentifier: string;
35
+ fragmentData: unknown;
36
+ connectionPathInFragmentData: ReadonlyArray<string | number>;
37
+ identifierField?: string | null | undefined;
38
+ paginationRequest: ConcreteRequest;
39
+ paginationMetadata: ReaderPaginationMetadata;
40
+ componentDisplayName: string;
41
+ observer: Observer<GraphQLResponse>;
42
+ onReset: () => void;
43
+ }
44
+ export function useLoadMoreFunction<TQuery extends OperationType>(
45
+ args: UseLoadMoreFunctionArgs,
46
+ ): [LoadMoreFn<TQuery>, boolean, DisposeFn];
47
+
48
+ export function getConnectionState(
49
+ direction: Direction,
50
+ fragmentNode: ReaderFragment,
51
+ fragmentData: unknown,
52
+ connectionPathInFragmentData: ReadonlyArray<string | number>,
53
+ ): {
54
+ cursor?: string | null | undefined;
55
+ hasMore: boolean;
56
+ };
@@ -0,0 +1,36 @@
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 {
9
+ DeclarativeMutationConfig,
10
+ Disposable,
11
+ GraphQLTaggedNode,
12
+ IEnvironment,
13
+ MutationConfig,
14
+ MutationParameters,
15
+ PayloadError,
16
+ SelectorStoreUpdater,
17
+ UploadableMap,
18
+ VariablesOf,
19
+ } from 'relay-runtime';
20
+
21
+ export interface UseMutationConfig<TMutation extends MutationParameters> {
22
+ variables: VariablesOf<TMutation>;
23
+ updater?: SelectorStoreUpdater<TMutation['response']> | null | undefined;
24
+ uploadables?: UploadableMap | undefined;
25
+ optimisticUpdater?: SelectorStoreUpdater<TMutation['response']> | null | undefined;
26
+ optimisticResponse?: TMutation['rawResponse'] | undefined;
27
+ configs?: DeclarativeMutationConfig[] | undefined;
28
+ onError?: ((error: Error) => void | null) | undefined;
29
+ onCompleted?: ((response: TMutation['response'], errors: PayloadError[] | null) => void | null) | undefined;
30
+ onUnsubscribe?: (() => void | null) | undefined;
31
+ }
32
+
33
+ export function useMutation<TMutation extends MutationParameters>(
34
+ mutation: GraphQLTaggedNode,
35
+ commitMutationFn?: (environment: IEnvironment, config: MutationConfig<TMutation>) => Disposable,
36
+ ): [(config: UseMutationConfig<TMutation>) => Disposable, boolean];
@@ -40,7 +40,7 @@ export type UseMutationConfig<TMutation extends MutationParameters> = {
40
40
  onNext?: ?() => void,
41
41
  onUnsubscribe?: ?() => void,
42
42
  optimisticResponse?: {
43
- +rawResponse?: {...},
43
+ readonly rawResponse?: {...},
44
44
  ...TMutation,
45
45
  ...
46
46
  }['rawResponse'],
@@ -0,0 +1,33 @@
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 {KeyType, KeyTypeData, RefetchFnDynamic} from '../ReactRelayTypes';
9
+ import { LoadMoreFn } from './useLoadMoreFunction';
10
+ import {GraphQLTaggedNode, OperationType} from 'relay-runtime';
11
+
12
+ export interface usePaginationFragmentHookType<
13
+ TQuery extends OperationType,
14
+ TKey extends KeyType | null | undefined,
15
+ TFragmentData,
16
+ > {
17
+ data: TFragmentData;
18
+ loadNext: LoadMoreFn<TQuery>;
19
+ loadPrevious: LoadMoreFn<TQuery>;
20
+ hasNext: boolean;
21
+ hasPrevious: boolean;
22
+ isLoadingNext: boolean;
23
+ isLoadingPrevious: boolean;
24
+ refetch: RefetchFnDynamic<TQuery, TKey>;
25
+ }
26
+ export function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(
27
+ fragmentInput: GraphQLTaggedNode,
28
+ parentFragmentRef: TKey,
29
+ ): usePaginationFragmentHookType<TQuery, TKey, KeyTypeData<TKey>>;
30
+ export function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(
31
+ fragmentInput: GraphQLTaggedNode,
32
+ parentFragmentRef: TKey | null | undefined,
33
+ ): usePaginationFragmentHookType<TQuery, TKey | null, KeyTypeData<TKey> | null | undefined>;
@@ -34,12 +34,14 @@ const {
34
34
 
35
35
  type RefetchVariables<
36
36
  TVariables,
37
- TKey extends ?{+$fragmentSpreads: unknown, ...},
37
+ TKey extends ?{readonly $fragmentSpreads: unknown, ...},
38
38
  > =
39
39
  // NOTE: This type ensures that the type of the returned variables is either:
40
40
  // - nullable if the provided ref type is nullable
41
41
  // - non-nullable if the provided ref type is non-nullable
42
- [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
42
+ [readonly key: TKey] extends [
43
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
44
+ ]
43
45
  ? Partial<TVariables>
44
46
  : TVariables;
45
47
 
@@ -57,7 +59,9 @@ export type ReturnType<TVariables, TData, TKey> = {
57
59
  // NOTE: This type ensures that the type of the returned data is either:
58
60
  // - nullable if the provided ref type is nullable
59
61
  // - non-nullable if the provided ref type is non-nullable
60
- data: [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
62
+ data: [readonly key: TKey] extends [
63
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
64
+ ]
61
65
  ? TData
62
66
  : ?TData,
63
67
  loadNext: LoadMoreFn<TVariables>,
@@ -76,7 +80,7 @@ export type UsePaginationFragmentType = <
76
80
  TFragmentType extends FragmentType,
77
81
  TVariables extends Variables,
78
82
  TData,
79
- TKey extends ?{+$fragmentSpreads: TFragmentType, ...},
83
+ TKey extends ?{readonly $fragmentSpreads: TFragmentType, ...},
80
84
  >(
81
85
  fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
82
86
  parentFragmentRef: TKey,
@@ -86,7 +90,7 @@ hook usePaginationFragment<
86
90
  TFragmentType extends FragmentType,
87
91
  TVariables extends Variables,
88
92
  TData,
89
- TKey extends ?{+$fragmentSpreads: TFragmentType, ...},
93
+ TKey extends ?{readonly $fragmentSpreads: TFragmentType, ...},
90
94
  >(
91
95
  fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
92
96
  parentFragmentRef: TKey,
@@ -55,7 +55,9 @@ export type ReturnType<TVariables, TData, TEdgeData, TKey> = {
55
55
  // NOTE: This type ensures that the type of the returned data is either:
56
56
  // - nullable if the provided ref type is nullable
57
57
  // - non-nullable if the provided ref type is non-nullable
58
- data: [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
58
+ data: [readonly key: TKey] extends [
59
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
60
+ ]
59
61
  ? TData
60
62
  : ?TData,
61
63
  loadNext: LoadMoreFn<TVariables>,
@@ -72,7 +74,9 @@ type LoadMoreOptions<TVariables> = {
72
74
 
73
75
  export type GetExtraVariablesFn<TEdgeData, TData, TVariables, TKey> = ({
74
76
  hasNext: boolean,
75
- data: [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
77
+ data: [readonly key: TKey] extends [
78
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
79
+ ]
76
80
  ? TData
77
81
  : ?TData,
78
82
  getServerEdges: () => TEdgeData,
@@ -83,7 +87,7 @@ hook usePrefetchableForwardPaginationFragment<
83
87
  TVariables extends Variables,
84
88
  TData,
85
89
  TEdgeData,
86
- TKey extends ?{+$fragmentSpreads: TFragmentType, ...},
90
+ TKey extends ?{readonly $fragmentSpreads: TFragmentType, ...},
87
91
  >(
88
92
  fragmentInput: PrefetchableRefetchableFragment<
89
93
  TFragmentType,
@@ -55,7 +55,9 @@ export type ReturnType<TVariables, TData, TEdgeData, TKey> = {
55
55
  // NOTE: This type ensures that the type of the returned data is either:
56
56
  // - nullable if the provided ref type is nullable
57
57
  // - non-nullable if the provided ref type is non-nullable
58
- data: [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
58
+ data: [readonly key: TKey] extends [
59
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
60
+ ]
59
61
  ? TData
60
62
  : ?TData,
61
63
  loadNext: LoadMoreFn<TVariables>,
@@ -72,7 +74,9 @@ type LoadMoreOptions<TVariables> = {
72
74
 
73
75
  export type GetExtraVariablesFn<TEdgeData, TData, TVariables, TKey> = ({
74
76
  hasNext: boolean,
75
- data: [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
77
+ data: [readonly key: TKey] extends [
78
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
79
+ ]
76
80
  ? TData
77
81
  : ?TData,
78
82
  getServerEdges: () => TEdgeData,
@@ -83,7 +87,7 @@ hook usePrefetchableForwardPaginationFragment_EXPERIMENTAL<
83
87
  TVariables extends Variables,
84
88
  TData,
85
89
  TEdgeData,
86
- TKey extends ?{+$fragmentSpreads: TFragmentType, ...},
90
+ TKey extends ?{readonly $fragmentSpreads: TFragmentType, ...},
87
91
  >(
88
92
  fragmentInput: PrefetchableRefetchableFragment<
89
93
  TFragmentType,