relay-runtime 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 (107) hide show
  1. package/experimental.d.ts +34 -0
  2. package/experimental.js +1 -1
  3. package/experimental.js.flow +4 -4
  4. package/handlers/RelayDefaultHandlerProvider.d.ts +12 -0
  5. package/handlers/connection/ConnectionHandler.d.ts +51 -0
  6. package/handlers/connection/ConnectionInterface.d.ts +40 -0
  7. package/handlers/connection/MutationHandlers.d.ts +17 -0
  8. package/index.d.ts +274 -0
  9. package/index.js +1 -1
  10. package/llm-docs/api-reference/relay-runtime/fetch-query.mdx +5 -0
  11. package/llm-docs/getting-started/compiler.mdx +19 -3
  12. package/llm-docs/getting-started/quick-start.mdx +15 -12
  13. package/llm-docs/guides/codemods.mdx +14 -1
  14. package/multi-actor-environment/ActorIdentifier.d.ts +17 -0
  15. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +9 -9
  16. package/multi-actor-environment/MultiActorEnvironment.d.ts +123 -0
  17. package/multi-actor-environment/MultiActorEnvironment.js.flow +22 -18
  18. package/multi-actor-environment/MultiActorEnvironmentTypes.d.ts +225 -0
  19. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +3 -3
  20. package/multi-actor-environment/index.d.ts +14 -0
  21. package/multi-actor-environment.d.ts +8 -0
  22. package/mutations/RelayDeclarativeMutationConfig.d.ts +70 -0
  23. package/mutations/applyOptimisticMutation.d.ts +25 -0
  24. package/mutations/commitLocalUpdate.d.ts +10 -0
  25. package/mutations/commitMutation.d.ts +48 -0
  26. package/mutations/commitMutation.js.flow +1 -1
  27. package/network/RelayNetwork.d.ts +12 -0
  28. package/network/RelayNetworkTypes.d.ts +145 -0
  29. package/network/RelayNetworkTypes.js.flow +15 -15
  30. package/network/RelayObservable.d.ts +197 -0
  31. package/network/RelayObservable.js.flow +21 -21
  32. package/network/RelayQueryResponseCache.d.ts +16 -0
  33. package/package.json +1 -1
  34. package/query/GraphQLTag.d.ts +45 -0
  35. package/query/fetchQuery.d.ts +21 -0
  36. package/query/fetchQueryInternal.d.ts +26 -0
  37. package/query/fetchQueryInternal.js.flow +4 -4
  38. package/query/fetchQuery_DEPRECATED.d.ts +17 -0
  39. package/store/ClientID.d.ts +14 -0
  40. package/store/DataChecker.js.flow +8 -6
  41. package/store/NormalizationEngine.js.flow +4 -1
  42. package/store/OperationExecutor.d.ts +51 -0
  43. package/store/OperationExecutor.js.flow +33 -30
  44. package/store/RelayModernEnvironment.d.ts +97 -0
  45. package/store/RelayModernEnvironment.js.flow +21 -21
  46. package/store/RelayModernOperationDescriptor.d.ts +28 -0
  47. package/store/RelayModernRecord.d.ts +92 -0
  48. package/store/RelayModernSelector.d.ts +123 -0
  49. package/store/RelayModernStore.d.ts +57 -0
  50. package/store/RelayOperationTracker.d.ts +29 -0
  51. package/store/RelayPublishQueue.js.flow +8 -8
  52. package/store/RelayRecordSource.d.ts +26 -0
  53. package/store/RelayRecordState.d.ts +28 -0
  54. package/store/RelayResponseNormalizer.d.ts +28 -0
  55. package/store/RelayResponseNormalizer.js.flow +8 -8
  56. package/store/RelayStoreTypes.d.ts +1327 -0
  57. package/store/RelayStoreTypes.js.flow +284 -280
  58. package/store/RelayStoreUtils.d.ts +86 -0
  59. package/store/RelayStoreUtils.js.flow +2 -2
  60. package/store/ResolverFragments.d.ts +43 -0
  61. package/store/ResolverFragments.js.flow +14 -6
  62. package/store/StoreInspector.js.flow +2 -2
  63. package/store/ViewerPattern.d.ts +11 -0
  64. package/store/createFragmentSpecResolver.d.ts +16 -0
  65. package/store/defaultGetDataID.js.flow +1 -1
  66. package/store/isRelayModernEnvironment.d.ts +8 -0
  67. package/store/live-resolvers/LiveResolverCache.js.flow +1 -1
  68. package/store/live-resolvers/resolverDataInjector.d.ts +27 -0
  69. package/store/observeFragmentExperimental.d.ts +46 -0
  70. package/store/observeFragmentExperimental.js.flow +1 -1
  71. package/store/observeQueryExperimental.d.ts +30 -0
  72. package/store/readInlineData.d.ts +19 -0
  73. package/store/readInlineData.js.flow +1 -1
  74. package/store/waitForFragmentExperimental.d.ts +49 -0
  75. package/subscription/requestSubscription.d.ts +27 -0
  76. package/subscription/requestSubscription.js.flow +3 -3
  77. package/util/JSResourceTypes.flow.js.flow +4 -4
  78. package/util/NormalizationNode.d.ts +235 -0
  79. package/util/NormalizationNode.js.flow +124 -122
  80. package/util/ReaderNode.d.ts +264 -0
  81. package/util/ReaderNode.js.flow +152 -149
  82. package/util/RelayConcreteNode.d.ts +120 -0
  83. package/util/RelayConcreteNode.js.flow +31 -31
  84. package/util/RelayError.d.ts +13 -0
  85. package/util/RelayFeatureFlags.d.ts +40 -0
  86. package/util/RelayProfiler.d.ts +121 -0
  87. package/util/RelayReplaySubject.d.ts +25 -0
  88. package/util/RelayRuntimeTypes.d.ts +59 -0
  89. package/util/RelayRuntimeTypes.js.flow +33 -30
  90. package/util/createPayloadFor3DField.d.ts +17 -0
  91. package/util/createPayloadFor3DField.js.flow +4 -4
  92. package/util/deepFreeze.d.ts +8 -0
  93. package/util/getFragmentIdentifier.d.ts +10 -0
  94. package/util/getPaginationMetadata.d.ts +20 -0
  95. package/util/getPaginationVariables.d.ts +20 -0
  96. package/util/getPendingOperationsForFragment.d.ts +18 -0
  97. package/util/getRefetchMetadata.d.ts +19 -0
  98. package/util/getRelayHandleKey.d.ts +8 -0
  99. package/util/getRequestIdentifier.d.ts +17 -0
  100. package/util/getValueAtPath.d.ts +8 -0
  101. package/util/handlePotentialSnapshotErrors.d.ts +14 -0
  102. package/util/isEmptyObject.js.flow +1 -1
  103. package/util/isPromise.d.ts +8 -0
  104. package/util/isScalarAndEqual.d.ts +8 -0
  105. package/util/recycleNodesInto.d.ts +8 -0
  106. package/util/stableCopy.d.ts +8 -0
  107. package/util/withProvidedVariables.d.ts +19 -0
