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.
- package/experimental.d.ts +34 -0
- package/experimental.js +1 -1
- package/experimental.js.flow +4 -4
- package/handlers/RelayDefaultHandlerProvider.d.ts +12 -0
- package/handlers/connection/ConnectionHandler.d.ts +51 -0
- package/handlers/connection/ConnectionInterface.d.ts +40 -0
- package/handlers/connection/MutationHandlers.d.ts +17 -0
- package/index.d.ts +274 -0
- package/index.js +1 -1
- package/llm-docs/api-reference/relay-runtime/fetch-query.mdx +5 -0
- package/llm-docs/getting-started/compiler.mdx +19 -3
- package/llm-docs/getting-started/quick-start.mdx +15 -12
- package/llm-docs/guides/codemods.mdx +14 -1
- package/multi-actor-environment/ActorIdentifier.d.ts +17 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +9 -9
- package/multi-actor-environment/MultiActorEnvironment.d.ts +123 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +22 -18
- package/multi-actor-environment/MultiActorEnvironmentTypes.d.ts +225 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +3 -3
- package/multi-actor-environment/index.d.ts +14 -0
- package/multi-actor-environment.d.ts +8 -0
- package/mutations/RelayDeclarativeMutationConfig.d.ts +70 -0
- package/mutations/applyOptimisticMutation.d.ts +25 -0
- package/mutations/commitLocalUpdate.d.ts +10 -0
- package/mutations/commitMutation.d.ts +48 -0
- package/mutations/commitMutation.js.flow +1 -1
- package/network/RelayNetwork.d.ts +12 -0
- package/network/RelayNetworkTypes.d.ts +145 -0
- package/network/RelayNetworkTypes.js.flow +15 -15
- package/network/RelayObservable.d.ts +197 -0
- package/network/RelayObservable.js.flow +21 -21
- package/network/RelayQueryResponseCache.d.ts +16 -0
- package/package.json +1 -1
- package/query/GraphQLTag.d.ts +45 -0
- package/query/fetchQuery.d.ts +21 -0
- package/query/fetchQueryInternal.d.ts +26 -0
- package/query/fetchQueryInternal.js.flow +4 -4
- package/query/fetchQuery_DEPRECATED.d.ts +17 -0
- package/store/ClientID.d.ts +14 -0
- package/store/DataChecker.js.flow +8 -6
- package/store/NormalizationEngine.js.flow +4 -1
- package/store/OperationExecutor.d.ts +51 -0
- package/store/OperationExecutor.js.flow +33 -30
- package/store/RelayModernEnvironment.d.ts +97 -0
- package/store/RelayModernEnvironment.js.flow +21 -21
- package/store/RelayModernOperationDescriptor.d.ts +28 -0
- package/store/RelayModernRecord.d.ts +92 -0
- package/store/RelayModernSelector.d.ts +123 -0
- package/store/RelayModernStore.d.ts +57 -0
- package/store/RelayOperationTracker.d.ts +29 -0
- package/store/RelayPublishQueue.js.flow +8 -8
- package/store/RelayRecordSource.d.ts +26 -0
- package/store/RelayRecordState.d.ts +28 -0
- package/store/RelayResponseNormalizer.d.ts +28 -0
- package/store/RelayResponseNormalizer.js.flow +8 -8
- package/store/RelayStoreTypes.d.ts +1327 -0
- package/store/RelayStoreTypes.js.flow +284 -280
- package/store/RelayStoreUtils.d.ts +86 -0
- package/store/RelayStoreUtils.js.flow +2 -2
- package/store/ResolverFragments.d.ts +43 -0
- package/store/ResolverFragments.js.flow +14 -6
- package/store/StoreInspector.js.flow +2 -2
- package/store/ViewerPattern.d.ts +11 -0
- package/store/createFragmentSpecResolver.d.ts +16 -0
- package/store/defaultGetDataID.js.flow +1 -1
- package/store/isRelayModernEnvironment.d.ts +8 -0
- package/store/live-resolvers/LiveResolverCache.js.flow +1 -1
- package/store/live-resolvers/resolverDataInjector.d.ts +27 -0
- package/store/observeFragmentExperimental.d.ts +46 -0
- package/store/observeFragmentExperimental.js.flow +1 -1
- package/store/observeQueryExperimental.d.ts +30 -0
- package/store/readInlineData.d.ts +19 -0
- package/store/readInlineData.js.flow +1 -1
- package/store/waitForFragmentExperimental.d.ts +49 -0
- package/subscription/requestSubscription.d.ts +27 -0
- package/subscription/requestSubscription.js.flow +3 -3
- package/util/JSResourceTypes.flow.js.flow +4 -4
- package/util/NormalizationNode.d.ts +235 -0
- package/util/NormalizationNode.js.flow +124 -122
- package/util/ReaderNode.d.ts +264 -0
- package/util/ReaderNode.js.flow +152 -149
- package/util/RelayConcreteNode.d.ts +120 -0
- package/util/RelayConcreteNode.js.flow +31 -31
- package/util/RelayError.d.ts +13 -0
- package/util/RelayFeatureFlags.d.ts +40 -0
- package/util/RelayProfiler.d.ts +121 -0
- package/util/RelayReplaySubject.d.ts +25 -0
- package/util/RelayRuntimeTypes.d.ts +59 -0
- package/util/RelayRuntimeTypes.js.flow +33 -30
- package/util/createPayloadFor3DField.d.ts +17 -0
- package/util/createPayloadFor3DField.js.flow +4 -4
- package/util/deepFreeze.d.ts +8 -0
- package/util/getFragmentIdentifier.d.ts +10 -0
- package/util/getPaginationMetadata.d.ts +20 -0
- package/util/getPaginationVariables.d.ts +20 -0
- package/util/getPendingOperationsForFragment.d.ts +18 -0
- package/util/getRefetchMetadata.d.ts +19 -0
- package/util/getRelayHandleKey.d.ts +8 -0
- package/util/getRequestIdentifier.d.ts +17 -0
- package/util/getValueAtPath.d.ts +8 -0
- package/util/handlePotentialSnapshotErrors.d.ts +14 -0
- package/util/isEmptyObject.js.flow +1 -1
- package/util/isPromise.d.ts +8 -0
- package/util/isScalarAndEqual.d.ts +8 -0
- package/util/recycleNodesInto.d.ts +8 -0
- package/util/stableCopy.d.ts +8 -0
- package/util/withProvidedVariables.d.ts +19 -0
|
@@ -0,0 +1,1327 @@
|
|
|
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 { MutationParameters } from '../mutations/commitMutation';
|
|
9
|
+
import {
|
|
10
|
+
GraphQLResponse,
|
|
11
|
+
Network,
|
|
12
|
+
PayloadData,
|
|
13
|
+
PayloadError,
|
|
14
|
+
ReactFlightServerTree,
|
|
15
|
+
UploadableMap,
|
|
16
|
+
} from '../network/RelayNetworkTypes';
|
|
17
|
+
import { RelayObservable } from '../network/RelayObservable';
|
|
18
|
+
import { GraphQLTaggedNode } from '../query/GraphQLTag';
|
|
19
|
+
import { RequestIdentifier } from '../util/getRequestIdentifier';
|
|
20
|
+
import {
|
|
21
|
+
NormalizationLinkedField,
|
|
22
|
+
NormalizationScalarField,
|
|
23
|
+
NormalizationSelectableNode,
|
|
24
|
+
NormalizationSplitOperation,
|
|
25
|
+
} from '../util/NormalizationNode';
|
|
26
|
+
import {ReaderFragment, ReaderLinkedField} from '../util/ReaderNode';
|
|
27
|
+
import {ConcreteRequest, RequestParameters} from '../util/RelayConcreteNode';
|
|
28
|
+
import {
|
|
29
|
+
CacheConfig,
|
|
30
|
+
DataID,
|
|
31
|
+
Disposable,
|
|
32
|
+
OperationType,
|
|
33
|
+
RenderPolicy,
|
|
34
|
+
Variables,
|
|
35
|
+
VariablesOf,
|
|
36
|
+
} from '../util/RelayRuntimeTypes';
|
|
37
|
+
import { InvalidationState } from './RelayModernStore';
|
|
38
|
+
import { RelayOperationTracker } from './RelayOperationTracker';
|
|
39
|
+
import { RecordState } from './RelayRecordState';
|
|
40
|
+
|
|
41
|
+
export type FragmentType = unknown;
|
|
42
|
+
export type OperationTracker = RelayOperationTracker;
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* An individual cached graph object.
|
|
46
|
+
*/
|
|
47
|
+
export interface Record<T extends object = Record<string, unknown>> {
|
|
48
|
+
[key: string]: T;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A collection of records keyed by id.
|
|
53
|
+
*/
|
|
54
|
+
export interface RecordMap {
|
|
55
|
+
// theoretically, this should be `[dataID: DataID]`, but `DataID` is a string.
|
|
56
|
+
[dataID: string]: Record | null | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface FragmentMap {
|
|
60
|
+
[key: string]: ReaderFragment;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The results of a selector given a store/RecordSource.
|
|
65
|
+
*/
|
|
66
|
+
export interface SelectorData {
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface SingularReaderSelector {
|
|
71
|
+
readonly kind: 'SingularReaderSelector';
|
|
72
|
+
readonly dataID: DataID;
|
|
73
|
+
readonly isWithinUnmatchedTypeRefinement: boolean;
|
|
74
|
+
readonly node: ReaderFragment;
|
|
75
|
+
readonly owner: RequestDescriptor;
|
|
76
|
+
readonly variables: Variables;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type ReaderSelector = SingularReaderSelector | PluralReaderSelector;
|
|
80
|
+
|
|
81
|
+
export interface PluralReaderSelector {
|
|
82
|
+
readonly kind: 'PluralReaderSelector';
|
|
83
|
+
readonly selectors: readonly SingularReaderSelector[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface RequestDescriptor {
|
|
87
|
+
readonly identifier: RequestIdentifier;
|
|
88
|
+
readonly node: ConcreteRequest;
|
|
89
|
+
readonly variables: Variables;
|
|
90
|
+
readonly cacheConfig: CacheConfig | null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A selector defines the starting point for a traversal into the graph for the
|
|
95
|
+
* purposes of targeting a subgraph.
|
|
96
|
+
*/
|
|
97
|
+
export interface NormalizationSelector {
|
|
98
|
+
readonly dataID: DataID;
|
|
99
|
+
readonly node: NormalizationSelectableNode;
|
|
100
|
+
readonly variables: Variables;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A representation of a selector and its results at a particular point in time.
|
|
105
|
+
*/
|
|
106
|
+
export interface TypedSnapshot<TData> {
|
|
107
|
+
readonly data: TData;
|
|
108
|
+
readonly isMissingData: boolean;
|
|
109
|
+
readonly seenRecords: RecordMap;
|
|
110
|
+
readonly selector: SingularReaderSelector;
|
|
111
|
+
}
|
|
112
|
+
export type Snapshot = TypedSnapshot<SelectorData>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* An operation selector describes a specific instance of a GraphQL operation
|
|
116
|
+
* with variables applied.
|
|
117
|
+
*
|
|
118
|
+
* - `root`: a selector intended for processing server results or retaining
|
|
119
|
+
* response data in the store.
|
|
120
|
+
* - `fragment`: a selector intended for use in reading or subscribing to
|
|
121
|
+
* the results of the the operation.
|
|
122
|
+
*/
|
|
123
|
+
export interface OperationDescriptor {
|
|
124
|
+
readonly fragment: SingularReaderSelector;
|
|
125
|
+
readonly request: RequestDescriptor;
|
|
126
|
+
readonly root: NormalizationSelector;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Arbitrary data e.g. received by a container as props.
|
|
131
|
+
*/
|
|
132
|
+
export interface Props {
|
|
133
|
+
[key: string]: unknown;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The type of the `relay` property set on React context by the React/Relay
|
|
138
|
+
* integration layer (e.g. QueryRenderer, FragmentContainer, etc).
|
|
139
|
+
*/
|
|
140
|
+
export interface RelayContext {
|
|
141
|
+
environment: Environment;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The results of reading the results of a FragmentMap given some input
|
|
146
|
+
* `Props`.
|
|
147
|
+
*/
|
|
148
|
+
export interface FragmentSpecResults {
|
|
149
|
+
[key: string]: unknown;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A utility for resolving and subscribing to the results of a fragment spec
|
|
154
|
+
* (key -> fragment mapping) given some "props" that determine the root ID
|
|
155
|
+
* and variables to use when reading each fragment. When props are changed via
|
|
156
|
+
* `setProps()`, the resolver will update its results and subscriptions
|
|
157
|
+
* accordingly. Internally, the resolver:
|
|
158
|
+
* - Converts the fragment map & props map into a map of `Selector`s.
|
|
159
|
+
* - Removes any resolvers for any props that became null.
|
|
160
|
+
* - Creates resolvers for any props that became non-null.
|
|
161
|
+
* - Updates resolvers with the latest props.
|
|
162
|
+
*/
|
|
163
|
+
export interface FragmentSpecResolver {
|
|
164
|
+
/**
|
|
165
|
+
* Stop watching for changes to the results of the fragments.
|
|
166
|
+
*/
|
|
167
|
+
dispose(): void;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get the current results.
|
|
171
|
+
*/
|
|
172
|
+
resolve(): FragmentSpecResults;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Update the resolver with new inputs. Call `resolve()` to get the updated
|
|
176
|
+
* results.
|
|
177
|
+
*/
|
|
178
|
+
setProps(props: Props): void;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Override the variables used to read the results of the fragments. Call
|
|
182
|
+
* `resolve()` to get the updated results.
|
|
183
|
+
*/
|
|
184
|
+
setVariables(variables: Variables, node: ConcreteRequest): void;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Subscribe to resolver updates.
|
|
188
|
+
* Overrides existing callback (if one has been specified).
|
|
189
|
+
*/
|
|
190
|
+
setCallback(callback: () => void): void;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A read-only interface for accessing cached graph data.
|
|
195
|
+
*/
|
|
196
|
+
export interface RecordSource {
|
|
197
|
+
get<T extends object = Record<string, unknown>>(dataID: DataID): Record<T> | null | undefined;
|
|
198
|
+
getRecordIDs(): DataID[];
|
|
199
|
+
getStatus(dataID: DataID): RecordState;
|
|
200
|
+
has(dataID: DataID): boolean;
|
|
201
|
+
size(): number;
|
|
202
|
+
toJSON(): { [key: string]: Record };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* A read/write interface for accessing and updating graph data.
|
|
207
|
+
*/
|
|
208
|
+
export interface MutableRecordSource extends RecordSource {
|
|
209
|
+
clear(): void;
|
|
210
|
+
delete(dataID: DataID): void;
|
|
211
|
+
remove(dataID: DataID): void;
|
|
212
|
+
set(dataID: DataID, record: Record): void;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface CheckOptions {
|
|
216
|
+
target: MutableRecordSource;
|
|
217
|
+
handlers: readonly MissingFieldHandler[];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export type OperationAvailability =
|
|
221
|
+
| {
|
|
222
|
+
status: 'available';
|
|
223
|
+
fetchTime: number | null | undefined;
|
|
224
|
+
}
|
|
225
|
+
| { status: 'stale' }
|
|
226
|
+
| { status: 'missing' };
|
|
227
|
+
|
|
228
|
+
export { InvalidationState } from './RelayModernStore';
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* An interface for keeping multiple views of data consistent across an
|
|
232
|
+
* application.
|
|
233
|
+
*/
|
|
234
|
+
export interface Store {
|
|
235
|
+
/**
|
|
236
|
+
* Get a read-only view of the store's internal RecordSource.
|
|
237
|
+
*/
|
|
238
|
+
getSource(): RecordSource;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Determine if the operation can be resolved with data in the store (i.e. no
|
|
242
|
+
* fields are missing).
|
|
243
|
+
*/
|
|
244
|
+
check(operation: OperationDescriptor, options?: CheckOptions): OperationAvailability;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Read the results of a selector from in-memory records in the store.
|
|
248
|
+
* Optionally takes an owner, corresponding to the operation that
|
|
249
|
+
* owns this selector (fragment).
|
|
250
|
+
*/
|
|
251
|
+
lookup(selector: SingularReaderSelector): Snapshot;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Notify subscribers (see `subscribe`) of any data that was published
|
|
255
|
+
* (`publish()`) since the last time `notify` was called.
|
|
256
|
+
* Optionally provide an OperationDescriptor indicating the source operation
|
|
257
|
+
* that was being processed to produce this run.
|
|
258
|
+
*
|
|
259
|
+
* This method should return an array of the affected fragment owners
|
|
260
|
+
*/
|
|
261
|
+
notify(sourceOperation?: OperationDescriptor, invalidateStore?: boolean): readonly RequestDescriptor[];
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Publish new information (e.g. from the network) to the store, updating its
|
|
265
|
+
* internal record source. Subscribers are not immediately notified - this
|
|
266
|
+
* occurs when `notify()` is called.
|
|
267
|
+
*/
|
|
268
|
+
publish(source: RecordSource, idsMarkedForInvalidation?: DataIDSet): void;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Ensure that all the records necessary to fulfill the given selector are
|
|
272
|
+
* retained in-memory. The records will not be eligible for garbage collection
|
|
273
|
+
* until the returned reference is disposed.
|
|
274
|
+
*/
|
|
275
|
+
retain(operation: OperationDescriptor): Disposable;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Subscribe to changes to the results of a selector. The callback is called
|
|
279
|
+
* when `notify()` is called *and* records have been published that affect the
|
|
280
|
+
* selector results relative to the last `notify()`.
|
|
281
|
+
*/
|
|
282
|
+
subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The method should disable garbage collection until
|
|
286
|
+
* the returned reference is disposed.
|
|
287
|
+
*/
|
|
288
|
+
holdGC(): Disposable;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Record a backup/snapshot of the current state of the store, including
|
|
292
|
+
* records and derived data such as fragment and connection subscriptions.
|
|
293
|
+
* This state can be restored with restore().
|
|
294
|
+
*/
|
|
295
|
+
snapshot(): void;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Reset the state of the store to the point that snapshot() was last called.
|
|
299
|
+
*/
|
|
300
|
+
restore(): void;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Will return an opaque snapshot of the current invalidation state of
|
|
304
|
+
* the data ids that were provided.
|
|
305
|
+
*/
|
|
306
|
+
lookupInvalidationState(dataIDs: readonly DataID[]): InvalidationState;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Given the previous invalidation state for those
|
|
310
|
+
* ids, this function will return:
|
|
311
|
+
* - false, if the invalidation state for those ids is the same, meaning
|
|
312
|
+
* **it has not changed**
|
|
313
|
+
* - true, if the invalidation state for the given ids has changed
|
|
314
|
+
*/
|
|
315
|
+
checkInvalidationState(previousInvalidationState: InvalidationState): boolean;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Will subscribe the provided callback to the invalidation state of the
|
|
319
|
+
* given data ids. Whenever the invalidation state for any of the provided
|
|
320
|
+
* ids changes, the callback will be called, and provide the latest
|
|
321
|
+
* invalidation state.
|
|
322
|
+
* Disposing of the returned disposable will remove the subscription.
|
|
323
|
+
*/
|
|
324
|
+
subscribeToInvalidationState(invalidationState: InvalidationState, callback: () => void): Disposable;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* A type that accepts a callback and schedules it to run at some future time.
|
|
329
|
+
* By convention, implementations should not execute the callback immediately.
|
|
330
|
+
*/
|
|
331
|
+
export type Scheduler = (callback: () => void) => void;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* An interface for imperatively getting/setting properties of a `Record`. This interface
|
|
335
|
+
* is designed to allow the appearance of direct Record manipulation while
|
|
336
|
+
* allowing different implementations that may e.g. create a changeset of
|
|
337
|
+
* the modifications.
|
|
338
|
+
*/
|
|
339
|
+
export type Unarray<T> = T extends Array<infer U> | ReadonlyArray<infer U> ? U : T;
|
|
340
|
+
export type Primitive = string | number | boolean | null | undefined;
|
|
341
|
+
|
|
342
|
+
export interface RecordProxy<T = Record<string, unknown>> {
|
|
343
|
+
copyFieldsFrom(source: RecordProxy): void;
|
|
344
|
+
getDataID(): DataID;
|
|
345
|
+
// If a parent type is provided, provide the child type
|
|
346
|
+
getLinkedRecord<K extends keyof T>(name: K, args?: Variables | null): RecordProxy<NonNullable<T[K]>>;
|
|
347
|
+
// If a hint is provided, the return value is guaranteed to be the hint type
|
|
348
|
+
getLinkedRecord<H = never>(
|
|
349
|
+
name: string,
|
|
350
|
+
args?: Variables | null,
|
|
351
|
+
): [H] extends [never] ? RecordProxy | null : RecordProxy<H>;
|
|
352
|
+
getLinkedRecords<K extends keyof T>(
|
|
353
|
+
name: K,
|
|
354
|
+
args?: Variables | null,
|
|
355
|
+
): Array<RecordProxy<Unarray<NonNullable<T[K]>>>>;
|
|
356
|
+
getLinkedRecords<H = never>(
|
|
357
|
+
name: string,
|
|
358
|
+
args?: Variables | null,
|
|
359
|
+
): [H] extends [never] ? RecordProxy[] | null
|
|
360
|
+
: NonNullable<H> extends Array<infer U> ? Array<RecordProxy<U>> | (H extends null ? null : never)
|
|
361
|
+
: never;
|
|
362
|
+
getOrCreateLinkedRecord<K extends keyof T>(
|
|
363
|
+
name: K,
|
|
364
|
+
typeName: string,
|
|
365
|
+
args?: Variables | null,
|
|
366
|
+
): RecordProxy<NonNullable<T[K]>>;
|
|
367
|
+
getOrCreateLinkedRecord(name: string, typeName: string, args?: Variables | null): RecordProxy<T>;
|
|
368
|
+
getType(): string;
|
|
369
|
+
getValue<K extends keyof T>(name: K, args?: Variables | null): T[K];
|
|
370
|
+
getValue(name: string, args?: Variables | null): Primitive | Primitive[];
|
|
371
|
+
setLinkedRecord<K extends keyof T>(
|
|
372
|
+
record: RecordProxy<T[K]> | null,
|
|
373
|
+
name: K,
|
|
374
|
+
args?: Variables | null,
|
|
375
|
+
): RecordProxy<T>;
|
|
376
|
+
setLinkedRecord(record: RecordProxy | null, name: string, args?: Variables | null): RecordProxy;
|
|
377
|
+
setLinkedRecords<K extends keyof T>(
|
|
378
|
+
records: Array<RecordProxy<Unarray<T[K]>> | null> | null | undefined,
|
|
379
|
+
name: K,
|
|
380
|
+
args?: Variables | null,
|
|
381
|
+
): RecordProxy<T>;
|
|
382
|
+
setLinkedRecords(
|
|
383
|
+
records: Array<RecordProxy | null> | null | undefined,
|
|
384
|
+
name: string,
|
|
385
|
+
args?: Variables | null,
|
|
386
|
+
): RecordProxy<T>;
|
|
387
|
+
setValue<K extends keyof T>(value: T[K], name: K, args?: Variables | null): RecordProxy<T>;
|
|
388
|
+
setValue(value: Primitive | Primitive[], name: string, args?: Variables | null): RecordProxy;
|
|
389
|
+
invalidateRecord(): void;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface ReadOnlyRecordProxy {
|
|
393
|
+
getDataID(): DataID;
|
|
394
|
+
getLinkedRecord(name: string, args?: Variables): RecordProxy | null | undefined;
|
|
395
|
+
getLinkedRecords(name: string, args?: Variables): Array<RecordProxy | null | undefined> | null | undefined;
|
|
396
|
+
getType(): string;
|
|
397
|
+
getValue(name: string, args?: Variables | null): unknown;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* An interface for imperatively getting/setting properties of a `RecordSource`. This interface
|
|
402
|
+
* is designed to allow the appearance of direct RecordSource manipulation while
|
|
403
|
+
* allowing different implementations that may e.g. create a changeset of
|
|
404
|
+
* the modifications.
|
|
405
|
+
*/
|
|
406
|
+
|
|
407
|
+
export interface RecordSourceProxy {
|
|
408
|
+
create(dataID: DataID, typeName: string): RecordProxy;
|
|
409
|
+
delete(dataID: DataID): void;
|
|
410
|
+
get<T = Record<string, unknown>>(dataID: DataID): RecordProxy<T> | null | undefined;
|
|
411
|
+
getRoot(): RecordProxy;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export interface ReadOnlyRecordSourceProxy {
|
|
415
|
+
get(dataID: DataID): ReadOnlyRecordProxy | null | undefined;
|
|
416
|
+
getRoot(): ReadOnlyRecordProxy;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Extends the RecordSourceProxy interface with methods for accessing the root
|
|
421
|
+
* fields of a Selector.
|
|
422
|
+
*/
|
|
423
|
+
|
|
424
|
+
export interface RecordSourceSelectorProxy<T = Record<string, unknown>> extends RecordSourceProxy {
|
|
425
|
+
getRootField<K extends keyof T>(fieldName: K): RecordProxy<NonNullable<T[K]>>;
|
|
426
|
+
getRootField(fieldName: string): RecordProxy | null;
|
|
427
|
+
getPluralRootField(fieldName: string): Array<RecordProxy<T> | null> | null;
|
|
428
|
+
invalidateStore(): void;
|
|
429
|
+
readUpdatableQuery<TQuery extends OperationType>(
|
|
430
|
+
gqlQuery: GraphQLTaggedNode,
|
|
431
|
+
variables: VariablesOf<TQuery>,
|
|
432
|
+
): UpdatableQueryData<TQuery>;
|
|
433
|
+
readUpdatableFragment<TKey extends HasUpdatableSpread>(
|
|
434
|
+
fragmentInput: GraphQLTaggedNode,
|
|
435
|
+
fragmentRef: TKey,
|
|
436
|
+
): UpdatableFragmentData<TKey>;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export type LogEvent =
|
|
440
|
+
| Readonly<{
|
|
441
|
+
name: 'suspense.fragment';
|
|
442
|
+
data: unknown;
|
|
443
|
+
fragment: ReaderFragment;
|
|
444
|
+
isRelayHooks: boolean;
|
|
445
|
+
isMissingData: boolean;
|
|
446
|
+
isPromiseCached: boolean;
|
|
447
|
+
pendingOperations: readonly RequestDescriptor[];
|
|
448
|
+
}>
|
|
449
|
+
| Readonly<{
|
|
450
|
+
name: 'suspense.query';
|
|
451
|
+
fetchPolicy: string;
|
|
452
|
+
isPromiseCached: boolean;
|
|
453
|
+
operation: OperationDescriptor;
|
|
454
|
+
queryAvailability?: OperationAvailability | undefined;
|
|
455
|
+
renderPolicy: RenderPolicy;
|
|
456
|
+
}>
|
|
457
|
+
| Readonly<{
|
|
458
|
+
name: 'queryresource.fetch';
|
|
459
|
+
/**
|
|
460
|
+
* ID of this query resource request and will be the same if there is an associated queryresource.retain event.
|
|
461
|
+
*/
|
|
462
|
+
resourceID: number;
|
|
463
|
+
operation: OperationDescriptor;
|
|
464
|
+
// value from ProfilerContext
|
|
465
|
+
profilerContext: unknown;
|
|
466
|
+
// FetchPolicy from Relay Hooks
|
|
467
|
+
fetchPolicy: string;
|
|
468
|
+
// RenderPolicy from Relay Hooks
|
|
469
|
+
renderPolicy: RenderPolicy;
|
|
470
|
+
queryAvailability: OperationAvailability;
|
|
471
|
+
shouldFetch: boolean;
|
|
472
|
+
}>
|
|
473
|
+
| Readonly<{
|
|
474
|
+
name: 'queryresource.retain';
|
|
475
|
+
resourceID: number;
|
|
476
|
+
// value from ProfilerContext
|
|
477
|
+
profilerContext: unknown;
|
|
478
|
+
}>
|
|
479
|
+
| Readonly<{
|
|
480
|
+
// Indicates FragmentResource is going to return a result that is missing data.
|
|
481
|
+
name: 'fragmentresource.missing_data';
|
|
482
|
+
data: unknown;
|
|
483
|
+
fragment: ReaderFragment;
|
|
484
|
+
isRelayHooks: boolean;
|
|
485
|
+
// Are we reading this result from the fragment resource cache?
|
|
486
|
+
cached: boolean;
|
|
487
|
+
}>
|
|
488
|
+
| Readonly<{
|
|
489
|
+
/**
|
|
490
|
+
* Indicates getPendingOperationForFragment identified a pending operation.
|
|
491
|
+
* Useful for measuring how frequently RelayOperationTracker identifies a related operation on which to suspend.
|
|
492
|
+
*/
|
|
493
|
+
name: 'pendingoperation.found';
|
|
494
|
+
fragment: ReaderFragment;
|
|
495
|
+
fragmentOwner: RequestDescriptor;
|
|
496
|
+
pendingOperations: ReadonlyArray<RequestDescriptor>;
|
|
497
|
+
}>
|
|
498
|
+
| Readonly<{
|
|
499
|
+
name: 'network.info';
|
|
500
|
+
networkRequestId: number;
|
|
501
|
+
info: unknown;
|
|
502
|
+
}>
|
|
503
|
+
| Readonly<{
|
|
504
|
+
name: 'network.start';
|
|
505
|
+
networkRequestId: number;
|
|
506
|
+
params: RequestParameters;
|
|
507
|
+
variables: Variables;
|
|
508
|
+
cacheConfig: CacheConfig;
|
|
509
|
+
}>
|
|
510
|
+
| Readonly<{
|
|
511
|
+
name: 'network.next';
|
|
512
|
+
networkRequestId: number;
|
|
513
|
+
response: GraphQLResponse;
|
|
514
|
+
}>
|
|
515
|
+
| Readonly<{
|
|
516
|
+
name: 'network.error';
|
|
517
|
+
networkRequestId: number;
|
|
518
|
+
error: Error;
|
|
519
|
+
}>
|
|
520
|
+
| Readonly<{
|
|
521
|
+
name: 'network.complete';
|
|
522
|
+
networkRequestId: number;
|
|
523
|
+
}>
|
|
524
|
+
| Readonly<{
|
|
525
|
+
name: 'network.unsubscribe';
|
|
526
|
+
networkRequestId: number;
|
|
527
|
+
}>
|
|
528
|
+
| Readonly<{
|
|
529
|
+
name: 'execute.start';
|
|
530
|
+
executeId: number;
|
|
531
|
+
params: RequestParameters;
|
|
532
|
+
variables: Variables;
|
|
533
|
+
cacheConfig: CacheConfig;
|
|
534
|
+
}>
|
|
535
|
+
| Readonly<{
|
|
536
|
+
name: 'execute.next.start';
|
|
537
|
+
executeId: number;
|
|
538
|
+
response: GraphQLResponse;
|
|
539
|
+
operation: OperationDescriptor;
|
|
540
|
+
}>
|
|
541
|
+
| Readonly<{
|
|
542
|
+
name: 'execute.next.end';
|
|
543
|
+
executeId: number;
|
|
544
|
+
response: GraphQLResponse;
|
|
545
|
+
operation: OperationDescriptor;
|
|
546
|
+
}>
|
|
547
|
+
| Readonly<{
|
|
548
|
+
name: 'execute.async.module';
|
|
549
|
+
executeId: number;
|
|
550
|
+
operationName: string;
|
|
551
|
+
duration: number;
|
|
552
|
+
}>
|
|
553
|
+
| Readonly<{
|
|
554
|
+
name: 'execute.error';
|
|
555
|
+
executeId: number;
|
|
556
|
+
error: Error;
|
|
557
|
+
}>
|
|
558
|
+
| Readonly<{
|
|
559
|
+
name: 'execute.complete';
|
|
560
|
+
executeId: number;
|
|
561
|
+
}>
|
|
562
|
+
| Readonly<{
|
|
563
|
+
name: 'execute.normalize.start';
|
|
564
|
+
operation: OperationDescriptor;
|
|
565
|
+
}>
|
|
566
|
+
| Readonly<{
|
|
567
|
+
name: 'execute.normalize.end';
|
|
568
|
+
operation: OperationDescriptor;
|
|
569
|
+
}>
|
|
570
|
+
| Readonly<{
|
|
571
|
+
name: 'store.datachecker.start';
|
|
572
|
+
selector: NormalizationSelector;
|
|
573
|
+
}>
|
|
574
|
+
| Readonly<{
|
|
575
|
+
name: 'store.datachecker.end';
|
|
576
|
+
selector: NormalizationSelector;
|
|
577
|
+
}>
|
|
578
|
+
| Readonly<{
|
|
579
|
+
name: 'store.publish';
|
|
580
|
+
source: RecordSource;
|
|
581
|
+
optimistic: boolean;
|
|
582
|
+
}>
|
|
583
|
+
| Readonly<{
|
|
584
|
+
name: 'store.snapshot';
|
|
585
|
+
}>
|
|
586
|
+
| Readonly<{
|
|
587
|
+
name: 'store.lookup.start';
|
|
588
|
+
selector: SingularReaderSelector;
|
|
589
|
+
}>
|
|
590
|
+
| Readonly<{
|
|
591
|
+
name: 'store.lookup.end';
|
|
592
|
+
selector: SingularReaderSelector;
|
|
593
|
+
}>
|
|
594
|
+
| Readonly<{
|
|
595
|
+
name: 'store.restore';
|
|
596
|
+
}>
|
|
597
|
+
| Readonly<{
|
|
598
|
+
name: 'store.gc.start';
|
|
599
|
+
}>
|
|
600
|
+
| Readonly<{
|
|
601
|
+
name: 'store.gc.interrupted';
|
|
602
|
+
}>
|
|
603
|
+
| Readonly<{
|
|
604
|
+
name: 'store.gc.end';
|
|
605
|
+
references: DataIDSet;
|
|
606
|
+
}>
|
|
607
|
+
| Readonly<{
|
|
608
|
+
name: 'store.notify.start';
|
|
609
|
+
sourceOperation?: OperationDescriptor | undefined;
|
|
610
|
+
}>
|
|
611
|
+
| Readonly<{
|
|
612
|
+
name: 'store.notify.complete';
|
|
613
|
+
sourceOperation?: OperationDescriptor | undefined;
|
|
614
|
+
updatedRecordIDs: DataIDSet;
|
|
615
|
+
invalidatedRecordIDs: DataIDSet;
|
|
616
|
+
subscriptionsSize: number;
|
|
617
|
+
updatedOwners: Array<RequestDescriptor>;
|
|
618
|
+
}>
|
|
619
|
+
| Readonly<{
|
|
620
|
+
name: 'store.notify.subscription';
|
|
621
|
+
sourceOperation?: OperationDescriptor | undefined;
|
|
622
|
+
snapshot: Snapshot;
|
|
623
|
+
nextSnapshot: Snapshot;
|
|
624
|
+
}>
|
|
625
|
+
| Readonly<{
|
|
626
|
+
name: 'entrypoint.root.consume';
|
|
627
|
+
profilerContext: unknown;
|
|
628
|
+
rootModuleID: string;
|
|
629
|
+
}>
|
|
630
|
+
| Readonly<{
|
|
631
|
+
name: 'liveresolver.batch.start';
|
|
632
|
+
}>
|
|
633
|
+
| Readonly<{
|
|
634
|
+
name: 'liveresolver.batch.end';
|
|
635
|
+
}>
|
|
636
|
+
| Readonly<{
|
|
637
|
+
name: 'useFragment.subscription.missedUpdates';
|
|
638
|
+
hasDataChanges: boolean;
|
|
639
|
+
}>;
|
|
640
|
+
|
|
641
|
+
export type LogFunction = (logEvent: LogEvent) => void;
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* The public API of Relay core. Represents an encapsulated environment with its
|
|
645
|
+
* own in-memory cache.
|
|
646
|
+
*/
|
|
647
|
+
export interface Environment {
|
|
648
|
+
/**
|
|
649
|
+
* Extra information attached to the environment instance
|
|
650
|
+
*/
|
|
651
|
+
options: unknown;
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Determine if the operation can be resolved with data in the store (i.e. no
|
|
655
|
+
* fields are missing).
|
|
656
|
+
*
|
|
657
|
+
* Note that this operation effectively "executes" the selector against the
|
|
658
|
+
* cache and therefore takes time proportional to the size/complexity of the
|
|
659
|
+
* selector.
|
|
660
|
+
*/
|
|
661
|
+
check(operation: OperationDescriptor, options?: CheckOptions): OperationAvailability;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Subscribe to changes to the results of a selector. The callback is called
|
|
665
|
+
* when data has been committed to the store that would cause the results of
|
|
666
|
+
* the snapshot's selector to change.
|
|
667
|
+
*/
|
|
668
|
+
subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable;
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Ensure that all the records necessary to fulfill the given operation are
|
|
672
|
+
* retained in-memory. The records will not be eligible for garbage collection
|
|
673
|
+
* until the returned reference is disposed.
|
|
674
|
+
*/
|
|
675
|
+
retain(operation: OperationDescriptor): Disposable;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Apply an optimistic update to the environment. The mutation can be reverted
|
|
679
|
+
* by calling `dispose()` on the returned value.
|
|
680
|
+
*/
|
|
681
|
+
applyUpdate(optimisticUpdate: OptimisticUpdateFunction): Disposable;
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Apply an optimistic mutation response and/or updater. The mutation can be
|
|
685
|
+
* reverted by calling `dispose()` on the returned value.
|
|
686
|
+
*/
|
|
687
|
+
applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable;
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Commit an updater to the environment. This mutation cannot be reverted and
|
|
691
|
+
* should therefore not be used for optimistic updates. This is mainly
|
|
692
|
+
* intended for updating fields from client schema extensions.
|
|
693
|
+
*/
|
|
694
|
+
commitUpdate(updater: StoreUpdater): void;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Commit a payload to the environment using the given operation selector.
|
|
698
|
+
*/
|
|
699
|
+
commitPayload(operationDescriptor: OperationDescriptor, payload: PayloadData): void;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Get the environment's internal Network.
|
|
703
|
+
*/
|
|
704
|
+
getNetwork(): Network;
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Get the environment's internal Store.
|
|
708
|
+
*/
|
|
709
|
+
getStore(): Store;
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Returns the environment specific OperationTracker.
|
|
713
|
+
*/
|
|
714
|
+
getOperationTracker(): RelayOperationTracker;
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Read the results of a selector from in-memory records in the store.
|
|
718
|
+
* Optionally takes an owner, corresponding to the operation that
|
|
719
|
+
* owns this selector (fragment).
|
|
720
|
+
*/
|
|
721
|
+
lookup(selector: SingularReaderSelector): Snapshot;
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Send a query to the server with Observer semantics: one or more
|
|
725
|
+
* responses may be returned (via `next`) over time followed by either
|
|
726
|
+
* the request completing (`completed`) or an error (`error`).
|
|
727
|
+
*
|
|
728
|
+
* Networks/servers that support subscriptions may choose to hold the
|
|
729
|
+
* subscription open indefinitely such that `complete` is not called.
|
|
730
|
+
*
|
|
731
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
732
|
+
* the result is subscribed to: environment.execute({...}).subscribe({...}).
|
|
733
|
+
*/
|
|
734
|
+
execute(config: {
|
|
735
|
+
operation: OperationDescriptor;
|
|
736
|
+
updater?: SelectorStoreUpdater | null | undefined;
|
|
737
|
+
}): RelayObservable<GraphQLResponse>;
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
741
|
+
* provided Mutation operation, the result of which is then normalized and
|
|
742
|
+
* committed to the publish queue along with an optional optimistic response
|
|
743
|
+
* or updater.
|
|
744
|
+
*
|
|
745
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
746
|
+
* the result is subscribed to:
|
|
747
|
+
* environment.executeMutation({...}).subscribe({...}).
|
|
748
|
+
*/
|
|
749
|
+
executeMutation({
|
|
750
|
+
operation,
|
|
751
|
+
optimisticUpdater,
|
|
752
|
+
optimisticResponse,
|
|
753
|
+
updater,
|
|
754
|
+
uploadables,
|
|
755
|
+
}: {
|
|
756
|
+
operation: OperationDescriptor;
|
|
757
|
+
optimisticUpdater?: SelectorStoreUpdater | null | undefined;
|
|
758
|
+
optimisticResponse?: { [key: string]: any } | null | undefined;
|
|
759
|
+
updater?: SelectorStoreUpdater | null | undefined;
|
|
760
|
+
uploadables?: UploadableMap | null | undefined;
|
|
761
|
+
}): RelayObservable<GraphQLResponse>;
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
765
|
+
* provided Query or Subscription operation responses, the result of which is
|
|
766
|
+
* then normalized and committed to the publish queue.
|
|
767
|
+
*
|
|
768
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
769
|
+
* the result is subscribed to:
|
|
770
|
+
* environment.executeWithSource({...}).subscribe({...}).
|
|
771
|
+
*/
|
|
772
|
+
executeWithSource({
|
|
773
|
+
operation,
|
|
774
|
+
source,
|
|
775
|
+
}: {
|
|
776
|
+
operation: OperationDescriptor;
|
|
777
|
+
source: RelayObservable<GraphQLResponse>;
|
|
778
|
+
}): RelayObservable<GraphQLResponse>;
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Returns true if a request is currently "active", meaning it's currently
|
|
782
|
+
* actively receiving payloads or downloading modules, and has not received
|
|
783
|
+
* a final payload yet. Note that a request might still be pending (or "in flight")
|
|
784
|
+
* without actively receiving payload, for example a live query or an
|
|
785
|
+
* active GraphQL subscription
|
|
786
|
+
*/
|
|
787
|
+
isRequestActive(requestIdentifier: string): boolean;
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Returns true if the environment is for use during server side rendering.
|
|
791
|
+
* functions like getQueryResource key off of this in order to determine
|
|
792
|
+
* whether we need to set up certain caches and timeout's.
|
|
793
|
+
*/
|
|
794
|
+
isServer(): boolean;
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Called by Relay when it encounters a missing field that has been annotated
|
|
798
|
+
* with `@required(action: LOG)` or `@required(action: THROW)`.
|
|
799
|
+
*/
|
|
800
|
+
relayFieldLogger: RelayFieldLogger;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* The results of reading data for a fragment. This is similar to a `Selector`,
|
|
805
|
+
* but references the (fragment) node by name rather than by value.
|
|
806
|
+
*/
|
|
807
|
+
export interface FragmentPointer {
|
|
808
|
+
__id: DataID;
|
|
809
|
+
__fragments: { [fragmentName: string]: Variables };
|
|
810
|
+
__fragmentOwner: RequestDescriptor;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// tslint:disable:no-redundant-jsdoc-2
|
|
814
|
+
/**
|
|
815
|
+
* The partial shape of an object with a '...Fragment @module(name: "...")'
|
|
816
|
+
* selection
|
|
817
|
+
*/
|
|
818
|
+
export interface ModuleImportPointer {
|
|
819
|
+
readonly __fragmentPropName: string | null | undefined;
|
|
820
|
+
readonly __module_component: unknown;
|
|
821
|
+
readonly $fragmentSpreads: unknown;
|
|
822
|
+
}
|
|
823
|
+
// tslint:enable:no-redundant-jsdoc-2
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* A callback for resolving a Selector from a source.
|
|
827
|
+
*/
|
|
828
|
+
export type AsyncLoadCallback = (loadingState: LoadingState) => void;
|
|
829
|
+
export interface LoadingState {
|
|
830
|
+
status: 'aborted' | 'complete' | 'error' | 'missing';
|
|
831
|
+
error?: Error | undefined;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
export type DataIDSet = Set<DataID>;
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* A function that updates a store (via a proxy) given the results of a "handle"
|
|
838
|
+
* field payload.
|
|
839
|
+
*/
|
|
840
|
+
export class Handler {
|
|
841
|
+
update: (store: RecordSourceProxy, fieldPayload: HandleFieldPayload) => void;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* A payload that is used to initialize or update a "handle" field with
|
|
846
|
+
* information from the server.
|
|
847
|
+
*/
|
|
848
|
+
export interface HandleFieldPayload {
|
|
849
|
+
// The arguments that were fetched.
|
|
850
|
+
readonly args: Variables;
|
|
851
|
+
// The __id of the record containing the source/handle field.
|
|
852
|
+
readonly dataID: DataID;
|
|
853
|
+
// The (storage) key at which the original server data was written.
|
|
854
|
+
readonly fieldKey: string;
|
|
855
|
+
// The name of the handle.
|
|
856
|
+
readonly handle: string;
|
|
857
|
+
// The (storage) key at which the handle's data should be written by the
|
|
858
|
+
// handler.
|
|
859
|
+
readonly handleKey: string;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* A payload that represents data necessary to process the results of an object
|
|
864
|
+
* with a `@module` fragment spread:
|
|
865
|
+
* - data: The GraphQL response value for the @match field.
|
|
866
|
+
* - dataID: The ID of the store object linked to by the @match field.
|
|
867
|
+
* - operationReference: A reference to a generated module containing the
|
|
868
|
+
* SplitOperation with which to normalize the field's `data`.
|
|
869
|
+
* - variables: Query variables.
|
|
870
|
+
* - typeName: the type that matched.
|
|
871
|
+
*
|
|
872
|
+
* The dataID, variables, and fragmentName can be used to create a Selector
|
|
873
|
+
* which can in turn be used to normalize and publish the data. The dataID and
|
|
874
|
+
* typeName can also be used to construct a root record for normalization.
|
|
875
|
+
*/
|
|
876
|
+
export interface ModuleImportPayload {
|
|
877
|
+
readonly data: PayloadData;
|
|
878
|
+
readonly dataID: DataID;
|
|
879
|
+
readonly operationReference: any;
|
|
880
|
+
readonly path: readonly string[];
|
|
881
|
+
readonly typeName: string;
|
|
882
|
+
readonly variables: Variables;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Data emitted after processing a Defer or Stream node during normalization
|
|
887
|
+
* that describes how to process the corresponding response chunk when it
|
|
888
|
+
* arrives.
|
|
889
|
+
*/
|
|
890
|
+
export interface DeferPlaceholder {
|
|
891
|
+
readonly kind: 'defer';
|
|
892
|
+
readonly data: PayloadData;
|
|
893
|
+
readonly label: string;
|
|
894
|
+
readonly path: readonly string[];
|
|
895
|
+
readonly selector: NormalizationSelector;
|
|
896
|
+
readonly typeName: string;
|
|
897
|
+
}
|
|
898
|
+
export interface StreamPlaceholder {
|
|
899
|
+
readonly kind: 'stream';
|
|
900
|
+
readonly label: string;
|
|
901
|
+
readonly path: readonly string[];
|
|
902
|
+
readonly parentID: DataID;
|
|
903
|
+
readonly node: NormalizationSelectableNode;
|
|
904
|
+
readonly variables: Variables;
|
|
905
|
+
}
|
|
906
|
+
export type IncrementalDataPlaceholder = DeferPlaceholder | StreamPlaceholder;
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* A user-supplied object to load a generated operation (SplitOperation) AST
|
|
910
|
+
* by a module reference. The exact format of a module reference is left to
|
|
911
|
+
* the application, but it must be a plain JavaScript value (string, number,
|
|
912
|
+
* or object/array of same).
|
|
913
|
+
*/
|
|
914
|
+
export interface OperationLoader {
|
|
915
|
+
/**
|
|
916
|
+
* Synchronously load an operation, returning either the node or null if it
|
|
917
|
+
* cannot be resolved synchronously.
|
|
918
|
+
*/
|
|
919
|
+
get(reference: unknown): NormalizationSplitOperation | null | undefined;
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* Asynchronously load an operation.
|
|
923
|
+
*/
|
|
924
|
+
load(reference: unknown): Promise<NormalizationSplitOperation | null | undefined>;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* A function that receives a proxy over the store and may trigger side-effects
|
|
929
|
+
* (indirectly) by calling `set*` methods on the store or its record proxies.
|
|
930
|
+
*/
|
|
931
|
+
export type StoreUpdater = (store: RecordSourceProxy) => void;
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Similar to StoreUpdater, but accepts a proxy tied to a specific selector in
|
|
935
|
+
* order to easily access the root fields of a query/mutation as well as a
|
|
936
|
+
* second argument of the response object of the mutation.
|
|
937
|
+
*/
|
|
938
|
+
export type SelectorStoreUpdater<T = object> = (
|
|
939
|
+
store: RecordSourceSelectorProxy<T>,
|
|
940
|
+
data: T | null | undefined,
|
|
941
|
+
) => void;
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* A set of configs that can be used to apply an optimistic update into the
|
|
945
|
+
* store.
|
|
946
|
+
*/
|
|
947
|
+
export type OptimisticUpdate = OptimisticUpdateFunction | OptimisticUpdateRelayPayload;
|
|
948
|
+
|
|
949
|
+
export interface OptimisticUpdateFunction {
|
|
950
|
+
readonly storeUpdater: StoreUpdater;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
export interface OptimisticUpdateRelayPayload {
|
|
954
|
+
readonly operation: OperationDescriptor;
|
|
955
|
+
readonly payload: RelayResponsePayload;
|
|
956
|
+
readonly updater: SelectorStoreUpdater | null | undefined;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
export interface OptimisticResponseConfig<TMutation extends MutationParameters = any> {
|
|
960
|
+
readonly operation: OperationDescriptor;
|
|
961
|
+
readonly response: PayloadData | null | undefined;
|
|
962
|
+
readonly updater: SelectorStoreUpdater<TMutation> | null | undefined;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* A set of handlers that can be used to provide substitute data for missing
|
|
967
|
+
* fields when reading a selector from a source.
|
|
968
|
+
*/
|
|
969
|
+
export type MissingFieldHandler =
|
|
970
|
+
| {
|
|
971
|
+
kind: 'scalar';
|
|
972
|
+
handle: (
|
|
973
|
+
field: NormalizationScalarField,
|
|
974
|
+
parentRecord: ReadOnlyRecordProxy | null | undefined,
|
|
975
|
+
args: Variables,
|
|
976
|
+
store: ReadOnlyRecordSourceProxy,
|
|
977
|
+
) => unknown;
|
|
978
|
+
}
|
|
979
|
+
| {
|
|
980
|
+
kind: 'linked';
|
|
981
|
+
handle: (
|
|
982
|
+
field: NormalizationLinkedField | ReaderLinkedField,
|
|
983
|
+
parentRecord: ReadOnlyRecordProxy | null | undefined,
|
|
984
|
+
args: Variables,
|
|
985
|
+
store: ReadOnlyRecordSourceProxy,
|
|
986
|
+
) => DataID | null | undefined;
|
|
987
|
+
}
|
|
988
|
+
| {
|
|
989
|
+
kind: 'pluralLinked';
|
|
990
|
+
handle: (
|
|
991
|
+
field: NormalizationLinkedField | ReaderLinkedField,
|
|
992
|
+
parentRecord: ReadOnlyRecordProxy | null | undefined,
|
|
993
|
+
args: Variables,
|
|
994
|
+
store: ReadOnlyRecordSourceProxy,
|
|
995
|
+
) => Array<DataID | null | undefined> | null | undefined;
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
type TRelayFieldErrorForDisplay = Readonly<{
|
|
999
|
+
path?: ReadonlyArray<string | number>;
|
|
1000
|
+
severity?: 'CRITICAL' | 'ERROR' | 'WARNING';
|
|
1001
|
+
}>;
|
|
1002
|
+
|
|
1003
|
+
export type TRelayFieldError =
|
|
1004
|
+
& TRelayFieldErrorForDisplay
|
|
1005
|
+
& Readonly<{
|
|
1006
|
+
message: string;
|
|
1007
|
+
}>;
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Data which Relay expected to be in the store (because it was requested by
|
|
1011
|
+
* the parent query/mutation/subscription) was missing. This can happen due
|
|
1012
|
+
* to graph relationship changes observed by other queries/mutations, or
|
|
1013
|
+
* imperative updates that don't provide all needed data.
|
|
1014
|
+
*
|
|
1015
|
+
* https://relay.dev/docs/next/debugging/why-null/#graph-relationship-change
|
|
1016
|
+
*
|
|
1017
|
+
* In this case Relay will render with the referenced field as `undefined`.
|
|
1018
|
+
*
|
|
1019
|
+
* __NOTE__: This may break with the type contract of Relay's generated types.
|
|
1020
|
+
*
|
|
1021
|
+
* To turn this into a hard error for a given fragment/query, you can use
|
|
1022
|
+
* `@throwOnFieldError`.
|
|
1023
|
+
*
|
|
1024
|
+
* https://relay.dev/docs/next/guides/throw-on-field-error-directive/
|
|
1025
|
+
*/
|
|
1026
|
+
type MissingExpectedDataLogEvent = Readonly<{
|
|
1027
|
+
kind: 'missing_expected_data.log';
|
|
1028
|
+
owner: string;
|
|
1029
|
+
fieldPath: string;
|
|
1030
|
+
}>;
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Data which Relay expected to be in the store (because it was requested by
|
|
1034
|
+
* the parent query/mutation/subscription) was missing. This can happen due
|
|
1035
|
+
* to graph relationship changes observed by other queries/mutations, or
|
|
1036
|
+
* imperative updates that don't provide all needed data.
|
|
1037
|
+
*
|
|
1038
|
+
* https://relay.dev/docs/next/debugging/why-null/#graph-relationship-change
|
|
1039
|
+
*
|
|
1040
|
+
* This event is as `.throw` because the missing data was encountered in a
|
|
1041
|
+
* query/fragment/mutation with `@throwOnFieldError` `@throwOnFieldError`.
|
|
1042
|
+
*
|
|
1043
|
+
* https://relay.dev/docs/next/guides/throw-on-field-error-directive/
|
|
1044
|
+
*
|
|
1045
|
+
* Relay will throw immediately after logging this event. If you wish to
|
|
1046
|
+
* customize the error being thrown, you may throw your own error.
|
|
1047
|
+
*
|
|
1048
|
+
* *NOTE*: Only throw on this event if `handled` is false. Errors that have been
|
|
1049
|
+
* handled by a `@catch` directive or by making a resolver null will have
|
|
1050
|
+
* `handled: true` and should not trigger a throw.
|
|
1051
|
+
*/
|
|
1052
|
+
type MissingExpectedDataThrowEvent = Readonly<{
|
|
1053
|
+
kind: 'missing_expected_data.throw';
|
|
1054
|
+
owner: string;
|
|
1055
|
+
fieldPath: string;
|
|
1056
|
+
handled: boolean;
|
|
1057
|
+
}>;
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* A field was marked as @required(action: LOG) but was null or missing in the
|
|
1061
|
+
* store.
|
|
1062
|
+
*/
|
|
1063
|
+
type MissingRequiredFieldLogEvent = Readonly<{
|
|
1064
|
+
kind: 'missing_required_field.log';
|
|
1065
|
+
owner: string;
|
|
1066
|
+
fieldPath: string;
|
|
1067
|
+
}>;
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* A field was marked as @required(action: THROW) but was null or missing in the
|
|
1071
|
+
* store.
|
|
1072
|
+
*
|
|
1073
|
+
* Relay will throw immediately after logging this event. If you wish to
|
|
1074
|
+
* customize the error being thrown, you may throw your own error.
|
|
1075
|
+
*
|
|
1076
|
+
* *NOTE*: Only throw on this event if `handled` is false. Errors that have been
|
|
1077
|
+
* handled by a `@catch` directive or by making a resolver null will have
|
|
1078
|
+
* `handled: true` and should not trigger a throw.
|
|
1079
|
+
*/
|
|
1080
|
+
type MissingRequiredFieldThrowEvent = Readonly<{
|
|
1081
|
+
kind: 'missing_required_field.throw';
|
|
1082
|
+
owner: string;
|
|
1083
|
+
fieldPath: string;
|
|
1084
|
+
handled: boolean;
|
|
1085
|
+
}>;
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* A Relay Resolver that is currently being read threw a JavaScript error when
|
|
1089
|
+
* it was last evaluated. By default, the value has been coerced to null and
|
|
1090
|
+
* passed to the product code.
|
|
1091
|
+
*
|
|
1092
|
+
* If `@throwOnFieldError` was used on the parent query/fragment/mutation, you
|
|
1093
|
+
* will also receive a TODO
|
|
1094
|
+
*
|
|
1095
|
+
* *NOTE*: Only throw on this event if `handled` is false. Errors that have been
|
|
1096
|
+
* handled by a `@catch` directive or by making a resolver null will have
|
|
1097
|
+
* `handled: true` and should not trigger a throw.
|
|
1098
|
+
*/
|
|
1099
|
+
type RelayResolverErrorEvent = Readonly<{
|
|
1100
|
+
kind: 'relay_resolver.error';
|
|
1101
|
+
owner: string;
|
|
1102
|
+
fieldPath: string;
|
|
1103
|
+
error: Error;
|
|
1104
|
+
shouldThrow: boolean;
|
|
1105
|
+
handled: boolean;
|
|
1106
|
+
}>;
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* A field being read by Relay was marked as being in an error state by the
|
|
1110
|
+
* GraphQL response.
|
|
1111
|
+
*
|
|
1112
|
+
* https://spec.graphql.org/October2021/#sec-Errors.Field-errors
|
|
1113
|
+
*
|
|
1114
|
+
* If the field's parent query/fragment/mutation was annotated with
|
|
1115
|
+
* `@throwOnFieldError` and no `@catch` directive was used to catch the error,
|
|
1116
|
+
* Relay will throw an error immediately after logging this event.
|
|
1117
|
+
*
|
|
1118
|
+
* https://relay.dev/docs/next/guides/catch-directive/
|
|
1119
|
+
* https://relay.dev/docs/next/guides/throw-on-field-error-directive/
|
|
1120
|
+
*
|
|
1121
|
+
* *NOTE*: Only throw on this event if `handled` is false. Errors that have been
|
|
1122
|
+
* handled by a `@catch` directive or by making a resolver null will have
|
|
1123
|
+
* `handled: true` and should not trigger a throw.
|
|
1124
|
+
*/
|
|
1125
|
+
type RelayFieldPayloadErrorEvent = Readonly<{
|
|
1126
|
+
kind: 'relay_field_payload.error';
|
|
1127
|
+
owner: string;
|
|
1128
|
+
fieldPath: string;
|
|
1129
|
+
error: TRelayFieldError;
|
|
1130
|
+
shouldThrow: boolean;
|
|
1131
|
+
handled: boolean;
|
|
1132
|
+
}>;
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* Union of all RelayFieldLoggerEvent types
|
|
1136
|
+
*/
|
|
1137
|
+
export type RelayFieldLoggerEvent =
|
|
1138
|
+
| MissingExpectedDataLogEvent
|
|
1139
|
+
| MissingExpectedDataThrowEvent
|
|
1140
|
+
| MissingRequiredFieldLogEvent
|
|
1141
|
+
| MissingRequiredFieldThrowEvent
|
|
1142
|
+
| RelayResolverErrorEvent
|
|
1143
|
+
| RelayFieldPayloadErrorEvent;
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* A handler for events related to field errors.
|
|
1147
|
+
*/
|
|
1148
|
+
export type RelayFieldLogger = (event: RelayFieldLoggerEvent) => void;
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* The results of normalizing a query.
|
|
1152
|
+
*/
|
|
1153
|
+
export interface RelayResponsePayload {
|
|
1154
|
+
readonly errors: PayloadError[] | null | undefined;
|
|
1155
|
+
readonly fieldPayloads: HandleFieldPayload[] | null | undefined;
|
|
1156
|
+
readonly incrementalPlaceholders: IncrementalDataPlaceholder[] | null | undefined;
|
|
1157
|
+
readonly moduleImportPayloads: ModuleImportPayload[] | null | undefined;
|
|
1158
|
+
readonly source: MutableRecordSource;
|
|
1159
|
+
readonly isFinal: boolean;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Configuration on the executeMutation(...).
|
|
1164
|
+
*/
|
|
1165
|
+
export interface ExecuteMutationConfig<TMutation extends MutationParameters> {
|
|
1166
|
+
operation: OperationDescriptor;
|
|
1167
|
+
optimisticUpdater?: SelectorStoreUpdater<TMutation['response']> | null;
|
|
1168
|
+
optimisticResponse?: { [key: string]: any } | null;
|
|
1169
|
+
updater?: SelectorStoreUpdater<TMutation['response']> | null;
|
|
1170
|
+
uploadables?: UploadableMap | null;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Public interface for Publish Queue
|
|
1175
|
+
*/
|
|
1176
|
+
export interface PublishQueue {
|
|
1177
|
+
/**
|
|
1178
|
+
* Schedule applying an optimistic updates on the next `run()`.
|
|
1179
|
+
*/
|
|
1180
|
+
applyUpdate(updater: OptimisticUpdate): void;
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Schedule reverting an optimistic updates on the next `run()`.
|
|
1184
|
+
*/
|
|
1185
|
+
revertUpdate(updater: OptimisticUpdate): void;
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* Schedule a revert of all optimistic updates on the next `run()`.
|
|
1189
|
+
*/
|
|
1190
|
+
revertAll(): void;
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Schedule applying a payload to the store on the next `run()`.
|
|
1194
|
+
*/
|
|
1195
|
+
commitPayload(
|
|
1196
|
+
operation: OperationDescriptor,
|
|
1197
|
+
payload: RelayResponsePayload,
|
|
1198
|
+
updater?: SelectorStoreUpdater | null,
|
|
1199
|
+
): void;
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* Schedule an updater to mutate the store on the next `run()` typically to
|
|
1203
|
+
* update client schema fields.
|
|
1204
|
+
*/
|
|
1205
|
+
commitUpdate(updater: StoreUpdater): void;
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Schedule a publish to the store from the provided source on the next
|
|
1209
|
+
* `run()`. As an example, to update the store with substituted fields that
|
|
1210
|
+
* are missing in the store.
|
|
1211
|
+
*/
|
|
1212
|
+
commitSource(source: RecordSource): void;
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Execute all queued up operations from the other public methods.
|
|
1216
|
+
*/
|
|
1217
|
+
run(): readonly RequestDescriptor[];
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* ReactFlightDOMRelayClient processes a ReactFlightServerTree into a
|
|
1222
|
+
* ReactFlightClientResponse object. readRoot() can suspend.
|
|
1223
|
+
*/
|
|
1224
|
+
export interface ReactFlightClientResponse {
|
|
1225
|
+
readRoot: () => any;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
export interface ReactFlightReachableQuery {
|
|
1229
|
+
readonly module: any;
|
|
1230
|
+
readonly variables: Variables;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
export type ReactFlightPayloadDeserializer = (tree: ReactFlightServerTree) => ReactFlightClientResponse;
|
|
1234
|
+
|
|
1235
|
+
interface FieldLocation {
|
|
1236
|
+
path: string;
|
|
1237
|
+
owner: string;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
export type MissingRequiredFields =
|
|
1241
|
+
| Readonly<{ action: 'THROW'; field: FieldLocation }>
|
|
1242
|
+
| Readonly<{ action: 'LOG'; fields: FieldLocation[] }>;
|
|
1243
|
+
|
|
1244
|
+
export interface RelayResolverError {
|
|
1245
|
+
field: FieldLocation;
|
|
1246
|
+
error: Error;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
export type RelayResolverErrors = RelayResolverError[];
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* The return type of calls to store.readUpdatableFragment.
|
|
1253
|
+
*/
|
|
1254
|
+
export interface UpdatableFragmentData<TKey extends HasUpdatableSpread<TData>, TData = unknown> {
|
|
1255
|
+
readonly updatableData: Required<TKey>[' $data'];
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* The return type of calls to store.readUpdatableQuery.
|
|
1260
|
+
*/
|
|
1261
|
+
export interface UpdatableQueryData<TQuery extends OperationType> {
|
|
1262
|
+
readonly updatableData: TQuery['response'];
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* A linked field where an updatable fragment is spread has the type
|
|
1267
|
+
* HasUpdatableSpread.
|
|
1268
|
+
* This type is expected by store.readUpdatableFragment.
|
|
1269
|
+
*/
|
|
1270
|
+
export type HasUpdatableSpread<TData = unknown> = Readonly<{
|
|
1271
|
+
' $data'?: TData | undefined;
|
|
1272
|
+
$updatableFragmentSpreads: FragmentType;
|
|
1273
|
+
}>;
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* The return type of a Live Resolver. Models an external value which can
|
|
1277
|
+
* be read lazily and which might change over time. The subscribe method
|
|
1278
|
+
* returns a callback which should be called when the value _may_ have changed.
|
|
1279
|
+
*
|
|
1280
|
+
* While over-notification (subscription notifications when the read value has
|
|
1281
|
+
* not actually changed) is suported, for performance reasons, it is recommended
|
|
1282
|
+
* that the provider of the LiveState value confirms that the value has indeed
|
|
1283
|
+
* change before notifying Relay of the change.
|
|
1284
|
+
*/
|
|
1285
|
+
export interface LiveState<T> {
|
|
1286
|
+
/**
|
|
1287
|
+
* Returns the current value of the live state.
|
|
1288
|
+
*/
|
|
1289
|
+
read(): T;
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* Subscribes to changes in the live state. The state provider should
|
|
1293
|
+
* call the callback when the value of the live state changes.
|
|
1294
|
+
* If the returned unsubscribe function is invoked, the state provider
|
|
1295
|
+
* should stop calling the callback for state updates.
|
|
1296
|
+
*/
|
|
1297
|
+
subscribe(callback: () => void): () => void;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
export function suspenseSentinel(): never;
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* A placeholder type for the context that will be provided to resolvers.
|
|
1304
|
+
* The actual type used will be determined by the `resolverContextType` type specified in your Relay project config.
|
|
1305
|
+
*
|
|
1306
|
+
* When set on the Relay Store, this context will be passed as the third argument to all resolvers (live and non-live).
|
|
1307
|
+
*
|
|
1308
|
+
* @see {@link https://relay.dev/docs/next/guides/relay-resolvers/context/#type-checking} for documentation on configuring resolverContextType
|
|
1309
|
+
*/
|
|
1310
|
+
export type ResolverContext = unknown;
|
|
1311
|
+
|
|
1312
|
+
export type KeyType<TData = unknown> = Readonly<{
|
|
1313
|
+
' $data'?: TData | undefined;
|
|
1314
|
+
' $fragmentSpreads': FragmentType;
|
|
1315
|
+
}>;
|
|
1316
|
+
|
|
1317
|
+
export type KeyTypeData<TKey extends KeyType<TData>, TData = unknown> = Required<TKey>[' $data'];
|
|
1318
|
+
|
|
1319
|
+
export type ArrayKeyType<TData = unknown> = ReadonlyArray<KeyType<readonly TData[]> | null | undefined>;
|
|
1320
|
+
export type ArrayKeyTypeData<TKey extends ArrayKeyType<TData>, TData = unknown> = KeyTypeData<
|
|
1321
|
+
NonNullable<TKey[number]>
|
|
1322
|
+
>;
|
|
1323
|
+
|
|
1324
|
+
export type FragmentState<T> =
|
|
1325
|
+
| { state: 'ok'; value: T }
|
|
1326
|
+
| { state: 'error'; error: Error }
|
|
1327
|
+
| { state: 'loading' };
|