relay-runtime 11.0.0-rc.0 → 12.0.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.
- package/handlers/connection/ConnectionHandler.js.flow +7 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +20 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +12 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +15 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +148 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +406 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -0
- package/lib/mutations/RelayRecordProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceMutator.js +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +7 -2
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +5 -2
- package/lib/mutations/validateMutation.js +39 -17
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayObservable.js +3 -1
- package/lib/network/RelayQueryResponseCache.js +20 -3
- package/lib/network/wrapNetworkWithLogObserver.js +78 -0
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +1 -1
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/store/DataChecker.js +132 -50
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +524 -187
- package/lib/store/RelayConcreteVariables.js +29 -4
- package/lib/store/RelayModernEnvironment.js +137 -220
- package/lib/store/RelayModernFragmentSpecResolver.js +49 -23
- package/lib/store/RelayModernRecord.js +36 -2
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +53 -22
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +30 -8
- package/lib/store/RelayReader.js +177 -29
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +53 -28
- package/lib/store/RelayResponseNormalizer.js +247 -108
- package/lib/store/RelayStoreReactFlightUtils.js +7 -11
- package/lib/store/RelayStoreSubscriptions.js +8 -5
- package/lib/store/RelayStoreUtils.js +10 -4
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createRelayContext.js +2 -2
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +32 -6
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayFeatureFlags.js +5 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +67 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +43 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +217 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +485 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +245 -0
- package/multi-actor-environment/index.js.flow +27 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
- package/mutations/commitMutation.js.flow +3 -1
- package/mutations/validateMutation.js.flow +42 -16
- package/network/RelayNetworkTypes.js.flow +17 -8
- package/network/RelayObservable.js.flow +2 -0
- package/network/RelayQueryResponseCache.js.flow +31 -17
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +3 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +5 -1
- package/store/DataChecker.js.flow +148 -44
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +578 -237
- package/store/RelayConcreteVariables.js.flow +31 -1
- package/store/RelayModernEnvironment.js.flow +132 -220
- package/store/RelayModernFragmentSpecResolver.js.flow +40 -14
- package/store/RelayModernOperationDescriptor.js.flow +9 -3
- package/store/RelayModernRecord.js.flow +49 -0
- package/store/RelayModernStore.js.flow +57 -17
- package/store/RelayOperationTracker.js.flow +56 -34
- package/store/RelayPublishQueue.js.flow +37 -11
- package/store/RelayReader.js.flow +186 -27
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +51 -21
- package/store/RelayResponseNormalizer.js.flow +251 -67
- package/store/RelayStoreReactFlightUtils.js.flow +6 -9
- package/store/RelayStoreSubscriptions.js.flow +10 -3
- package/store/RelayStoreTypes.js.flow +144 -21
- package/store/RelayStoreUtils.js.flow +19 -4
- package/store/ResolverCache.js.flow +247 -0
- package/store/ResolverFragments.js.flow +128 -0
- package/store/createRelayContext.js.flow +1 -1
- package/store/defaultGetDataID.js.flow +3 -1
- package/subscription/requestSubscription.js.flow +43 -8
- package/util/NormalizationNode.js.flow +16 -3
- package/util/ReaderNode.js.flow +29 -2
- package/util/RelayConcreteNode.js.flow +3 -0
- package/util/RelayFeatureFlags.js.flow +10 -6
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +7 -6
- package/util/RelayRuntimeTypes.js.flow +4 -2
- package/util/deepFreeze.js.flow +2 -1
- package/util/getPaginationMetadata.js.flow +74 -0
- package/util/getPaginationVariables.js.flow +112 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +80 -0
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -22,9 +22,9 @@ const cloneRelayHandleSourceField = require('./cloneRelayHandleSourceField');
|
|
|
22
22
|
const getOperation = require('../util/getOperation');
|
|
23
23
|
const invariant = require('invariant');
|
|
24
24
|
|
|
25
|
+
const {getLocalVariables} = require('./RelayConcreteVariables');
|
|
25
26
|
const {generateTypeID} = require('./TypeID');
|
|
26
27
|
|
|
27
|
-
import type {ReactFlightPayloadQuery} from '../network/RelayNetworkTypes';
|
|
28
28
|
import type {
|
|
29
29
|
NormalizationFlightField,
|
|
30
30
|
NormalizationLinkedField,
|
|
@@ -39,10 +39,13 @@ import type {
|
|
|
39
39
|
OperationLoader,
|
|
40
40
|
Record,
|
|
41
41
|
RecordSource,
|
|
42
|
+
ReactFlightReachableExecutableDefinitions,
|
|
42
43
|
} from './RelayStoreTypes';
|
|
43
44
|
|
|
44
45
|
const {
|
|
46
|
+
ACTOR_CHANGE,
|
|
45
47
|
CONDITION,
|
|
48
|
+
CLIENT_COMPONENT,
|
|
46
49
|
CLIENT_EXTENSION,
|
|
47
50
|
DEFER,
|
|
48
51
|
FLIGHT_FIELD,
|
|
@@ -63,6 +66,7 @@ function mark(
|
|
|
63
66
|
selector: NormalizationSelector,
|
|
64
67
|
references: DataIDSet,
|
|
65
68
|
operationLoader: ?OperationLoader,
|
|
69
|
+
shouldProcessClientComponents: ?boolean,
|
|
66
70
|
): void {
|
|
67
71
|
const {dataID, node, variables} = selector;
|
|
68
72
|
const marker = new RelayReferenceMarker(
|
|
@@ -70,6 +74,7 @@ function mark(
|
|
|
70
74
|
variables,
|
|
71
75
|
references,
|
|
72
76
|
operationLoader,
|
|
77
|
+
shouldProcessClientComponents,
|
|
73
78
|
);
|
|
74
79
|
marker.mark(node, dataID);
|
|
75
80
|
}
|
|
@@ -83,18 +88,21 @@ class RelayReferenceMarker {
|
|
|
83
88
|
_recordSource: RecordSource;
|
|
84
89
|
_references: DataIDSet;
|
|
85
90
|
_variables: Variables;
|
|
91
|
+
_shouldProcessClientComponents: ?boolean;
|
|
86
92
|
|
|
87
93
|
constructor(
|
|
88
94
|
recordSource: RecordSource,
|
|
89
95
|
variables: Variables,
|
|
90
96
|
references: DataIDSet,
|
|
91
97
|
operationLoader: ?OperationLoader,
|
|
98
|
+
shouldProcessClientComponents: ?boolean,
|
|
92
99
|
) {
|
|
93
100
|
this._operationLoader = operationLoader ?? null;
|
|
94
101
|
this._operationName = null;
|
|
95
102
|
this._recordSource = recordSource;
|
|
96
103
|
this._references = references;
|
|
97
104
|
this._variables = variables;
|
|
105
|
+
this._shouldProcessClientComponents = shouldProcessClientComponents;
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
mark(node: NormalizationNode, dataID: DataID): void {
|
|
@@ -119,6 +127,7 @@ class RelayReferenceMarker {
|
|
|
119
127
|
'RelayReferenceMarker(): Undefined variable `%s`.',
|
|
120
128
|
name,
|
|
121
129
|
);
|
|
130
|
+
// $FlowFixMe[cannot-write]
|
|
122
131
|
return this._variables[name];
|
|
123
132
|
}
|
|
124
133
|
|
|
@@ -129,6 +138,10 @@ class RelayReferenceMarker {
|
|
|
129
138
|
selections.forEach(selection => {
|
|
130
139
|
/* eslint-disable no-fallthrough */
|
|
131
140
|
switch (selection.kind) {
|
|
141
|
+
case ACTOR_CHANGE:
|
|
142
|
+
// TODO: T89695151 Support multi-actor record sources in RelayReferenceMarker.js
|
|
143
|
+
this._traverseLink(selection.linkedField, record);
|
|
144
|
+
break;
|
|
132
145
|
case LINKED_FIELD:
|
|
133
146
|
if (selection.plural) {
|
|
134
147
|
this._traversePluralLink(selection, record);
|
|
@@ -137,7 +150,9 @@ class RelayReferenceMarker {
|
|
|
137
150
|
}
|
|
138
151
|
break;
|
|
139
152
|
case CONDITION:
|
|
140
|
-
const conditionValue =
|
|
153
|
+
const conditionValue = Boolean(
|
|
154
|
+
this._getVariableValue(selection.condition),
|
|
155
|
+
);
|
|
141
156
|
if (conditionValue === selection.passingValue) {
|
|
142
157
|
this._traverseSelections(selection.selections, record);
|
|
143
158
|
}
|
|
@@ -148,18 +163,22 @@ class RelayReferenceMarker {
|
|
|
148
163
|
if (typeName != null && typeName === selection.type) {
|
|
149
164
|
this._traverseSelections(selection.selections, record);
|
|
150
165
|
}
|
|
151
|
-
} else
|
|
166
|
+
} else {
|
|
152
167
|
const typeName = RelayModernRecord.getType(record);
|
|
153
168
|
const typeID = generateTypeID(typeName);
|
|
154
169
|
this._references.add(typeID);
|
|
155
170
|
this._traverseSelections(selection.selections, record);
|
|
156
|
-
} else {
|
|
157
|
-
this._traverseSelections(selection.selections, record);
|
|
158
171
|
}
|
|
159
172
|
break;
|
|
160
|
-
// $FlowFixMe[incompatible-type]
|
|
161
173
|
case FRAGMENT_SPREAD:
|
|
174
|
+
const prevVariables = this._variables;
|
|
175
|
+
this._variables = getLocalVariables(
|
|
176
|
+
this._variables,
|
|
177
|
+
selection.fragment.argumentDefinitions,
|
|
178
|
+
selection.args,
|
|
179
|
+
);
|
|
162
180
|
this._traverseSelections(selection.fragment.selections, record);
|
|
181
|
+
this._variables = prevVariables;
|
|
163
182
|
break;
|
|
164
183
|
case LINKED_HANDLE:
|
|
165
184
|
// The selections for a "handle" field are the same as those of the
|
|
@@ -190,11 +209,9 @@ class RelayReferenceMarker {
|
|
|
190
209
|
case SCALAR_HANDLE:
|
|
191
210
|
break;
|
|
192
211
|
case TYPE_DISCRIMINATOR: {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this._references.add(typeID);
|
|
197
|
-
}
|
|
212
|
+
const typeName = RelayModernRecord.getType(record);
|
|
213
|
+
const typeID = generateTypeID(typeName);
|
|
214
|
+
this._references.add(typeID);
|
|
198
215
|
break;
|
|
199
216
|
}
|
|
200
217
|
case MODULE_IMPORT:
|
|
@@ -210,6 +227,12 @@ class RelayReferenceMarker {
|
|
|
210
227
|
throw new Error('Flight fields are not yet supported.');
|
|
211
228
|
}
|
|
212
229
|
break;
|
|
230
|
+
case CLIENT_COMPONENT:
|
|
231
|
+
if (this._shouldProcessClientComponents === false) {
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
this._traverseSelections(selection.fragment.selections, record);
|
|
235
|
+
break;
|
|
213
236
|
default:
|
|
214
237
|
(selection: empty);
|
|
215
238
|
invariant(
|
|
@@ -240,8 +263,15 @@ class RelayReferenceMarker {
|
|
|
240
263
|
}
|
|
241
264
|
const normalizationRootNode = operationLoader.get(operationReference);
|
|
242
265
|
if (normalizationRootNode != null) {
|
|
243
|
-
const
|
|
244
|
-
this.
|
|
266
|
+
const operation = getOperation(normalizationRootNode);
|
|
267
|
+
const prevVariables = this._variables;
|
|
268
|
+
this._variables = getLocalVariables(
|
|
269
|
+
this._variables,
|
|
270
|
+
operation.argumentDefinitions,
|
|
271
|
+
moduleImport.args,
|
|
272
|
+
);
|
|
273
|
+
this._traverseSelections(operation.selections, record);
|
|
274
|
+
this._variables = prevVariables;
|
|
245
275
|
}
|
|
246
276
|
// Otherwise, if the operation is not available, we assume that the data
|
|
247
277
|
// cannot have been processed yet and therefore isn't in the store to
|
|
@@ -286,12 +316,12 @@ class RelayReferenceMarker {
|
|
|
286
316
|
return;
|
|
287
317
|
}
|
|
288
318
|
|
|
289
|
-
const
|
|
319
|
+
const reachableExecutableDefinitions = RelayModernRecord.getValue(
|
|
290
320
|
reactFlightClientResponseRecord,
|
|
291
|
-
RelayStoreReactFlightUtils.
|
|
321
|
+
RelayStoreReactFlightUtils.REACT_FLIGHT_EXECUTABLE_DEFINITIONS_STORAGE_KEY,
|
|
292
322
|
);
|
|
293
323
|
|
|
294
|
-
if (!Array.isArray(
|
|
324
|
+
if (!Array.isArray(reachableExecutableDefinitions)) {
|
|
295
325
|
return;
|
|
296
326
|
}
|
|
297
327
|
|
|
@@ -301,13 +331,13 @@ class RelayReferenceMarker {
|
|
|
301
331
|
'DataChecker: Expected an operationLoader to be configured when using ' +
|
|
302
332
|
'React Flight',
|
|
303
333
|
);
|
|
304
|
-
// In Flight, the variables that are in scope for reachable
|
|
305
|
-
// the same as what's in scope for the outer query.
|
|
334
|
+
// In Flight, the variables that are in scope for reachable executable
|
|
335
|
+
// definitions aren't the same as what's in scope for the outer query.
|
|
306
336
|
const prevVariables = this._variables;
|
|
307
337
|
// $FlowFixMe[incompatible-cast]
|
|
308
|
-
for (const
|
|
309
|
-
this._variables =
|
|
310
|
-
const operationReference =
|
|
338
|
+
for (const definition of (reachableExecutableDefinitions: Array<ReactFlightReachableExecutableDefinitions>)) {
|
|
339
|
+
this._variables = definition.variables;
|
|
340
|
+
const operationReference = definition.module;
|
|
311
341
|
const normalizationRootNode = operationLoader.get(operationReference);
|
|
312
342
|
if (normalizationRootNode != null) {
|
|
313
343
|
const operation = getOperation(normalizationRootNode);
|