@@ -0,0 +1,86 @@
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 {NormalizationArgument, NormalizationField, NormalizationHandle} from '../util/NormalizationNode';
9
+ import {ReaderArgument, ReaderField} from '../util/ReaderNode';
10
+ import { Variables } from '../util/RelayRuntimeTypes';
11
+
12
+ export interface Arguments {
13
+ [key: string]: any;
14
+ }
15
+
16
+ /**
17
+ * Returns the values of field/fragment arguments as an object keyed by argument
18
+ * names. Guaranteed to return a result with stable ordered nested values.
19
+ */
20
+ export function getArgumentValues(
21
+ args: ReadonlyArray<NormalizationArgument | ReaderArgument>,
22
+ variables: Variables,
23
+ ): Arguments;
24
+
25
+ /**
26
+ * Given a handle field and variable values, returns a key that can be used to
27
+ * uniquely identify the combination of the handle name and argument values.
28
+ *
29
+ * Note: the word "storage" here refers to the fact this key is primarily used
30
+ * when writing the results of a key in a normalized graph or "store". This
31
+ * name was used in previous implementations of Relay internals and is also
32
+ * used here for consistency.
33
+ */
34
+ export function getHandleStorageKey(handleField: NormalizationHandle, variables: Variables): string;
35
+
36
+ /**
37
+ * Given a field and variable values, returns a key that can be used to
38
+ * uniquely identify the combination of the field name and argument values.
39
+ *
40
+ * Note: the word "storage" here refers to the fact this key is primarily used
41
+ * when writing the results of a key in a normalized graph or "store". This
42
+ * name was used in previous implementations of Relay internals and is also
43
+ * used here for consistency.
44
+ */
45
+ export function getStorageKey(
46
+ field: NormalizationField | NormalizationHandle | ReaderField,
47
+ variables: Variables,
48
+ ): string;
49
+
50
+ /**
51
+ * Given a `name` (eg. "foo") and an object representing argument values
52
+ * (eg. `{orberBy: "name", first: 10}`) returns a unique storage key
53
+ * (ie. `foo{"first":10,"orderBy":"name"}`).
54
+ *
55
+ * This differs from getStorageKey which requires a ConcreteNode where arguments
56
+ * are assumed to already be sorted into a stable order.
57
+ */
58
+ export function getStableStorageKey(name: string, args: Arguments): string;
59
+
60
+ /**
61
+ * Given a name and argument values, format a storage key.
62
+ *
63
+ * Arguments and the values within them are expected to be ordered in a stable
64
+ * alphabetical ordering.
65
+ */
66
+ export function formatStorageKey(name: string, argValues: Arguments): string;
67
+
68
+ /**
69
+ * Given Variables and a variable name, return a variable value with
70
+ * all values in a stable order.
71
+ */
72
+ export function getStableVariableValue(name: string, variables: Variables): unknown;
73
+
74
+ export function getModuleComponentKey(documentName: string): string;
75
+ export function getModuleOperationKey(documentName: string): string;
76
+
77
+ export const FRAGMENTS_KEY: string;
78
+ export const FRAGMENT_OWNER_KEY: string;
79
+ export const FRAGMENT_PROP_NAME_KEY: string;
80
+ export const MODULE_COMPONENT_KEY: string; // alias returned by Reader
81
+ export const ID_KEY: string;
82
+ export const REF_KEY: string;
83
+ export const REFS_KEY: string;
84
+ export const ROOT_ID: string;
85
+ export const ROOT_TYPE: string;
86
+ export const TYPENAME_KEY: string;
@@ -35,8 +35,8 @@ const {stableCopy} = require('../util/stableCopy');
35
35
  const invariant = require('invariant');
