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,145 @@
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 { RequestParameters } from '../util/RelayConcreteNode';
9
+ import {CacheConfig, Disposable, Variables} from '../util/RelayRuntimeTypes';
10
+ import {ObservableFromValue, RelayObservable} from './RelayObservable';
11
+
12
+ /**
13
+ * An interface for fetching the data for one or more (possibly interdependent)
14
+ * queries.
15
+ */
16
+ export interface Network {
17
+ execute: ExecuteFunction;
18
+ }
19
+ export type LogRequestInfoFunction = (arg: any) => void;
20
+
21
+ export interface PayloadData {
22
+ [key: string]: any;
23
+ }
24
+
25
+ export interface PayloadError {
26
+ message: string;
27
+ locations?:
28
+ | Array<{
29
+ line: number;
30
+ column: number;
31
+ }>
32
+ | undefined;
33
+ path?: Array<string | number>;
34
+ severity?: 'CRITICAL' | 'ERROR' | 'WARNING' | undefined; // Not officially part of the spec, but used at Facebook
35
+ }
36
+
37
+ export interface PayloadExtensions {
38
+ [key: string]: any;
39
+ }
40
+
41
+ /**
42
+ * The shape of a GraphQL response as dictated by the
43
+ * [spec](https://graphql.github.io/graphql-spec/June2018/#sec-Response-Format)
44
+ */
45
+ export interface GraphQLResponseWithData {
46
+ data: PayloadData;
47
+ errors?: PayloadError[] | undefined;
48
+ extensions?: PayloadExtensions | undefined;
49
+ label?: string | undefined;
50
+ path?: Array<string | number> | undefined;
51
+ }
52
+ export interface GraphQLResponseWithoutData {
53
+ data?: PayloadData | undefined;
54
+ errors: PayloadError[];
55
+ extensions?: PayloadExtensions | undefined;
56
+ label?: string | undefined;
57
+ path?: Array<string | number> | undefined;
58
+ }
59
+ export interface GraphQLResponseWithExtensionsOnly {
60
+ // Per https://spec.graphql.org/June2018/#sec-Errors
61
+ // > If the data entry in the response is not present, the errors entry
62
+ // > in the response must not be empty. It must contain at least one error
63
+ // This means a payload has to have either a data key or an errors key:
64
+ // but the spec leaves room for the combination of data: null plus extensions
65
+ // since `data: null` is a *required* output if there was an error during
66
+ // execution, but the inverse is not described in the sepc: `data: null`
67
+ // does not necessarily indicate that there was an error.
68
+ data: null;
69
+ extensions: PayloadExtensions;
70
+ }
71
+
72
+ export type GraphQLSingularResponse =
73
+ | GraphQLResponseWithData
74
+ | GraphQLResponseWithExtensionsOnly
75
+ | GraphQLResponseWithoutData;
76
+
77
+ export type GraphQLResponse = GraphQLSingularResponse | readonly GraphQLSingularResponse[];
78
+
79
+ /**
80
+ * A function that returns an Observable representing the response of executing
81
+ * a GraphQL operation.
82
+ */
83
+ export type ExecuteFunction = (
84
+ request: RequestParameters,
85
+ variables: Variables,
86
+ cacheConfig: CacheConfig,
87
+ uploadables?: UploadableMap | null,
88
+ ) => RelayObservable<GraphQLResponse>;
89
+
90
+ /**
91
+ * A function that executes a GraphQL operation with request/response semantics.
92
+ *
93
+ * May return an Observable or Promise of a plain GraphQL server response, or
94
+ * a composed ExecutePayload object supporting additional metadata.
95
+ */
96
+ export type FetchFunction = (
97
+ request: RequestParameters,
98
+ variables: Variables,
99
+ cacheConfig: CacheConfig,
100
+ uploadables?: UploadableMap | null,
101
+ ) => ObservableFromValue<GraphQLResponse>;
102
+
103
+ export interface LegacyObserver<T> {
104
+ onCompleted?: (() => void) | undefined;
105
+ onError?: ((error: Error) => void) | undefined;
106
+ onNext?: ((data: T) => void) | undefined;
107
+ }
108
+
109
+ /**
110
+ * A function that executes a GraphQL subscription operation, returning zero or
111
+ * more raw server responses over time.
112
+ */
113
+ export type SubscribeFunction = (
114
+ request: RequestParameters,
115
+ variables: Variables,
116
+ cacheConfig: CacheConfig,
117
+ observer?: LegacyObserver<GraphQLResponse>,
118
+ ) => RelayObservable<GraphQLResponse> | Disposable;
119
+
120
+ export type Uploadable = File | Blob;
121
+ export interface UploadableMap {
122
+ [key: string]: Uploadable;
123
+ }
124
+
125
+ /**
126
+ * React Flight tree created on the server.
127
+ */
128
+ export type ReactFlightServerTree = any;
129
+ export interface ReactFlightPayloadQuery {
130
+ readonly id: any;
131
+ readonly module: any;
132
+ readonly response: GraphQLSingularResponse;
133
+ readonly variables: Variables;
134
+ }
135
+ /**
136
+ * Data that is returned by a Flight compliant GraphQL server.
137
+ *
138
+ * - tree: an array of values that will be iterated and fed into
139
+ * ReactFlightDOMRelayClient.
140
+ * - queries: an array of queries that the server preloaded for the client.
141
+ */
142
+ export interface ReactFlightPayloadData {
143
+ readonly tree: ReactFlightServerTree[];
144
+ readonly queries: ReactFlightPayloadQuery[];
145
+ }
@@ -21,12 +21,12 @@ import type RelayObservable, {ObservableFromValue} from './RelayObservable';
21
21
  * queries.
