relay-runtime 9.0.0 → 10.1.0

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 (142) hide show
  1. package/handlers/RelayDefaultHandlerProvider.js.flow +47 -0
  2. package/handlers/connection/ConnectionHandler.js.flow +549 -0
  3. package/handlers/connection/ConnectionInterface.js.flow +92 -0
  4. package/handlers/connection/MutationHandlers.js.flow +199 -0
  5. package/index.js +1 -1
  6. package/index.js.flow +335 -0
  7. package/lib/handlers/RelayDefaultHandlerProvider.js +20 -0
  8. package/lib/handlers/connection/ConnectionHandler.js +1 -3
  9. package/lib/handlers/connection/MutationHandlers.js +212 -0
  10. package/lib/index.js +14 -2
  11. package/lib/mutations/RelayDeclarativeMutationConfig.js +22 -45
  12. package/lib/mutations/RelayRecordProxy.js +1 -3
  13. package/lib/mutations/RelayRecordSourceMutator.js +1 -3
  14. package/lib/mutations/RelayRecordSourceProxy.js +1 -3
  15. package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -3
  16. package/lib/mutations/commitMutation.js +2 -3
  17. package/lib/mutations/validateMutation.js +40 -9
  18. package/lib/network/RelayObservable.js +9 -9
  19. package/lib/network/RelayQueryResponseCache.js +8 -6
  20. package/lib/query/GraphQLTag.js +2 -1
  21. package/lib/query/PreloadableQueryRegistry.js +70 -0
  22. package/lib/query/fetchQuery.js +2 -3
  23. package/lib/query/fetchQueryInternal.js +5 -14
  24. package/lib/store/DataChecker.js +200 -71
  25. package/lib/store/RelayConcreteVariables.js +6 -2
  26. package/lib/store/RelayModernEnvironment.js +124 -65
  27. package/lib/store/RelayModernFragmentSpecResolver.js +19 -14
  28. package/lib/store/RelayModernOperationDescriptor.js +6 -5
  29. package/lib/store/RelayModernQueryExecutor.js +122 -73
  30. package/lib/store/RelayModernRecord.js +14 -9
  31. package/lib/store/RelayModernSelector.js +6 -2
  32. package/lib/store/RelayModernStore.js +281 -131
  33. package/lib/store/RelayOperationTracker.js +35 -78
  34. package/lib/store/RelayOptimisticRecordSource.js +7 -5
  35. package/lib/store/RelayPublishQueue.js +2 -4
  36. package/lib/store/RelayReader.js +304 -52
  37. package/lib/store/RelayRecordSource.js +1 -3
  38. package/lib/store/RelayRecordSourceMapImpl.js +13 -18
  39. package/lib/store/RelayReferenceMarker.js +125 -14
  40. package/lib/store/RelayResponseNormalizer.js +261 -66
  41. package/lib/store/RelayStoreReactFlightUtils.js +47 -0
  42. package/lib/store/RelayStoreUtils.js +1 -0
  43. package/lib/store/StoreInspector.js +8 -8
  44. package/lib/store/TypeID.js +28 -0
  45. package/lib/store/cloneRelayScalarHandleSourceField.js +44 -0
  46. package/lib/store/defaultRequiredFieldLogger.js +18 -0
  47. package/lib/store/normalizeRelayPayload.js +6 -2
  48. package/lib/store/readInlineData.js +1 -1
  49. package/lib/subscription/requestSubscription.js +4 -3
  50. package/lib/util/NormalizationNode.js +1 -5
  51. package/lib/util/RelayConcreteNode.js +11 -6
  52. package/lib/util/RelayError.js +39 -9
  53. package/lib/util/RelayFeatureFlags.js +6 -3
  54. package/lib/util/RelayReplaySubject.js +3 -3
  55. package/lib/util/createPayloadFor3DField.js +7 -2
  56. package/lib/util/getFragmentIdentifier.js +12 -3
  57. package/lib/util/getOperation.js +33 -0
  58. package/lib/util/getRequestIdentifier.js +2 -2
  59. package/lib/util/isEmptyObject.js +25 -0
  60. package/lib/util/recycleNodesInto.js +6 -7
  61. package/lib/util/reportMissingRequiredFields.js +48 -0
  62. package/mutations/RelayDeclarativeMutationConfig.js.flow +380 -0
  63. package/mutations/RelayRecordProxy.js.flow +165 -0
  64. package/mutations/RelayRecordSourceMutator.js.flow +238 -0
  65. package/mutations/RelayRecordSourceProxy.js.flow +164 -0
  66. package/mutations/RelayRecordSourceSelectorProxy.js.flow +119 -0
  67. package/mutations/applyOptimisticMutation.js.flow +76 -0
  68. package/mutations/commitLocalUpdate.js.flow +24 -0
  69. package/mutations/commitMutation.js.flow +181 -0
  70. package/mutations/validateMutation.js.flow +242 -0
  71. package/network/ConvertToExecuteFunction.js.flow +49 -0
  72. package/network/RelayNetwork.js.flow +84 -0
  73. package/network/RelayNetworkTypes.js.flow +145 -0
  74. package/network/RelayObservable.js.flow +634 -0
  75. package/network/RelayQueryResponseCache.js.flow +111 -0
  76. package/package.json +2 -2
  77. package/query/GraphQLTag.js.flow +168 -0
  78. package/query/PreloadableQueryRegistry.js.flow +65 -0
  79. package/query/fetchQuery.js.flow +47 -0
  80. package/query/fetchQueryInternal.js.flow +343 -0
  81. package/relay-runtime.js +2 -2
  82. package/relay-runtime.min.js +2 -2
  83. package/store/ClientID.js.flow +43 -0
  84. package/store/DataChecker.js.flow +568 -0
  85. package/store/RelayConcreteVariables.js.flow +96 -0
  86. package/store/RelayModernEnvironment.js.flow +571 -0
  87. package/store/RelayModernFragmentSpecResolver.js.flow +438 -0
  88. package/store/RelayModernOperationDescriptor.js.flow +92 -0
  89. package/store/RelayModernQueryExecutor.js.flow +1345 -0
  90. package/store/RelayModernRecord.js.flow +403 -0
  91. package/store/RelayModernSelector.js.flow +455 -0
  92. package/store/RelayModernStore.js.flow +858 -0
  93. package/store/RelayOperationTracker.js.flow +164 -0
  94. package/store/RelayOptimisticRecordSource.js.flow +119 -0
  95. package/store/RelayPublishQueue.js.flow +401 -0
  96. package/store/RelayReader.js.flow +638 -0
  97. package/store/RelayRecordSource.js.flow +29 -0
  98. package/store/RelayRecordSourceMapImpl.js.flow +87 -0
  99. package/store/RelayRecordState.js.flow +37 -0
  100. package/store/RelayReferenceMarker.js.flow +324 -0
  101. package/store/RelayResponseNormalizer.js.flow +791 -0
  102. package/store/RelayStoreReactFlightUtils.js.flow +64 -0
  103. package/store/RelayStoreTypes.js.flow +958 -0
  104. package/store/RelayStoreUtils.js.flow +219 -0
  105. package/store/StoreInspector.js.flow +171 -0
  106. package/store/TypeID.js.flow +28 -0
  107. package/store/ViewerPattern.js.flow +26 -0
  108. package/store/cloneRelayHandleSourceField.js.flow +66 -0
  109. package/store/cloneRelayScalarHandleSourceField.js.flow +62 -0
  110. package/store/createFragmentSpecResolver.js.flow +55 -0
  111. package/store/createRelayContext.js.flow +44 -0
  112. package/store/defaultGetDataID.js.flow +27 -0
  113. package/store/defaultRequiredFieldLogger.js.flow +23 -0
  114. package/store/hasOverlappingIDs.js.flow +34 -0
  115. package/store/isRelayModernEnvironment.js.flow +27 -0
  116. package/store/normalizeRelayPayload.js.flow +51 -0
  117. package/store/readInlineData.js.flow +75 -0
  118. package/subscription/requestSubscription.js.flow +103 -0
  119. package/util/JSResourceTypes.flow.js.flow +20 -0
  120. package/util/NormalizationNode.js.flow +213 -0
  121. package/util/ReaderNode.js.flow +227 -0
  122. package/util/RelayConcreteNode.js.flow +99 -0
  123. package/util/RelayDefaultHandleKey.js.flow +17 -0
  124. package/util/RelayError.js.flow +62 -0
  125. package/util/RelayFeatureFlags.js.flow +37 -0
  126. package/util/RelayProfiler.js.flow +284 -0
  127. package/util/RelayReplaySubject.js.flow +135 -0
  128. package/util/RelayRuntimeTypes.js.flow +72 -0
  129. package/util/createPayloadFor3DField.js.flow +43 -0
  130. package/util/deepFreeze.js.flow +36 -0
  131. package/util/generateID.js.flow +21 -0
  132. package/util/getFragmentIdentifier.js.flow +76 -0
  133. package/util/getOperation.js.flow +40 -0
  134. package/util/getRelayHandleKey.js.flow +41 -0
  135. package/util/getRequestIdentifier.js.flow +42 -0
  136. package/util/isEmptyObject.js.flow +25 -0
  137. package/util/isPromise.js.flow +21 -0
  138. package/util/isScalarAndEqual.js.flow +26 -0
  139. package/util/recycleNodesInto.js.flow +87 -0
  140. package/util/reportMissingRequiredFields.js.flow +51 -0
  141. package/util/resolveImmediate.js.flow +30 -0
  142. package/util/stableCopy.js.flow +35 -0