36
36
 
37
37
  export type Arguments = {
38
- +FRAGMENT_POINTER_IS_WITHIN_UNMATCHED_TYPE_REFINEMENT?: boolean,
39
- +[string]: unknown,
38
+ readonly FRAGMENT_POINTER_IS_WITHIN_UNMATCHED_TYPE_REFINEMENT?: boolean,
39
+ readonly [string]: unknown,
40
40
  };
41
41
 
42
42
  const {VARIABLE, LITERAL, OBJECT_VALUE, LIST_VALUE} = RelayConcreteNode;
@@ -0,0 +1,43 @@
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 type { GraphQLTaggedNode } from '../query/GraphQLTag';
9
+ import type {ArrayKeyType, ArrayKeyTypeData, FragmentType, KeyType, KeyTypeData, SingularReaderSelector} from './RelayStoreTypes';
10
+
11
+ export interface ResolverContext {
12
+ getDataForResolverFragment: (
13
+ arg0: SingularReaderSelector,
14
+ arg1: FragmentType,
15
+ ) => {
16
+ data: unknown;
17
+ isMissingData: boolean;
18
+ };
19
+ }
20
+
21
+ export const RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL: unknown;
22
+
23
+ export function withResolverContext<T>(context: ResolverContext, cb: () => T): T;
24
+
25
+ export function readFragment<TKey extends KeyType>(
26
+ fragmentInput: GraphQLTaggedNode,
27
+ fragmentRef: TKey,
28
+ ): KeyTypeData<TKey>;
29
+
30
+ export function readFragment<TKey extends KeyType>(
31
+ fragmentInput: GraphQLTaggedNode,
32
+ fragmentRef: TKey | null,
33
+ ): KeyTypeData<TKey> | null;
34
+
35
+ export function readFragment<TKey extends ArrayKeyType>(
36
+ fragmentInput: GraphQLTaggedNode,
37
+ fragmentRef: TKey,
38
+ ): ArrayKeyTypeData<TKey>;
39
+
40
+ export function readFragment<TKey extends ArrayKeyType>(
41
+ fragmentInput: GraphQLTaggedNode,
42
+ fragmentRef: TKey | null,
43
+ ): ArrayKeyTypeData<TKey> | null;
@@ -52,14 +52,22 @@ function withResolverContext<T>(context: ResolverContext, cb: () => T): T {
52
52
  // - array of nullable if the provided ref type is an array of nullable refs
53
53
 
54
54
  declare function readFragment<
55
- TKey extends {+$data?: unknown, +$fragmentSpreads: FragmentType, ...},
55
+ TKey extends {
56
+ readonly $data?: unknown,
57
+ readonly $fragmentSpreads: FragmentType,
58
+ ...
59
+ },
56
60
  >(
57
61
  fragmentInput: GraphQLTaggedNode,
58
62
  fragmentKey: TKey,
59
63
  ): NonNullable<TKey['$data']>;
60
64
 
61
65
  declare function readFragment<
62
- TKey extends ?{+$data?: unknown, +$fragmentSpreads: FragmentType, ...},
66
+ TKey extends ?{
67
+ readonly $data?: unknown,
68
+ readonly $fragmentSpreads: FragmentType,
69
+ ...
70
+ },
63
71
  >(
64
72
  fragmentInput: GraphQLTaggedNode,
65
73
  fragmentKey: TKey,
@@ -67,8 +75,8 @@ declare function readFragment<
67
75
 
68
76
  declare function readFragment<
69
77
  TKey extends ReadonlyArray<{
70
- +$data?: unknown,
71
- +$fragmentSpreads: FragmentType,
78
+ readonly $data?: unknown,
79
+ readonly $fragmentSpreads: FragmentType,
72
80
  ...
73
81
  }>,
74
82
  >(
@@ -78,8 +86,8 @@ declare function readFragment<
78
86
 
79
87
  declare function readFragment<
80
88
  TKey extends ?ReadonlyArray<{
81
- +$data?: unknown,
82
- +$fragmentSpreads: FragmentType,
89
+ readonly $data?: unknown,
90
+ readonly $fragmentSpreads: FragmentType,
83
91
  ...
84
92
  }>,
85
93
  >(
@@ -80,8 +80,8 @@ if (__DEV__) {
80
80
  const isRecord = (o: $FlowFixMe) => o != null && typeof o.__id === 'string';
81
81
 
82
82
  class RecordEntry {
83
- +key: string;
84
- +value: unknown;
83
+ readonly key: string;
84
+ readonly value: unknown;
85
85
  constructor(key: string, value: unknown) {
86
86
  this.key = key;
87
87
  this.value = value;
@@ -0,0 +1,11 @@
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 type { DataID } from '../util/RelayRuntimeTypes';
9
+
10
+ export const VIEWER_ID: DataID;
11
+ export const VIEWER_TYPE = 'Viewer';
@@ -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 {FragmentMap, FragmentSpecResolver, Props, RelayContext} from './RelayStoreTypes';
9
+
10
+ export function createFragmentSpecResolver(
11
+ context: RelayContext,
12
+ containerName: string,
13
+ fragments: FragmentMap,
14
+ props: Props,
15
+ callback?: () => void,
16
+ ): FragmentSpecResolver;
@@ -14,7 +14,7 @@
14
14
  const {VIEWER_ID, VIEWER_TYPE} = require('./ViewerPattern');
15
15
 
16
16
  function defaultGetDataID(
17
- fieldValue: {+[string]: unknown},
17
+ fieldValue: {readonly [string]: unknown},
18
18
  typeName: string,
19
19
  ): unknown {
20
20
  if (typeName === VIEWER_TYPE) {
@@ -0,0 +1,8 @@
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
+ export function isRelayModernEnvironment(environment: any): boolean;
@@ -772,7 +772,7 @@ class LiveResolverCache implements ResolverCache {
772
772
  // containing only "weak" records.
773
773
  _normalizeOutputTypeValue(
774
774
  outputTypeDataID: DataID,
775
- value: {+[key: string]: unknown},
775
+ value: {readonly [key: string]: unknown},
776
776
  variables: Variables,
777
777
  normalizationInfo: ResolverNormalizationInfo,
778
778
  fieldPath: Array<string>,
@@ -0,0 +1,27 @@
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 type { GraphQLTaggedNode } from '../../query/GraphQLTag';
9
+ import type { FragmentType } from '../RelayStoreTypes';
10
+
11
+ /**
12
+ * This a higher order function that returns a relay resolver that can read the data for
13
+ * the fragment`.
14
+ *
15
+ * - fragment: contains fragment Reader AST with resolver's data dependencies.
16
+ * - resolverFn: original resolver function that expects a data from the fragment
17
+ * - (optional) fieldName: individual field that needs to be read out of the fragment.
18
+ *
19
+ * This will not call the `resolverFn` if the fragment data for it is null/undefined.
20
+ * The compiler generates calls to this function, ensuring the correct set of arguments.
21
+ */
22
+ export function resolverDataInjector(
23
+ fragment: GraphQLTaggedNode,
24
+ _resolverFn: unknown,
25
+ fieldName?: string,
26
+ isRequiredField?: boolean,
27
+ ): (fragmentKey: FragmentType, args: unknown) => unknown;
@@ -0,0 +1,46 @@
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 type { RelayObservable as Observable } from '../network/RelayObservable';
9
+ import type { GraphQLTaggedNode } from '../query/GraphQLTag';
10
+ import type {ArrayKeyType, ArrayKeyTypeData, Environment as IEnvironment, FragmentState, KeyType, KeyTypeData} from './RelayStoreTypes';
11
+
12
+ /**
13
+ * EXPERIMENTAL: This API is experimental and does not yet support all Relay
14
+ * features. Notably, it does not correctly handle some features of Relay Resolvers.
15
+ *
16
+ * Given a fragment and a fragment reference, returns an observable that emits
17
+ * the state of the fragment over time. The observable will emit the following
18
+ * values:
19
+ * - 'ok': The fragment has a value
20
+ * - 'error': The fragment has an error, this could be due to a network error or
21
+ * a field error due to @required(action: THROW) or @throwOnFieldError
22
+ * - 'loading': The fragment is still in flight and is still expected to resolver.
23
+ */
24
+ export function observeFragment<TKey extends KeyType>(
25
+ environment: IEnvironment,
26
+ fragmentInput: GraphQLTaggedNode,
27
+ fragmentRef: TKey,
28
+ ): Observable<FragmentState<KeyTypeData<TKey>>>;
29
+
30
+ /**
31
+ * EXPERIMENTAL: This API is experimental and does not yet support all Relay
32
+ * features. Notably, it does not correctly handle some features of Relay Resolvers.
33
+ *
34
+ * Given a fragment and a fragment reference, returns an observable that emits
35
+ * the state of the fragment over time. The observable will emit the following
36
+ * values:
37
+ * - 'ok': The fragment has a value
38
+ * - 'error': The fragment has an error, this could be due to a network error or
39
+ * a field error due to @required(action: THROW) or @throwOnFieldError
40
+ * - 'loading': The fragment is still in flight and is still expected to resolver.
41
+ */
42
+ export function observeFragment<TKey extends ArrayKeyType>(
43
+ environment: IEnvironment,
44
+ fragmentInput: GraphQLTaggedNode,
45
+ fragmentRef: TKey,
46
+ ): Observable<FragmentState<ArrayKeyTypeData<TKey>>>;
@@ -45,7 +45,7 @@ export type FragmentState<T> =
45
45
  | {state: 'loading'};
46
46
 
47
47
  export type HasSpread<TFragmentType> = {
48
- +$fragmentSpreads: TFragmentType,
48
+ readonly $fragmentSpreads: TFragmentType,
49
49
  ...
50
50
  };
51
51
 
@@ -0,0 +1,30 @@
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 type { RelayObservable as Observable } from '../network/RelayObservable';
9
+ import type { GraphQLTaggedNode } from '../query/GraphQLTag';
10
+ import type { OperationType } from '../util/RelayRuntimeTypes';
11
+ import type {Environment as IEnvironment, FragmentState} from './RelayStoreTypes';
12
+
13
+ /**
14
+ * This function returns an observable that can be used to subscribe to the data
15
+ * contained in a query. It does not return the full response shape, but rather
16
+ * the contents of the query body minus any fragment spreads. If you wish to
17
+ * read the contents of a fragment spread into this query you may pass the
18
+ * object into which the fragment was spread to `observeFragment`.
19
+ *
20
+ * NOTE: `observeQuery` assumes that you have already fetched and retained the
21
+ * query via some other means, such as `fetchQuery`.
22
+ *
23
+ * This feature is still experimental and does not properly handle some resolver
24
+ * features such as client-to-server edges.
25
+ */
26
+ export function observeQuery<T extends OperationType>(
27
+ environment: IEnvironment,
28
+ gqlQuery: GraphQLTaggedNode,
29
+ variables: T['variables'],
30
+ ): Observable<FragmentState<T['response']>>;
@@ -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 type { GraphQLTaggedNode } from '../query/GraphQLTag';
9
+ import type {KeyType, KeyTypeData} from './RelayStoreTypes';
10
+
11
+ export function readInlineData<TKey extends KeyType>(
12
+ fragmentInput: GraphQLTaggedNode,
13
+ fragmentRef: TKey,
14
+ ): KeyTypeData<TKey>;
15
+
16
+ export function readInlineData<TKey extends KeyType>(
17
+ fragmentInput: GraphQLTaggedNode,
18
+ fragmentRef: TKey | null | undefined,
19
+ ): KeyTypeData<TKey> | null | undefined;
@@ -20,7 +20,7 @@ const {FRAGMENTS_KEY} = require('./RelayStoreUtils');
20
20
  const invariant = require('invariant');
21
21
 
22
22
  type HasSpread<TFragmentType> = {
23
- +$fragmentSpreads: TFragmentType,
23
+ readonly $fragmentSpreads: TFragmentType,
24
24
  ...
25
25
  };
26
26
 
@@ -0,0 +1,49 @@
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 type { GraphQLTaggedNode } from '../query/GraphQLTag';
9
+ import type {ArrayKeyType, ArrayKeyTypeData, Environment as IEnvironment, KeyType, KeyTypeData} from './RelayStoreTypes';
10
+
11
+ /**
12
+ * EXPERIMENTAL: This API is experimental and does not yet support all Relay
13
+ * features. Notably, it does not correctly handle some features of Relay Resolvers.
14
+ *
15
+ * Given a fragment and a fragment reference, returns a promise that resolves
16
+ * once the fragment data is available, or rejects if the fragment has an error.
17
+ * Errors include both network errors and field errors due to @required(action:
18
+ * THROW) or @throwOnFieldError.
19
+
20
+ * This API is intended for use when consuming data outside of a UI framework, or
21
+ * when you need to imperatively access data inside an event handler. For example,
22
+ * you might choose to @defer a fragment that you only need to access inside an
23
+ * event handler and then await its value inside the handler if/when it is triggered.
24
+ */
25
+ export function waitForFragmentData<TKey extends KeyType>(
26
+ environment: IEnvironment,
27
+ fragmentInput: GraphQLTaggedNode,
28
+ fragmentRef: TKey,
29
+ ): Promise<KeyTypeData<TKey>>;
30
+
31
+ /**
32
+ * EXPERIMENTAL: This API is experimental and does not yet support all Relay
33
+ * features. Notably, it does not correctly handle some features of Relay Resolvers.
34
+ *
35
+ * Given a fragment and a fragment reference, returns a promise that resolves
36
+ * once the fragment data is available, or rejects if the fragment has an error.
37
+ * Errors include both network errors and field errors due to @required(action:
38
+ * THROW) or @throwOnFieldError.
39
+
40
+ * This API is intended for use when consuming data outside of a UI framework, or
41
+ * when you need to imperatively access data inside an event handler. For example,
42
+ * you might choose to @defer a fragment that you only need to access inside an
43
+ * event handler and then await its value inside the handler if/when it is triggered.
44
+ */
45
+ export function waitForFragmentData<TKey extends ArrayKeyType>(
46
+ environment: IEnvironment,
47
+ fragmentInput: GraphQLTaggedNode,
48
+ fragmentRef: TKey,
49
+ ): Promise<ArrayKeyTypeData<TKey>>;
@@ -0,0 +1,27 @@
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 { DeclarativeMutationConfig } from '../mutations/RelayDeclarativeMutationConfig';
9
+ import { GraphQLTaggedNode } from '../query/GraphQLTag';
10
+ import {Environment, SelectorStoreUpdater} from '../store/RelayStoreTypes';
11
+ import {CacheConfig, Disposable, OperationType} from '../util/RelayRuntimeTypes';
12
+
13
+ export interface GraphQLSubscriptionConfig<TSubscription extends OperationType> {
14
+ cacheConfig?: CacheConfig | undefined;
15
+ configs?: readonly DeclarativeMutationConfig[] | undefined;
16
+ subscription: GraphQLTaggedNode;
17
+ variables: TSubscription['variables'];
18
+ onCompleted?: (() => void) | undefined;
19
+ onError?: ((error: Error) => void) | undefined;
20
+ onNext?: ((response: TSubscription['response'] | null | undefined) => void) | undefined;
21
+ updater?: SelectorStoreUpdater<TSubscription['response']> | undefined;
22
+ }
23
+
24
+ export function requestSubscription<TSubscription extends OperationType = OperationType>(
25
+ environment: Environment,
26
+ config: GraphQLSubscriptionConfig<TSubscription>,
27
+ ): Disposable;
@@ -32,9 +32,9 @@ const {createReaderSelector} = require('../store/RelayModernSelector');
32
32
  const warning = require('warning');
33
33
 
34
34
  export type SubscriptionParameters = {
35
- +response: {...},
36
- +variables: {...},
37
- +rawResponse?: {...},
35
+ readonly response: {...},
36
+ readonly variables: {...},
37
+ readonly rawResponse?: {...},
38
38
  };
39
39
 
40
40
  /**
@@ -11,8 +11,8 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- export interface JSResourceReference<+T> {
15
- +getModuleId: () => string;
16
- +getModuleIfRequired: () => ?T;
17
- +load: () => Promise<T>;
14
+ export interface JSResourceReference<out T> {
15
+ readonly getModuleId: () => string;
16
+ readonly getModuleIfRequired: () => ?T;
17
+ readonly load: () => Promise<T>;
18
18
  }