22
22
  */
23
23
  export interface INetwork {
24
- +execute: ExecuteFunction;
24
+ readonly execute: ExecuteFunction;
25
25
  }
26
26
 
27
27
  export type LogRequestInfoFunction = unknown => void;
28
28
 
29
- export type PayloadData = {+[key: string]: unknown};
29
+ export type PayloadData = {readonly [key: string]: unknown};
30
30
 
31
31
  export type PayloadError = interface {
32
32
  message: string,
@@ -47,19 +47,19 @@ export type PayloadExtensions = {[key: string]: unknown, ...};
47
47
  * [spec](https://spec.graphql.org/June2018/#sec-Response-Format).
48
48
  */
49
49
  export type GraphQLResponseWithData = {
50
- +data: PayloadData,
51
- +errors?: Array<PayloadError>,
52
- +extensions?: PayloadExtensions,
53
- +label?: string,
54
- +path?: Array<string | number>,
50
+ readonly data: PayloadData,
51
+ readonly errors?: Array<PayloadError>,
52
+ readonly extensions?: PayloadExtensions,
53
+ readonly label?: string,
54
+ readonly path?: Array<string | number>,
55
55
  };
56
56
 
57
57
  export type GraphQLResponseWithoutData = {
58
- +data?: ?PayloadData,
59
- +errors: Array<PayloadError>,
60
- +extensions?: PayloadExtensions,
61
- +label?: string,
62
- +path?: Array<string | number>,
58
+ readonly data?: ?PayloadData,
59
+ readonly errors: Array<PayloadError>,
60
+ readonly extensions?: PayloadExtensions,
61
+ readonly label?: string,
62
+ readonly path?: Array<string | number>,
63
63
  };
64
64
 
65
65
  export type GraphQLResponseWithExtensionsOnly = {
@@ -71,8 +71,8 @@ export type GraphQLResponseWithExtensionsOnly = {
71
71
  // since `data: null` is a *required* output if there was an error during
72
72
  // execution, but the inverse is not described in the sepc: `data: null`
73
73
  // does not necessarily indicate that there was an error.
74
- +data: null,
75
- +extensions: PayloadExtensions,
74
+ readonly data: null,
75
+ readonly extensions: PayloadExtensions,
76
76
  };
77
77
 
78
78
  export type GraphQLSingularResponse =
@@ -134,4 +134,4 @@ export type SubscribeFunction = (
134
134
  ) => RelayObservable<GraphQLResponse>;
135
135
 
136
136
  export type Uploadable = File | Blob;
137
- export type UploadableMap = {+[key: string]: Uploadable};
137
+ export type UploadableMap = {readonly [key: string]: Uploadable};
@@ -0,0 +1,197 @@
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
+ /**
9
+ * A Subscription object is returned from .subscribe(), which can be
10
+ * unsubscribed or checked to see if the resulting subscription has closed.
11
+ */
12
+ export interface Subscription {
13
+ unsubscribe(): void;
14
+ readonly closed: boolean;
15
+ }
16
+
17
+ /**
18
+ * An Observer is an object of optional callback functions provided to
19
+ * .subscribe(). Each callback function is invoked when that event occurs.
20
+ */
21
+ export interface Observer<T> {
22
+ readonly start?: ((subscription: Subscription) => void) | undefined;
23
+ readonly next?: ((value: T) => void) | undefined;
24
+ readonly error?: ((error: Error) => void) | undefined;
25
+ readonly complete?: (() => void) | undefined;
26
+ readonly unsubscribe?: ((subscription: Subscription) => void) | undefined;
27
+ }
28
+
29
+ /**
30
+ * A Sink is an object of methods provided by Observable during construction.
31
+ * The methods are to be called to trigger each event. It also contains a closed
32
+ * field to see if the resulting subscription has closed.
33
+ */
34
+ export interface Sink<T> {
35
+ next(value: T): void;
36
+ error(error: Error, isUncaughtThrownError?: boolean): void;
37
+ complete(): void;
38
+ readonly closed: boolean;
39
+ }
40
+
41
+ /**
42
+ * A Source is the required argument when constructing a new Observable. Similar
43
+ * to a Promise constructor, this is a function which is invoked with a Sink,
44
+ * and may return either a cleanup function or a Subscription instance (for use
45
+ * when composing Observables).
46
+ */
47
+ export type Source<T> = (sink: Sink<T>) => void | Subscription | (() => unknown);
48
+
49
+ /**
50
+ * A Subscribable is an interface describing any object which can be subscribed.
51
+ *
52
+ * Note: A sink may be passed directly to .subscribe() as its observer,
53
+ * allowing for easily composing Subscribables.
54
+ */
55
+ export interface Subscribable<T> {
56
+ subscribe(observer: Observer<T> | Sink<T>): Subscription;
57
+ }
58
+
59
+ export type ObservableFromValue<T> = Subscribable<T> | Promise<T> | T;
60
+
61
+ /**
62
+ * Limited implementation of ESObservable, providing the limited set of behavior
63
+ * Relay networking requires.
64
+ *
65
+ * Observables retain the benefit of callbacks which can be called
66
+ * synchronously, avoiding any UI jitter, while providing a compositional API,
67
+ * which simplifies logic and prevents mishandling of errors compared to
68
+ * the direct use of callback functions.
69
+ *
70
+ * ESObservable: https://github.com/tc39/proposal-observable
71
+ */
72
+ export class RelayObservable<T> implements Subscribable<T> {
73
+ // Use RelayObservable.create(source);
74
+ private constructor(source: never);
75
+
76
+ static create<V>(source: Source<V>): RelayObservable<V>;
77
+
78
+ /**
79
+ * When an emitted error event is not handled by an Observer, it is reported
80
+ * to the host environment (what the ESObservable spec refers to as
81
+ * "HostReportErrors()").
82
+ *
83
+ * The default implementation in development rethrows thrown errors, and
84
+ * logs emitted error events to the console, while in production does nothing
85
+ * (swallowing unhandled errors).
86
+ *
87
+ * Called during application initialization, this method allows
88
+ * application-specific handling of unhandled errors. Allowing, for example,
89
+ * integration with error logging or developer tools.
90
+ *
91
+ * A second parameter `isUncaughtThrownError` is true when the unhandled error
92
+ * was thrown within an Observer handler, and false when the unhandled error
93
+ * was an unhandled emitted event.
94
+ *
95
+ * - Uncaught thrown errors typically represent avoidable errors thrown from
96
+ * application code, which should be handled with a try/catch block, and
97
+ * usually have useful stack traces.
98
+ *
99
+ * - Unhandled emitted event errors typically represent unavoidable events in
100
+ * application flow such as network failure, and may not have useful
101
+ * stack traces.
102
+ */
103
+ static onUnhandledError(callback: (error: Error, isUncaughtThrownError: boolean) => void): void;
104
+
105
+ /**
106
+ * Accepts various kinds of data sources, and always returns a RelayObservable
107
+ * useful for accepting the result of a user-provided FetchFunction.
108
+ */
109
+ static from<V>(obj: ObservableFromValue<V>): RelayObservable<V>;
110
+
111
+ /**
112
+ * Similar to promise.catch(), observable.catch() handles error events, and
113
+ * provides an alternative observable to use in it's place.
114
+ *
115
+ * If the catch handler throws a new error, it will appear as an error event
116
+ * on the resulting Observable.
117
+ */
118
+ catch<U>(fn: (error: Error) => RelayObservable<U>): RelayObservable<T | U>;
119
+
120
+ /**
121
+ * Returns a new Observable which first yields values from this Observable,
122
+ * then yields values from the next Observable. This is useful for chaining
123
+ * together Observables of finite length.
124
+ */
125
+ concat<U>(next: RelayObservable<U>): RelayObservable<T | U>;
126
+
127
+ /**
128
+ * Returns a new Observable which returns the same values as this one, but
129
+ * modified so that the provided Observer is called to perform a side-effects
130
+ * for all events emitted by the source.
131
+ *
132
+ * Any errors that are thrown in the side-effect Observer are unhandled, and
133
+ * do not affect the source Observable or its Observer.
134
+ *
135
+ * This is useful for when debugging your Observables or performing other
136
+ * side-effects such as logging or performance monitoring.
137
+ */
138
+ do(observer: Observer<T>): RelayObservable<T>;
139
+
140
+ /**
141
+ * Returns a new Observable which returns the same values as this one, but
142
+ * modified so that the finally callback is performed after completion,
143
+ * whether normal or due to error or unsubscription.
144
+ *
145
+ * This is useful for cleanup such as resource finalization.
146
+ */
147
+ finally(fn: () => unknown): RelayObservable<T>;
148
+
149
+ /**
150
+ * Returns a new Observable which is identical to this one, unless this
151
+ * Observable completes before yielding any values, in which case the new
152
+ * Observable will yield the values from the alternate Observable.
153
+ *
154
+ * If this Observable does yield values, the alternate is never subscribed to.
155
+ *
156
+ * This is useful for scenarios where values may come from multiple sources
157
+ * which should be tried in order, i.e. from a cache before a network.
158
+ */
159
+ ifEmpty<U>(alternate: RelayObservable<U>): RelayObservable<T | U>;
160
+
161
+ /**
162
+ * Observable's primary API: returns an unsubscribable Subscription to the
163
+ * source of this Observable.
164
+ *
165
+ * Note: A sink may be passed directly to .subscribe() as its observer,
166
+ * allowing for easily composing Observables.
167
+ */
168
+ subscribe(observer: Observer<T> | Sink<T>): Subscription;
169
+
170
+ /**
171
+ * Returns a new Observerable where each value has been transformed by
172
+ * the mapping function.
173
+ */
174
+ map<U>(fn: (value: T) => U): RelayObservable<U>;
175
+
176
+ /**
177
+ * Returns a new Observable where each value is replaced with a new Observable
178
+ * by the mapping function, the results of which returned as a single
179
+ * merged Observable.
180
+ */
181
+ mergeMap<U>(fn: (value: T) => ObservableFromValue<U>): RelayObservable<U>;
182
+
183
+ /**
184
+ * Returns a new Observable which first mirrors this Observable, then when it
185
+ * completes, waits for `pollInterval` milliseconds before re-subscribing to
186
+ * this Observable again, looping in this manner until unsubscribed.
187
+ *
188
+ * The returned Observable never completes.
189
+ */
190
+ poll(pollInterval: number): RelayObservable<T>;
191
+
192
+ /**
193
+ * Returns a Promise which resolves when this Observable yields a first value
194
+ * or when it completes with no value.
195
+ */
196
+ toPromise(): Promise<T | undefined>;
197
+ }
@@ -18,14 +18,14 @@ const isPromise = require('../util/isPromise');
18
18
  * unsubscribed or checked to see if the resulting subscription has closed.
19
19
  */
20
20
  export type Subscription = {
21
- +unsubscribe: () => void,
22
- +closed: boolean,
21
+ readonly unsubscribe: () => void,
22
+ readonly closed: boolean,
23
23
  };
24
24
 
25
25
  type SubscriptionFn = {
26
26
  (): unknown,
27
- +unsubscribe?: void,
28
- +closed?: void,
27
+ readonly unsubscribe?: void,
28
+ readonly closed?: void,
29
29
  ...
30
30
  };
31
31
 
@@ -33,12 +33,12 @@ type SubscriptionFn = {
33
33
  * An Observer is an object of optional callback functions provided to
34
34
  * .subscribe(). Each callback function is invoked when that event occurs.
35
35
  */
36
- export type Observer<-T> = {
37
- +start?: ?(Subscription) => unknown,
38
- +next?: ?(T) => unknown,
39
- +error?: ?(Error) => unknown,
40
- +complete?: ?() => unknown,
41
- +unsubscribe?: ?(Subscription) => unknown,
36
+ export type Observer<in T> = {
37
+ readonly start?: ?(Subscription) => unknown,
38
+ readonly next?: ?(T) => unknown,
39
+ readonly error?: ?(Error) => unknown,
40
+ readonly complete?: ?() => unknown,
41
+ readonly unsubscribe?: ?(Subscription) => unknown,
42
42
  };
43
43
 
44
44
  /**
@@ -46,11 +46,11 @@ export type Observer<-T> = {
46
46
  * The methods are to be called to trigger each event. It also contains a closed
47
47
  * field to see if the resulting subscription has closed.
48
48
  */
49
- export type Sink<-T> = {
50
- +next: T => void,
51
- +error: (Error, isUncaughtThrownError?: boolean) => void,
52
- +complete: () => void,
53
- +closed: boolean,
49
+ export type Sink<in T> = {
50
+ readonly next: T => void,
51
+ readonly error: (Error, isUncaughtThrownError?: boolean) => void,
52
+ readonly complete: () => void,
53
+ readonly closed: boolean,
54
54
  };
55
55
 
56
56
  /**
@@ -59,7 +59,7 @@ export type Sink<-T> = {
59
59
  * and may return either a cleanup function or a Subscription instance (for use
60
60
  * when composing Observables).
61
61
  */
62
- export type Source<+T> = (Sink<T>) => void | Subscription | SubscriptionFn;
62
+ export type Source<out T> = (Sink<T>) => void | Subscription | SubscriptionFn;
63
63
 
64
64
  /**
65
65
  * A Subscribable is an interface describing any object which can be subscribed.
@@ -67,11 +67,11 @@ export type Source<+T> = (Sink<T>) => void | Subscription | SubscriptionFn;
67
67
  * Note: A sink may be passed directly to .subscribe() as its observer,
68
68
  * allowing for easily composing Subscribables.
69
69
  */
70
- export interface Subscribable<+T> {
70
+ export interface Subscribable<out T> {
71
71
  subscribe(observer: Observer<T> | Sink<T>): Subscription;
72
72
  }
73
73
 
74
- export type ObservableFromValue<+T> = Subscribable<T> | Promise<T> | T;
74
+ export type ObservableFromValue<out T> = Subscribable<T> | Promise<T> | T;
75
75
 
76
76
  let hostReportError:
77
77
  | ((Error, isUncaughtThrownError: boolean) => unknown)
@@ -88,8 +88,8 @@ let hostReportError:
88
88
  *
89
89
  * ESObservable: https://github.com/tc39/proposal-observable
90
90
  */
91
- class RelayObservable<+T> implements Subscribable<T> {
92
- +_source: Source<T>;
91
+ class RelayObservable<out T> implements Subscribable<T> {
92
+ readonly _source: Source<T>;
93
93
 
94
94
  static create<V>(source: Source<V>): RelayObservable<V> {
95
95
  return new RelayObservable(source as any);
@@ -491,7 +491,7 @@ function subscribe<T>(
491
491
  // Subscription objects below, however not all flow environments we expect
492
492
  // Relay to be used within will support property getters, and many minifier
493
493
  // tools still do not support ES5 syntax. Instead, we can use defineProperty.
494
- const withClosed: <O>(obj: O) => {...O, +closed: boolean} = (obj =>
494
+ const withClosed: <O>(obj: O) => {...O, readonly closed: boolean} = (obj =>
495
495
  Object.defineProperty(obj, 'closed', {get: () => closed} as any)) as any;
496
496
 
497
497
  function doCleanup() {
@@ -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 { GraphQLResponse } from '../network/RelayNetworkTypes';
9
+ import { Variables } from '../util/RelayRuntimeTypes';
10
+
11
+ export default class RelayQueryResponseCache {
12
+ constructor(config: { size: number; ttl: number });
13
+ clear(): void;
14
+ get(queryID: string, variables: Variables): GraphQLResponse | null;
15
+ set(queryID: string, variables: Variables, payload: GraphQLResponse): void;
16
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "relay-runtime",
3
3
  "description": "A core runtime for building GraphQL-driven applications.",
4
- "version": "21.0.0",
4
+ "version": "21.0.1",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"
@@ -0,0 +1,45 @@
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
+ ReaderFragment,
10
+ ReaderInlineDataFragment,
11
+ ReaderPaginationFragment,
12
+ ReaderRefetchableFragment,
13
+ } from '../util/ReaderNode';
14
+ import { ConcreteRequest } from '../util/RelayConcreteNode';
15
+
16
+ // The type of a graphql`...` tagged template expression.
17
+ export type GraphQLTaggedNode =
18
+ | ReaderFragment
19
+ | ConcreteRequest
20
+ | ReaderInlineDataFragment
21
+ | (() => ReaderFragment | ConcreteRequest | ReaderInlineDataFragment);
22
+
23
+ /**
24
+ * Runtime function to correspond to the `graphql` tagged template function.
25
+ * All calls to this function should be transformed by the plugin.
26
+ */
27
+ export function graphql(strings: unknown): GraphQLTaggedNode;
28
+
29
+ export function getNode(taggedNode: unknown): unknown;
30
+
31
+ export function isFragment(node: GraphQLTaggedNode): boolean;
32
+
33
+ export function isRequest(node: GraphQLTaggedNode): boolean;
34
+
35
+ export function isInlineDataFragment(node: GraphQLTaggedNode): boolean;
36
+
37
+ export function getFragment(taggedNode: GraphQLTaggedNode): ReaderFragment;
38
+
39
+ export function getPaginationFragment(taggedNode: GraphQLTaggedNode): ReaderPaginationFragment | null;
40
+
41
+ export function getRefetchableFragment(taggedNode: GraphQLTaggedNode): ReaderRefetchableFragment | null;
42
+
43
+ export function getRequest(taggedNode: GraphQLTaggedNode): ConcreteRequest;
44
+
45
+ export function getInlineDataFragment(taggedNode: GraphQLTaggedNode): ReaderInlineDataFragment;
@@ -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 { RelayObservable } from '../network/RelayObservable';
9
+ import { Environment } from '../store/RelayStoreTypes';
10
+ import {CacheConfig, FetchQueryFetchPolicy, OperationType} from '../util/RelayRuntimeTypes';
11
+ import { GraphQLTaggedNode } from './GraphQLTag';
12
+
13
+ export function fetchQuery<T extends OperationType>(
14
+ environment: Environment,
15
+ taggedNode: GraphQLTaggedNode,
16
+ variables: T['variables'],
17
+ cacheConfig?: {
18
+ networkCacheConfig?: CacheConfig | null | undefined;
19
+ fetchPolicy?: FetchQueryFetchPolicy | null | undefined;
20
+ } | null,
21
+ ): RelayObservable<T['response']>;
@@ -0,0 +1,26 @@
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 { GraphQLResponse } from '../network/RelayNetworkTypes';
9
+ import { RelayObservable as Observable } from '../network/RelayObservable';
10
+ import {Environment, OperationDescriptor, RequestDescriptor} from '../store/RelayStoreTypes';
11
+ import { RequestIdentifier } from '../util/getRequestIdentifier';
12
+
13
+ export function fetchQuery(environment: Environment, operation: OperationDescriptor): Observable<GraphQLResponse>;
14
+
15
+ export function fetchQueryDeduped(
16
+ environment: Environment,
17
+ identifier: RequestIdentifier,
18
+ fetchFn: () => Observable<GraphQLResponse>,
19
+ ): Observable<GraphQLResponse>;
20
+
21
+ export function getPromiseForActiveRequest(environment: Environment, request: RequestDescriptor): Promise<void> | null;
22
+
23
+ export function getObservableForActiveRequest(
24
+ environment: Environment,
25
+ request: RequestDescriptor,
26
+ ): Observable<void> | null;
@@ -25,10 +25,10 @@ const RelayReplaySubject = require('../util/RelayReplaySubject');
25
25
  const invariant = require('invariant');
26
26
 
27
27
  type RequestCacheEntry = {
28
- +identifier: RequestIdentifier,
29
- +subject: RelayReplaySubject<GraphQLResponse>,
30
- +subjectForInFlightStatus: RelayReplaySubject<GraphQLResponse>,
31
- +subscription: Subscription,
28
+ readonly identifier: RequestIdentifier,
29
+ readonly subject: RelayReplaySubject<GraphQLResponse>,
30
+ readonly subjectForInFlightStatus: RelayReplaySubject<GraphQLResponse>,
31
+ readonly subscription: Subscription,
32
32
  promise: ?Promise<void>,
33
33
  };
34
34
 
@@ -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 { Environment } from '../store/RelayStoreTypes';
9
+ import {CacheConfig, OperationType} from '../util/RelayRuntimeTypes';
10
+ import { GraphQLTaggedNode } from './GraphQLTag';
11
+
12
+ export function fetchQuery_DEPRECATED<T extends OperationType>(
13
+ environment: Environment,
14
+ taggedNode: GraphQLTaggedNode,
15
+ variables: T['variables'],
16
+ cacheConfig?: CacheConfig | null,
17
+ ): Promise<T['response']>;
@@ -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 { DataID } from '../util/RelayRuntimeTypes';
9
+
10
+ export function generateClientID(id: DataID, storageKey: string, index?: number): DataID;
11
+
12
+ export function isClientID(id: DataID): boolean;
13
+
14
+ export function generateUniqueClientID(): DataID;