@@ -0,0 +1,958 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its 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
+ * @flow
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ import type {
16
+ GraphQLResponse,
17
+ INetwork,
18
+ PayloadData,
19
+ PayloadError,
20
+ ReactFlightServerTree,
21
+ UploadableMap,
22
+ } from '../network/RelayNetworkTypes';
23
+ import type RelayObservable from '../network/RelayObservable';
24
+ import type {
25
+ NormalizationLinkedField,
26
+ NormalizationRootNode,
27
+ NormalizationScalarField,
28
+ NormalizationSelectableNode,
29
+ } from '../util/NormalizationNode';
30
+ import type {ReaderFragment} from '../util/ReaderNode';
31
+ import type {
32
+ ConcreteRequest,
33
+ RequestParameters,
34
+ } from '../util/RelayConcreteNode';
35
+ import type {
36
+ CacheConfig,
37
+ DataID,
38
+ Disposable,
39
+ RenderPolicy,
40
+ Variables,
41
+ } from '../util/RelayRuntimeTypes';
42
+ import type {RequestIdentifier} from '../util/getRequestIdentifier';
43
+ import type {InvalidationState} from './RelayModernStore';
44
+ import type RelayOperationTracker from './RelayOperationTracker';
45
+ import type {RecordState} from './RelayRecordState';
46
+
47
+ export opaque type FragmentReference = empty;
48
+ export type OperationTracker = RelayOperationTracker;
49
+
50
+ /*
51
+ * An individual cached graph object.
52
+ */
53
+ export type Record = {[key: string]: mixed, ...};
54
+
55
+ /**
56
+ * A collection of records keyed by id.
57
+ */
58
+ export type RecordMap = {[dataID: DataID]: ?Record, ...};
59
+
60
+ export type FragmentMap = {[key: string]: ReaderFragment, ...};
61
+
62
+ /**
63
+ * The results of a selector given a store/RecordSource.
64
+ */
65
+ export type SelectorData = {[key: string]: mixed, ...};
66
+
67
+ export type SingularReaderSelector = {|
68
+ +kind: 'SingularReaderSelector',
69
+ +dataID: DataID,
70
+ +isWithinUnmatchedTypeRefinement: boolean,
71
+ +node: ReaderFragment,
72
+ +owner: RequestDescriptor,
73
+ +variables: Variables,
74
+ |};
75
+
76
+ export type ReaderSelector = SingularReaderSelector | PluralReaderSelector;
77
+
78
+ export type PluralReaderSelector = {|
79
+ +kind: 'PluralReaderSelector',
80
+ +selectors: $ReadOnlyArray<SingularReaderSelector>,
81
+ |};
82
+
83
+ export type RequestDescriptor = {|
84
+ +identifier: RequestIdentifier,
85
+ +node: ConcreteRequest,
86
+ +variables: Variables,
87
+ +cacheConfig: ?CacheConfig,
88
+ |};
89
+
90
+ /**
91
+ * A selector defines the starting point for a traversal into the graph for the
92
+ * purposes of targeting a subgraph.
93
+ */
94
+ export type NormalizationSelector = {|
95
+ +dataID: DataID,
96
+ +node: NormalizationSelectableNode,
97
+ +variables: Variables,
98
+ |};
99
+
100
+ type MissingRequiredField = {|
101
+ path: string,
102
+ owner: string,
103
+ |};
104
+
105
+ export type MissingRequiredFields =
106
+ | {|action: 'THROW', field: MissingRequiredField|}
107
+ | {|action: 'LOG', fields: Array<MissingRequiredField>|};
108
+
109
+ /**
110
+ * A representation of a selector and its results at a particular point in time.
111
+ */
112
+ export type Snapshot = {|
113
+ +data: ?SelectorData,
114
+ +isMissingData: boolean,
115
+ +seenRecords: RecordMap,
116
+ +selector: SingularReaderSelector,
117
+ +missingRequiredFields: ?MissingRequiredFields,
118
+ |};
119
+
120
+ /**
121
+ * An operation selector describes a specific instance of a GraphQL operation
122
+ * with variables applied.
123
+ *
124
+ * - `root`: a selector intended for processing server results or retaining
125
+ * response data in the store.
126
+ * - `fragment`: a selector intended for use in reading or subscribing to
127
+ * the results of the the operation.
128
+ */
129
+ export type OperationDescriptor = {|
130
+ +fragment: SingularReaderSelector,
131
+ +request: RequestDescriptor,
132
+ +root: NormalizationSelector,
133
+ |};
134
+
135
+ /**
136
+ * Arbitrary data e.g. received by a container as props.
137
+ */
138
+ export type Props = {[key: string]: mixed, ...};
139
+
140
+ /**
141
+ * The type of the `relay` property set on React context by the React/Relay
142
+ * integration layer (e.g. QueryRenderer, FragmentContainer, etc).
143
+ */
144
+ export type RelayContext = {|
145
+ environment: IEnvironment,
146
+ |};
147
+
148
+ /**
149
+ * The results of reading the results of a FragmentMap given some input
150
+ * `Props`.
151
+ */
152
+ export type FragmentSpecResults = {[key: string]: mixed, ...};
153
+
154
+ /**
155
+ * A utility for resolving and subscribing to the results of a fragment spec
156
+ * (key -> fragment mapping) given some "props" that determine the root ID
157
+ * and variables to use when reading each fragment. When props are changed via
158
+ * `setProps()`, the resolver will update its results and subscriptions
159
+ * accordingly. Internally, the resolver:
160
+ * - Converts the fragment map & props map into a map of `Selector`s.
161
+ * - Removes any resolvers for any props that became null.
162
+ * - Creates resolvers for any props that became non-null.
163
+ * - Updates resolvers with the latest props.
164
+ */
165
+ export interface FragmentSpecResolver {
166
+ /**
167
+ * Stop watching for changes to the results of the fragments.
168
+ */
169
+ dispose(): void;
170
+
171
+ /**
172
+ * Get the current results.
173
+ */
174
+ resolve(): FragmentSpecResults;
175
+
176
+ /**
177
+ * Update the resolver with new inputs. Call `resolve()` to get the updated
178
+ * results.
179
+ */
180
+ setProps(props: Props): void;
181
+
182
+ /**
183
+ * Override the variables used to read the results of the fragments. Call
184
+ * `resolve()` to get the updated results.
185
+ */
186
+ setVariables(variables: Variables, node: ConcreteRequest): void;
187
+
188
+ /**
189
+ * Subscribe to resolver updates.
190
+ * Overrides existing callback (if one has been specified).
191
+ */
192
+ setCallback(callback: () => void): void;
193
+ }
194
+
195
+ /**
196
+ * A read-only interface for accessing cached graph data.
197
+ */
198
+ export interface RecordSource {
199
+ get(dataID: DataID): ?Record;
200
+ getRecordIDs(): Array<DataID>;
201
+ getStatus(dataID: DataID): RecordState;
202
+ has(dataID: DataID): boolean;
203
+ size(): number;
204
+ toJSON(): {[DataID]: ?Record, ...};
205
+ }
206
+
207
+ /**
208
+ * A read/write interface for accessing and updating graph data.
209
+ */
210
+ export interface MutableRecordSource extends RecordSource {
211
+ clear(): void;
212
+ delete(dataID: DataID): void;
213
+ remove(dataID: DataID): void;
214
+ set(dataID: DataID, record: Record): void;
215
+ }
216
+
217
+ export type CheckOptions = {|
218
+ target: MutableRecordSource,
219
+ handlers: $ReadOnlyArray<MissingFieldHandler>,
220
+ |};
221
+
222
+ export type OperationAvailability =
223
+ | {|status: 'available', fetchTime: ?number|}
224
+ | {|status: 'stale'|}
225
+ | {|status: 'missing'|};
226
+
227
+ export type {InvalidationState} from './RelayModernStore';
228
+
229
+ /**
230
+ * An interface for keeping multiple views of data consistent across an
231
+ * application.
232
+ */
233
+ export interface Store {
234
+ /**
235
+ * Get a read-only view of the store's internal RecordSource.
236
+ */
237
+ getSource(): RecordSource;
238
+
239
+ /**
240
+ * Determine if the operation can be resolved with data in the store (i.e. no
241
+ * fields are missing).
242
+ */
243
+ check(
244
+ operation: OperationDescriptor,
245
+ options?: CheckOptions,
246
+ ): OperationAvailability;
247
+
248
+ /**
249
+ * Read the results of a selector from in-memory records in the store.
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(
262
+ sourceOperation?: OperationDescriptor,
263
+ invalidateStore?: boolean,
264
+ ): $ReadOnlyArray<RequestDescriptor>;
265
+
266
+ /**
267
+ * Publish new information (e.g. from the network) to the store, updating its
268
+ * internal record source. Subscribers are not immediately notified - this
269
+ * occurs when `notify()` is called.
270
+ */
271
+ publish(source: RecordSource, idsMarkedForInvalidation?: Set<DataID>): void;
272
+
273
+ /**
274
+ * Ensure that all the records necessary to fulfill the given selector are
275
+ * retained in memory. The records will not be eligible for garbage collection
276
+ * until the returned reference is disposed.
277
+ */
278
+ retain(operation: OperationDescriptor): Disposable;
279
+
280
+ /**
281
+ * Subscribe to changes to the results of a selector. The callback is called
282
+ * when `notify()` is called *and* records have been published that affect the
283
+ * selector results relative to the last `notify()`.
284
+ */
285
+ subscribe(
286
+ snapshot: Snapshot,
287
+ callback: (snapshot: Snapshot) => void,
288
+ ): Disposable;
289
+
290
+ /**
291
+ * The method should disable garbage collection until
292
+ * the returned reference is disposed.
293
+ */
294
+ holdGC(): Disposable;
295
+
296
+ /**
297
+ * Record a backup/snapshot of the current state of the store, including
298
+ * records and derived data such as fragment subscriptions.
299
+ * This state can be restored with restore().
300
+ */
301
+ snapshot(): void;
302
+
303
+ /**
304
+ * Reset the state of the store to the point that snapshot() was last called.
305
+ */
306
+ restore(): void;
307
+
308
+ /**
309
+ * Will return an opaque snapshot of the current invalidation state of
310
+ * the data ids that were provided.
311
+ */
312
+ lookupInvalidationState(dataIDs: $ReadOnlyArray<DataID>): InvalidationState;
313
+
314
+ /**
315
+ * Given the previous invalidation state for those
316
+ * ids, this function will return:
317
+ * - false, if the invalidation state for those ids is the same, meaning
318
+ * **it has not changed**
319
+ * - true, if the invalidation state for the given ids has changed
320
+ */
321
+ checkInvalidationState(previousInvalidationState: InvalidationState): boolean;
322
+
323
+ /**
324
+ * Will subscribe the provided callback to the invalidation state of the
325
+ * given data ids. Whenever the invalidation state for any of the provided
326
+ * ids changes, the callback will be called, and provide the latest
327
+ * invalidation state.
328
+ * Disposing of the returned disposable will remove the subscription.
329
+ */
330
+ subscribeToInvalidationState(
331
+ invalidationState: InvalidationState,
332
+ callback: () => void,
333
+ ): Disposable;
334
+ }
335
+
336
+ /**
337
+ * A type that accepts a callback and schedules it to run at some future time.
338
+ * By convention, implementations should not execute the callback immediately.
339
+ */
340
+ export type Scheduler = (() => void) => void;
341
+
342
+ /**
343
+ * An interface for imperatively getting/setting properties of a `Record`. This interface
344
+ * is designed to allow the appearance of direct Record manipulation while
345
+ * allowing different implementations that may e.g. create a changeset of
346
+ * the modifications.
347
+ */
348
+ export interface RecordProxy {
349
+ copyFieldsFrom(source: RecordProxy): void;
350
+ getDataID(): DataID;
351
+ getLinkedRecord(name: string, args?: ?Variables): ?RecordProxy;
352
+ getLinkedRecords(name: string, args?: ?Variables): ?Array<?RecordProxy>;
353
+ getOrCreateLinkedRecord(
354
+ name: string,
355
+ typeName: string,
356
+ args?: ?Variables,
357
+ ): RecordProxy;
358
+ getType(): string;
359
+ getValue(name: string, args?: ?Variables): mixed;
360
+ setLinkedRecord(
361
+ record: RecordProxy,
362
+ name: string,
363
+ args?: ?Variables,
364
+ ): RecordProxy;
365
+ setLinkedRecords(
366
+ records: Array<?RecordProxy>,
367
+ name: string,
368
+ args?: ?Variables,
369
+ ): RecordProxy;
370
+ setValue(value: mixed, name: string, args?: ?Variables): RecordProxy;
371
+ invalidateRecord(): void;
372
+ }
373
+
374
+ export interface ReadOnlyRecordProxy {
375
+ getDataID(): DataID;
376
+ getLinkedRecord(name: string, args?: ?Variables): ?RecordProxy;
377
+ getLinkedRecords(name: string, args?: ?Variables): ?Array<?RecordProxy>;
378
+ getType(): string;
379
+ getValue(name: string, args?: ?Variables): mixed;
380
+ }
381
+
382
+ /**
383
+ * An interface for imperatively getting/setting properties of a `RecordSource`. This interface
384
+ * is designed to allow the appearance of direct RecordSource manipulation while
385
+ * allowing different implementations that may e.g. create a changeset of
386
+ * the modifications.
387
+ */
388
+ export interface RecordSourceProxy {
389
+ create(dataID: DataID, typeName: string): RecordProxy;
390
+ delete(dataID: DataID): void;
391
+ get(dataID: DataID): ?RecordProxy;
392
+ getRoot(): RecordProxy;
393
+ invalidateStore(): void;
394
+ }
395
+
396
+ export interface ReadOnlyRecordSourceProxy {
397
+ get(dataID: DataID): ?ReadOnlyRecordProxy;
398
+ getRoot(): ReadOnlyRecordProxy;
399
+ }
400
+
401
+ /**
402
+ * Extends the RecordSourceProxy interface with methods for accessing the root
403
+ * fields of a Selector.
404
+ */
405
+ export interface RecordSourceSelectorProxy extends RecordSourceProxy {
406
+ getRootField(fieldName: string): ?RecordProxy;
407
+ getPluralRootField(fieldName: string): ?Array<?RecordProxy>;
408
+ invalidateStore(): void;
409
+ }
410
+
411
+ export type LogEvent =
412
+ | {|
413
+ +name: 'queryresource.fetch',
414
+ // ID of this query resource request and will be the same
415
+ // if there is an associated queryresource.retain event.
416
+ +resourceID: number,
417
+ +operation: OperationDescriptor,
418
+ // value from ProfilerContext
419
+ +profilerContext: mixed,
420
+ // FetchPolicy from relay-experimental
421
+ +fetchPolicy: string,
422
+ // RenderPolicy from relay-experimental
423
+ +renderPolicy: string,
424
+ +queryAvailability: OperationAvailability,
425
+ +shouldFetch: boolean,
426
+ |}
427
+ | {|
428
+ +name: 'queryresource.retain',
429
+ +resourceID: number,
430
+ // value from ProfilerContext
431
+ +profilerContext: mixed,
432
+ |}
433
+ | {|
434
+ +name: 'execute.info',
435
+ +transactionID: number,
436
+ +info: mixed,
437
+ |}
438
+ | {|
439
+ +name: 'execute.start',
440
+ +transactionID: number,
441
+ +params: RequestParameters,
442
+ +variables: Variables,
443
+ |}
444
+ | {|
445
+ +name: 'execute.next',
446
+ +transactionID: number,
447
+ +response: GraphQLResponse,
448
+ |}
449
+ | {|
450
+ +name: 'execute.error',
451
+ +transactionID: number,
452
+ +error: Error,
453
+ |}
454
+ | {|
455
+ +name: 'execute.complete',
456
+ +transactionID: number,
457
+ |}
458
+ | {|
459
+ +name: 'execute.unsubscribe',
460
+ +transactionID: number,
461
+ |}
462
+ | {|
463
+ +name: 'store.publish',
464
+ +source: RecordSource,
465
+ +optimistic: boolean,
466
+ |}
467
+ | {|
468
+ +name: 'store.snapshot',
469
+ |}
470
+ | {|
471
+ +name: 'store.restore',
472
+ |}
473
+ | {|
474
+ +name: 'store.gc',
475
+ +references: Set<DataID>,
476
+ |}
477
+ | {|
478
+ +name: 'store.notify.start',
479
+ |}
480
+ | {|
481
+ +name: 'store.notify.complete',
482
+ +updatedRecordIDs: UpdatedRecords,
483
+ +invalidatedRecordIDs: Set<DataID>,
484
+ |}
485
+ | {|
486
+ +name: 'entrypoint.root.consume',
487
+ +profilerContext: mixed,
488
+ +rootModuleID: string,
489
+ |};
490
+
491
+ export type LogFunction = LogEvent => void;
492
+ export type LogRequestInfoFunction = mixed => void;
493
+
494
+ /**
495
+ * The public API of Relay core. Represents an encapsulated environment with its
496
+ * own in-memory cache.
497
+ */
498
+ export interface IEnvironment {
499
+ /**
500
+ * Extra information attached to the environment instance
501
+ */
502
+ +options: mixed;
503
+
504
+ /**
505
+ * **UNSTABLE** Event based logging API thats scoped to the environment.
506
+ */
507
+ __log: LogFunction;
508
+
509
+ /**
510
+ * Determine if the operation can be resolved with data in the store (i.e. no
511
+ * fields are missing).
512
+ *
513
+ * Note that this operation effectively "executes" the selector against the
514
+ * cache and therefore takes time proportional to the size/complexity of the
515
+ * selector.
516
+ */
517
+ check(operation: OperationDescriptor): OperationAvailability;
518
+
519
+ /**
520
+ * Subscribe to changes to the results of a selector. The callback is called
521
+ * when data has been committed to the store that would cause the results of
522
+ * the snapshot's selector to change.
523
+ */
524
+ subscribe(
525
+ snapshot: Snapshot,
526
+ callback: (snapshot: Snapshot) => void,
527
+ ): Disposable;
528
+
529
+ /**
530
+ * Ensure that all the records necessary to fulfill the given selector are
531
+ * retained in-memory. The records will not be eligible for garbage collection
532
+ * until the returned reference is disposed.
533
+ */
534
+ retain(operation: OperationDescriptor): Disposable;
535
+
536
+ /**
537
+ * Apply an optimistic update to the environment. The mutation can be reverted
538
+ * by calling `dispose()` on the returned value.
539
+ */
540
+ applyUpdate(optimisticUpdate: OptimisticUpdateFunction): Disposable;
541
+
542
+ /**
543
+ * Apply an optimistic mutation response and/or updater. The mutation can be
544
+ * reverted by calling `dispose()` on the returned value.
545
+ */
546
+ applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable;
547
+
548
+ /**
549
+ * Commit an updater to the environment. This mutation cannot be reverted and
550
+ * should therefore not be used for optimistic updates. This is mainly
551
+ * intended for updating fields from client schema extensions.
552
+ */
553
+ commitUpdate(updater: StoreUpdater): void;
554
+
555
+ /**
556
+ * Commit a payload to the environment using the given operation selector.
557
+ */
558
+ commitPayload(
559
+ operationDescriptor: OperationDescriptor,
560
+ payload: PayloadData,
561
+ ): void;
562
+
563
+ /**
564
+ * Get the environment's internal Network.
565
+ */
566
+ getNetwork(): INetwork;
567
+
568
+ /**
569
+ * Get the environment's internal Store.
570
+ */
571
+ getStore(): Store;
572
+
573
+ /**
574
+ * Returns the environment specific OperationTracker.
575
+ */
576
+ getOperationTracker(): RelayOperationTracker;
577
+
578
+ /**
579
+ * EXPERIMENTAL
580
+ * Returns the default render policy to use when rendering a query
581
+ * that uses Relay Hooks.
582
+ */
583
+ UNSTABLE_getDefaultRenderPolicy(): RenderPolicy;
584
+
585
+ /**
586
+ * Read the results of a selector from in-memory records in the store.
587
+ */
588
+ lookup(selector: SingularReaderSelector): Snapshot;
589
+
590
+ /**
591
+ * Send a query to the server with Observer semantics: one or more
592
+ * responses may be returned (via `next`) over time followed by either
593
+ * the request completing (`completed`) or an error (`error`).
594
+ *
595
+ * Networks/servers that support subscriptions may choose to hold the
596
+ * subscription open indefinitely such that `complete` is not called.
597
+ *
598
+ * Note: Observables are lazy, so calling this method will do nothing until
599
+ * the result is subscribed to: environment.execute({...}).subscribe({...}).
600
+ */
601
+ execute(config: {|
602
+ operation: OperationDescriptor,
603
+ updater?: ?SelectorStoreUpdater,
604
+ |}): RelayObservable<GraphQLResponse>;
605
+
606
+ /**
607
+ * Returns an Observable of GraphQLResponse resulting from executing the
608
+ * provided Mutation operation, the result of which is then normalized and
609
+ * committed to the publish queue along with an optional optimistic response
610
+ * or updater.
611
+ *
612
+ * Note: Observables are lazy, so calling this method will do nothing until
613
+ * the result is subscribed to:
614
+ * environment.executeMutation({...}).subscribe({...}).
615
+ */
616
+ executeMutation({|
617
+ operation: OperationDescriptor,
618
+ optimisticUpdater?: ?SelectorStoreUpdater,
619
+ optimisticResponse?: ?Object,
620
+ updater?: ?SelectorStoreUpdater,
621
+ uploadables?: ?UploadableMap,
622
+ |}): RelayObservable<GraphQLResponse>;
623
+
624
+ /**
625
+ * Returns an Observable of GraphQLResponse resulting from executing the
626
+ * provided Query or Subscription operation responses, the result of which is
627
+ * then normalized and comitted to the publish queue.
628
+ *
629
+ * Note: Observables are lazy, so calling this method will do nothing until
630
+ * the result is subscribed to:
631
+ * environment.executeWithSource({...}).subscribe({...}).
632
+ */
633
+ executeWithSource({|
634
+ operation: OperationDescriptor,
635
+ source: RelayObservable<GraphQLResponse>,
636
+ |}): RelayObservable<GraphQLResponse>;
637
+
638
+ /**
639
+ * Returns true if a request is currently "active", meaning it's currently
640
+ * actively receiving payloads or downloading modules, and has not received
641
+ * a final payload yet. Note that a request might still be pending (or "in flight")
642
+ * without actively receiving payload, for example a live query or an
643
+ * active GraphQL subscription
644
+ */
645
+ isRequestActive(requestIdentifier: string): boolean;
646
+
647
+ /**
648
+ * Returns true if the environment is for use during server side rendering.
649
+ * functions like getQueryResource key off of this in order to determine
650
+ * whether we need to set up certain caches and timeout's.
651
+ */
652
+ isServer(): boolean;
653
+
654
+ /**
655
+ * Called by Relay when it encounters a missing field that has been annotated
656
+ * with `@required(action: LOG)`.
657
+ */
658
+ requiredFieldLogger: RequiredFieldLogger;
659
+ }
660
+
661
+ /**
662
+ * The partial shape of an object with a '...Fragment @module(name: "...")'
663
+ * selection
664
+ */
665
+ export type ModuleImportPointer = {
666
+ +__fragmentPropName: ?string,
667
+ +__module_component: mixed,
668
+ +$fragmentRefs: mixed,
669
+ ...
670
+ };
671
+
672
+ /**
673
+ * A map of records affected by an update operation.
674
+ */
675
+ export type UpdatedRecords = {[dataID: DataID]: boolean, ...};
676
+
677
+ /**
678
+ * A function that updates a store (via a proxy) given the results of a "handle"
679
+ * field payload.
680
+ */
681
+ export type Handler = {
682
+ update: (store: RecordSourceProxy, fieldPayload: HandleFieldPayload) => void,
683
+ ...
684
+ };
685
+
686
+ /**
687
+ * A payload that is used to initialize or update a "handle" field with
688
+ * information from the server.
689
+ */
690
+ export type HandleFieldPayload = {|
691
+ // The arguments that were fetched.
692
+ +args: Variables,
693
+ // The __id of the record containing the source/handle field.
694
+ +dataID: DataID,
695
+ // The (storage) key at which the original server data was written.
696
+ +fieldKey: string,
697
+ // The name of the handle.
698
+ +handle: string,
699
+ // The (storage) key at which the handle's data should be written by the
700
+ // handler.
701
+ +handleKey: string,
702
+ // The arguments applied to the handle
703
+ +handleArgs: Variables,
704
+ |};
705
+
706
+ /**
707
+ * A payload that represents data necessary to process the results of an object
708
+ * with a `@module` fragment spread, or a Flight field's:
709
+ *
710
+ * ## @module Fragment Spread
711
+ * - data: The GraphQL response value for the @match field.
712
+ * - dataID: The ID of the store object linked to by the @match field.
713
+ * - operationReference: A reference to a generated module containing the
714
+ * SplitOperation with which to normalize the field's `data`.
715
+ * - variables: Query variables.
716
+ * - typeName: the type that matched.
717
+ *
718
+ * The dataID, variables, and fragmentName can be used to create a Selector
719
+ * which can in turn be used to normalize and publish the data. The dataID and
720
+ * typeName can also be used to construct a root record for normalization.
721
+ *
722
+ * ## Flight fields
723
+ * In Flight, data for additional components rendered by the requested server
724
+ * component are included in the response returned by a Flight compliant server.
725
+ *
726
+ * - data: Data used by additional components rendered by the server component
727
+ * being requested.
728
+ * - dataID: For Flight fields, this should always be ROOT_ID. This is because
729
+ * the query data isn't relative to the parent record–it's root data.
730
+ * - operationReference: The query's module that will be later used by an
731
+ * operation loader.
732
+ * - variables: The query's variables.
733
+ * - typeName: For Flight fields, this should always be ROOT_TYPE. This is
734
+ * because the query data isn't relative to the parent record–it's
735
+ * root data.
736
+ */
737
+ export type ModuleImportPayload = {|
738
+ +data: PayloadData,
739
+ +dataID: DataID,
740
+ +operationReference: mixed,
741
+ +path: $ReadOnlyArray<string>,
742
+ +typeName: string,
743
+ +variables: Variables,
744
+ |};
745
+
746
+ /**
747
+ * Data emitted after processing a Defer or Stream node during normalization
748
+ * that describes how to process the corresponding response chunk when it
749
+ * arrives.
750
+ */
751
+ export type DeferPlaceholder = {|
752
+ +kind: 'defer',
753
+ +data: PayloadData,
754
+ +label: string,
755
+ +path: $ReadOnlyArray<string>,
756
+ +selector: NormalizationSelector,
757
+ +typeName: string,
758
+ |};
759
+ export type StreamPlaceholder = {|
760
+ +kind: 'stream',
761
+ +label: string,
762
+ +path: $ReadOnlyArray<string>,
763
+ +parentID: DataID,
764
+ +node: NormalizationSelectableNode,
765
+ +variables: Variables,
766
+ |};
767
+ export type IncrementalDataPlaceholder = DeferPlaceholder | StreamPlaceholder;
768
+
769
+ /**
770
+ * A user-supplied object to load a generated operation (SplitOperation or
771
+ * ConcreteRequest) AST by a module reference. The exact format of a module
772
+ * reference is left to the application, but it must be a plain JavaScript value
773
+ * (string, number, or object/array of same).
774
+ */
775
+ export type OperationLoader = {|
776
+ /**
777
+ * Synchronously load an operation, returning either the node or null if it
778
+ * cannot be resolved synchronously.
779
+ */
780
+ get(reference: mixed): ?NormalizationRootNode,
781
+
782
+ /**
783
+ * Asynchronously load an operation.
784
+ */
785
+ load(reference: mixed): Promise<?NormalizationRootNode>,
786
+ |};
787
+
788
+ /**
789
+ * A function that receives a proxy over the store and may trigger side-effects
790
+ * (indirectly) by calling `set*` methods on the store or its record proxies.
791
+ */
792
+ export type StoreUpdater = (store: RecordSourceProxy) => void;
793
+
794
+ /**
795
+ * Similar to StoreUpdater, but accepts a proxy tied to a specific selector in
796
+ * order to easily access the root fields of a query/mutation as well as a
797
+ * second argument of the response object of the mutation.
798
+ */
799
+ export type SelectorStoreUpdater = (
800
+ store: RecordSourceSelectorProxy,
801
+ // Actually SelectorData, but mixed is inconvenient to access deeply in
802
+ // product code.
803
+ data: $FlowFixMe,
804
+ ) => void;
805
+
806
+ /**
807
+ * A set of configs that can be used to apply an optimistic update into the
808
+ * store.
809
+ */
810
+ export type OptimisticUpdate =
811
+ | OptimisticUpdateFunction
812
+ | OptimisticUpdateRelayPayload;
813
+
814
+ export type OptimisticUpdateFunction = {|
815
+ +storeUpdater: StoreUpdater,
816
+ |};
817
+
818
+ export type OptimisticUpdateRelayPayload = {|
819
+ +operation: OperationDescriptor,
820
+ +payload: RelayResponsePayload,
821
+ +updater: ?SelectorStoreUpdater,
822
+ |};
823
+
824
+ export type OptimisticResponseConfig = {|
825
+ +operation: OperationDescriptor,
826
+ +response: ?PayloadData,
827
+ +updater: ?SelectorStoreUpdater,
828
+ |};
829
+
830
+ /**
831
+ * A set of handlers that can be used to provide substitute data for missing
832
+ * fields when reading a selector from a source.
833
+ */
834
+ export type MissingFieldHandler =
835
+ | {|
836
+ kind: 'scalar',
837
+ handle: (
838
+ field: NormalizationScalarField,
839
+ record: ?Record,
840
+ args: Variables,
841
+ store: ReadOnlyRecordSourceProxy,
842
+ ) => mixed,
843
+ |}
844
+ | {|
845
+ kind: 'linked',
846
+ handle: (
847
+ field: NormalizationLinkedField,
848
+ record: ?Record,
849
+ args: Variables,
850
+ store: ReadOnlyRecordSourceProxy,
851
+ ) => ?DataID,
852
+ |}
853
+ | {|
854
+ kind: 'pluralLinked',
855
+ handle: (
856
+ field: NormalizationLinkedField,
857
+ record: ?Record,
858
+ args: Variables,
859
+ store: ReadOnlyRecordSourceProxy,
860
+ ) => ?Array<?DataID>,
861
+ |};
862
+
863
+ /**
864
+ * A handler for events related to @required fields. Currently reports missing
865
+ * fields with either `action: LOG` or `action: THROW`.
866
+ */
867
+ export type RequiredFieldLogger = (
868
+ | {|
869
+ +kind: 'missing_field.log',
870
+ +owner: string,
871
+ +fieldPath: string,
872
+ |}
873
+ | {|
874
+ +kind: 'missing_field.throw',
875
+ +owner: string,
876
+ +fieldPath: string,
877
+ |},
878
+ ) => void;
879
+
880
+ /**
881
+ * The results of normalizing a query.
882
+ */
883
+ export type RelayResponsePayload = {|
884
+ +errors: ?Array<PayloadError>,
885
+ +fieldPayloads: ?Array<HandleFieldPayload>,
886
+ +incrementalPlaceholders: ?Array<IncrementalDataPlaceholder>,
887
+ +moduleImportPayloads: ?Array<ModuleImportPayload>,
888
+ +source: MutableRecordSource,
889
+ +isFinal: boolean,
890
+ |};
891
+
892
+ /**
893
+ * Public interface for Publish Queue
894
+ */
895
+ export interface PublishQueue {
896
+ /**
897
+ * Schedule applying an optimistic updates on the next `run()`.
898
+ */
899
+ applyUpdate(updater: OptimisticUpdate): void;
900
+
901
+ /**
902
+ * Schedule reverting an optimistic updates on the next `run()`.
903
+ */
904
+ revertUpdate(updater: OptimisticUpdate): void;
905
+
906
+ /**
907
+ * Schedule a revert of all optimistic updates on the next `run()`.
908
+ */
909
+ revertAll(): void;
910
+
911
+ /**
912
+ * Schedule applying a payload to the store on the next `run()`.
913
+ */
914
+ commitPayload(
915
+ operation: OperationDescriptor,
916
+ payload: RelayResponsePayload,
917
+ updater?: ?SelectorStoreUpdater,
918
+ ): void;
919
+
920
+ /**
921
+ * Schedule an updater to mutate the store on the next `run()` typically to
922
+ * update client schema fields.
923
+ */
924
+ commitUpdate(updater: StoreUpdater): void;
925
+
926
+ /**
927
+ * Schedule a publish to the store from the provided source on the next
928
+ * `run()`. As an example, to update the store with substituted fields that
929
+ * are missing in the store.
930
+ */
931
+ commitSource(source: RecordSource): void;
932
+
933
+ /**
934
+ * Execute all queued up operations from the other public methods.
935
+ * Optionally provide an OperationDescriptor indicating the source operation
936
+ * that was being processed to produce this run.
937
+ */
938
+ run(sourceOperation?: OperationDescriptor): $ReadOnlyArray<RequestDescriptor>;
939
+ }
940
+
941
+ /**
942
+ * ReactFlightDOMRelayClient processes a ReactFlightServerTree into a
943
+ * ReactFlightClientResponse object. readRoot() can suspend.
944
+ */
945
+ export type ReactFlightClientResponse = {readRoot: () => mixed, ...};
946
+
947
+ export type ReactFlightReachableQuery = {|
948
+ +module: mixed,
949
+ +variables: Variables,
950
+ |};
951
+
952
+ /**
953
+ * A user-supplied function that takes a ReactFlightServerTree, and deserializes
954
+ * it into a ReactFlightClientResponse object.
955
+ */
956
+ export type ReactFlightPayloadDeserializer = (
957
+ tree: ReactFlightServerTree,
958
+ ) => ReactFlightClientResponse;