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
@@ -0,0 +1,17 @@
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 { PreloadedQuery } from '../ReactRelayTypes';
9
+ import {GraphQLTaggedNode, OperationType, RenderPolicy} from 'relay-runtime';
10
+
11
+ export function usePreloadedQuery<TQuery extends OperationType>(
12
+ gqlQuery: GraphQLTaggedNode,
13
+ preloadedQuery: PreloadedQuery<TQuery>,
14
+ options?: {
15
+ UNSTABLE_renderPolicy?: RenderPolicy | undefined;
16
+ },
17
+ ): TQuery['response'];
@@ -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 {LoadQueryOptions, PreloadedQuery} from '../ReactRelayTypes';
9
+ import {
10
+ DisposeFn,
11
+ GraphQLTaggedNode,
12
+ IEnvironment,
13
+ OperationType,
14
+ PreloadableConcreteRequest,
15
+ VariablesOf,
16
+ } from 'relay-runtime';
17
+
18
+ export type useQueryLoaderHookType<TQuery extends OperationType> = [
19
+ PreloadedQuery<TQuery> | null | undefined,
20
+ (variables: VariablesOf<TQuery>, options?: UseQueryLoaderLoadQueryOptions) => void,
21
+ DisposeFn,
22
+ ];
23
+
24
+ export type UseQueryLoaderLoadQueryOptions =
25
+ & LoadQueryOptions
26
+ & Readonly<{
27
+ __environment?: IEnvironment | null | undefined;
28
+ }>;
29
+
30
+ export function useQueryLoader<TQuery extends OperationType>(
31
+ preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
32
+ initialQueryReference?: PreloadedQuery<TQuery> | null,
33
+ ): useQueryLoaderHookType<TQuery>;
@@ -37,7 +37,7 @@ export type LoaderFn<TQuery extends OperationType> = (
37
37
 
38
38
  export type UseQueryLoaderLoadQueryOptions = Readonly<{
39
39
  ...LoadQueryOptions,
40
- +__environment?: ?IEnvironment,
40
+ readonly __environment?: ?IEnvironment,
41
41
  }>;
42
42
 
43
43
  // NullQueryReference needs to implement referential equality,
@@ -0,0 +1,23 @@
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 {GraphQLTaggedNode, OperationType} from 'relay-runtime';
10
+
11
+ export type useRefetchableFragmentHookType<
12
+ TQuery extends OperationType,
13
+ TKey extends KeyType | null | undefined,
14
+ TFragmentData,
15
+ > = [TFragmentData, RefetchFnDynamic<TQuery, TKey>];
16
+ export function useRefetchableFragment<TQuery extends OperationType, TKey extends KeyType>(
17
+ fragmentInput: GraphQLTaggedNode,
18
+ fragmentRef: TKey,
19
+ ): useRefetchableFragmentHookType<TQuery, TKey, KeyTypeData<TKey>>;
20
+ export function useRefetchableFragment<TQuery extends OperationType, TKey extends KeyType>(
21
+ fragmentInput: GraphQLTaggedNode,
22
+ fragmentRef: TKey | null | undefined,
23
+ ): useRefetchableFragmentHookType<TQuery, TKey, KeyTypeData<TKey> | null | undefined>;
@@ -26,12 +26,14 @@ const {getFragment} = require('relay-runtime');
26
26
 
27
27
  type RefetchVariables<
28
28
  TVariables,
29
- TKey extends ?{+$fragmentSpreads: unknown, ...},
29
+ TKey extends ?{readonly $fragmentSpreads: unknown, ...},
30
30
  > =
31
31
  // NOTE: This type ensures that the type of the returned variables is either:
32
32
  // - nullable if the provided ref type is nullable
33
33
  // - non-nullable if the provided ref type is non-nullable
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
 
@@ -48,12 +50,14 @@ export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
48
50
  export type ReturnType<
49
51
  TVariables,
50
52
  TData,
51
- TKey extends ?{+$fragmentSpreads: unknown, ...},
53
+ TKey extends ?{readonly $fragmentSpreads: unknown, ...},
52
54
  > = [
53
55
  // NOTE: This type ensures that the type of the returned data is either:
54
56
  // - nullable if the provided ref type is nullable
55
57
  // - non-nullable if the provided ref type is non-nullable
56
- [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
58
+ [readonly key: TKey] extends [
59
+ readonly key: {readonly $fragmentSpreads: unknown, ...},
60
+ ]
57
61
  ? TData
58
62
  : ?TData,
59
63
  RefetchFn<TVariables, TKey>,
@@ -63,7 +67,7 @@ export type UseRefetchableFragmentType = <
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
  fragment: RefetchableFragment<TFragmentType, TData, TVariables>,
69
73
  key: TKey,
@@ -73,7 +77,7 @@ hook useRefetchableFragment<
73
77
  TFragmentType extends FragmentType,
74
78
  TVariables extends Variables,
75
79
  TData,
76
- TKey extends ?{+$fragmentSpreads: TFragmentType, ...},
80
+ TKey extends ?{readonly $fragmentSpreads: TFragmentType, ...},
77
81
  >(
78
82
  fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
79
83
  fragmentRef: TKey,
@@ -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,
@@ -162,7 +162,7 @@ function reducer(state: RefetchState, action: Action): RefetchState {
162
162
 
163
163
  hook useRefetchableFragmentInternal<
164
164
  TQuery extends OperationType,
165
- TKey extends ?{+$data?: unknown, ...},
165
+ TKey extends ?{readonly $data?: unknown, ...},
166
166
  >(
167
167
  fragmentNode: ReaderFragment,
168
168
  parentFragmentRef: unknown,
@@ -0,0 +1,10 @@
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 { Environment } from 'relay-runtime';
9
+
10
+ export function useRelayEnvironment(): Environment;
@@ -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 {DataID, Disposable} from 'relay-runtime';
9
+
10
+ /**
11
+ * This hook subscribes a callback to the invalidation state of the given data
12
+ * ids.
13
+ * Any time the invalidation state of the given data ids changes, the provided
14
+ * callback will be called.
15
+ * If new ids or a new callback are provided, the subscription will be
16
+ * re-established and the previous one will be disposed.
17
+ * The subscription will automatically be disposed on unmount
18
+ */
19
+ export function useSubscribeToInvalidationState(dataIDs: readonly DataID[], callback: () => void): Disposable;
@@ -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 {GraphQLSubscriptionConfig, OperationType, requestSubscription} from 'relay-runtime';
9
+
10
+ export function useSubscription<TSubscriptionPayload extends OperationType>(
11
+ // The actual subtype of OperationType is required to allow for type inference inside GraphQLSubscriptionConfig.s
12
+ config: GraphQLSubscriptionConfig<TSubscriptionPayload>,
13
+ requestSubscriptionFn?: typeof requestSubscription,
14
+ ): void;
@@ -0,0 +1,17 @@
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 { PreloadedQueryRef } from './rsc_EXPERIMENTAL';
9
+ import {GraphQLTaggedNode, OperationType} from 'relay-runtime';
10
+
11
+ export function useQueryFromServer<T extends OperationType>(
12
+ query: GraphQLTaggedNode,
13
+ queryRef: PreloadedQueryRef<T['variables'], T['response']>,
14
+ options?: { staleThresholdMs?: number },
15
+ ): T['response'];
16
+
17
+ export { PreloadedQueryRef };
@@ -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
  *
@@ -0,0 +1,48 @@
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, IEnvironment, OperationType} from 'relay-runtime';
10
+
11
+ export interface PreloadedQueryResponse<TData> {
12
+ readonly data: TData;
13
+ readonly errors?: ReadonlyArray<{ readonly message: string }>;
14
+ }
15
+
16
+ export interface PreloadedQueryRef<TVariables, TData> {
17
+ readonly kind: 'PreloadedQueryRef';
18
+ readonly queryId: string;
19
+ readonly variables: TVariables;
20
+ readonly _response: Promise<PreloadedQueryResponse<TData>>;
21
+ readonly fetchedAt: number;
22
+ }
23
+
24
+ export interface ServerEnvironment {
25
+ readonly getEnvironment: () => IEnvironment;
26
+ readonly serverFetchQuery: <T extends OperationType>(
27
+ query: GraphQLTaggedNode,
28
+ variables: T['variables'],
29
+ ) => Promise<T['response']>;
30
+ readonly serverPreloadQuery: <T extends OperationType>(
31
+ query: GraphQLTaggedNode,
32
+ variables: T['variables'],
33
+ ) => PreloadedQueryRef<T['variables'], T['response']>;
34
+ readonly serverReadFragment: {
35
+ <TKey extends KeyType>(
36
+ fragment: GraphQLTaggedNode,
37
+ fragmentRef: TKey,
38
+ ): Promise<KeyTypeData<TKey>>;
39
+ <TKey extends ArrayKeyType>(
40
+ fragment: GraphQLTaggedNode,
41
+ fragmentRef: TKey,
42
+ ): Promise<ArrayKeyTypeData<TKey>>;
43
+ };
44
+ }
45
+
46
+ export function createServerEnvironment(
47
+ create: () => IEnvironment,
48
+ ): ServerEnvironment;
@@ -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
  *
@@ -28,19 +28,19 @@ const React = require('react');
28
28
 
29
29
  export type {PreloadedQueryRef};
30
30
 
31
- type HasSpread<TFragmentType> = {+$fragmentSpreads: TFragmentType, ...};
31
+ type HasSpread<TFragmentType> = {readonly $fragmentSpreads: TFragmentType, ...};
32
32
 
33
33
  export type ServerEnvironment = {
34
- +getEnvironment: () => IEnvironment,
35
- +serverFetchQuery: <TVariables extends Variables, TData>(
34
+ readonly getEnvironment: () => IEnvironment,
35
+ readonly serverFetchQuery: <TVariables extends Variables, TData>(
36
36
  query: Query<TVariables, TData>,
37
37
  variables: TVariables,
38
38
  ) => Promise<TData>,
39
- +serverPreloadQuery: <TVariables extends Variables, TData>(
39
+ readonly serverPreloadQuery: <TVariables extends Variables, TData>(
40
40
  query: Query<TVariables, TData>,
41
41
  variables: TVariables,
42
42
  ) => PreloadedQueryRef<TVariables, TData>,
43
- +serverReadFragment: <TFragmentType extends FragmentType, TData>(
43
+ readonly serverReadFragment: <TFragmentType extends FragmentType, TData>(
44
44
  fragment: Fragment<TFragmentType, TData>,
45
45
  fragmentRef:
46
46
  | HasSpread<TFragmentType>