relay-runtime 11.0.1 → 13.0.0-rc.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/handlers/RelayDefaultHandlerProvider.js.flow +2 -2
- package/handlers/connection/ConnectionHandler.js.flow +8 -17
- package/handlers/connection/MutationHandlers.js.flow +7 -11
- package/index.js +1 -1
- package/index.js.flow +60 -36
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +13 -19
- package/lib/handlers/connection/MutationHandlers.js +4 -7
- package/lib/index.js +58 -43
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +152 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +419 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -0
- package/lib/mutations/RelayDeclarativeMutationConfig.js +4 -1
- package/lib/mutations/RelayRecordProxy.js +3 -2
- package/lib/mutations/RelayRecordSourceMutator.js +3 -2
- package/lib/mutations/RelayRecordSourceProxy.js +12 -4
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +18 -5
- package/lib/mutations/applyOptimisticMutation.js +6 -6
- package/lib/mutations/commitMutation.js +14 -10
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +238 -0
- package/lib/mutations/validateMutation.js +10 -5
- package/lib/network/ConvertToExecuteFunction.js +2 -1
- package/lib/network/RelayNetwork.js +3 -2
- package/lib/network/RelayQueryResponseCache.js +21 -5
- package/lib/network/wrapNetworkWithLogObserver.js +79 -0
- package/lib/query/GraphQLTag.js +3 -2
- package/lib/query/fetchQuery.js +6 -5
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +2 -1
- package/lib/store/ClientID.js +7 -1
- package/lib/store/DataChecker.js +123 -54
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +518 -200
- package/lib/store/RelayConcreteVariables.js +26 -8
- package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
- package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
- package/lib/store/RelayModernEnvironment.js +175 -240
- package/lib/store/RelayModernFragmentSpecResolver.js +52 -26
- package/lib/store/RelayModernOperationDescriptor.js +2 -1
- package/lib/store/RelayModernRecord.js +47 -12
- package/lib/store/RelayModernSelector.js +14 -8
- package/lib/store/RelayModernStore.js +56 -28
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +41 -13
- package/lib/store/RelayReader.js +288 -48
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +34 -22
- package/lib/store/RelayResponseNormalizer.js +211 -110
- package/lib/store/RelayStoreReactFlightUtils.js +4 -10
- package/lib/store/RelayStoreSubscriptions.js +14 -9
- package/lib/store/RelayStoreUtils.js +12 -7
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +61 -0
- package/lib/store/cloneRelayHandleSourceField.js +5 -4
- package/lib/store/cloneRelayScalarHandleSourceField.js +5 -4
- package/lib/store/createRelayContext.js +4 -2
- package/lib/store/readInlineData.js +6 -2
- package/lib/subscription/requestSubscription.js +34 -25
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayFeatureFlags.js +10 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/RelayRuntimeTypes.js +0 -6
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/getFragmentIdentifier.js +15 -7
- package/lib/util/getOperation.js +2 -1
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +66 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +2 -2
- package/lib/util/getRequestIdentifier.js +2 -2
- 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 +225 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +506 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +261 -0
- package/multi-actor-environment/index.js.flow +26 -0
- package/mutations/RelayDeclarativeMutationConfig.js.flow +32 -26
- package/mutations/RelayRecordProxy.js.flow +4 -5
- package/mutations/RelayRecordSourceMutator.js.flow +4 -6
- package/mutations/RelayRecordSourceProxy.js.flow +19 -10
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +22 -7
- package/mutations/applyOptimisticMutation.js.flow +13 -14
- package/mutations/commitLocalUpdate.js.flow +1 -1
- package/mutations/commitMutation.js.flow +35 -46
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +309 -0
- package/mutations/validateMutation.js.flow +26 -16
- package/network/ConvertToExecuteFunction.js.flow +2 -2
- package/network/RelayNetwork.js.flow +4 -5
- package/network/RelayNetworkTypes.js.flow +5 -4
- package/network/RelayObservable.js.flow +1 -1
- package/network/RelayQueryResponseCache.js.flow +34 -21
- package/network/wrapNetworkWithLogObserver.js.flow +100 -0
- package/package.json +3 -2
- package/query/GraphQLTag.js.flow +9 -9
- package/query/PreloadableQueryRegistry.js.flow +2 -1
- package/query/fetchQuery.js.flow +11 -13
- package/query/fetchQueryInternal.js.flow +6 -9
- package/query/fetchQuery_DEPRECATED.js.flow +6 -6
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +14 -3
- package/store/DataChecker.js.flow +141 -59
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +605 -303
- package/store/RelayConcreteVariables.js.flow +27 -8
- package/store/RelayExperimentalGraphResponseHandler.js.flow +124 -0
- package/store/RelayExperimentalGraphResponseTransform.js.flow +475 -0
- package/store/RelayModernEnvironment.js.flow +173 -240
- package/store/RelayModernFragmentSpecResolver.js.flow +55 -31
- package/store/RelayModernOperationDescriptor.js.flow +12 -7
- package/store/RelayModernRecord.js.flow +67 -11
- package/store/RelayModernSelector.js.flow +24 -14
- package/store/RelayModernStore.js.flow +66 -36
- package/store/RelayOperationTracker.js.flow +59 -43
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +79 -34
- package/store/RelayReader.js.flow +351 -73
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +40 -26
- package/store/RelayResponseNormalizer.js.flow +258 -99
- package/store/RelayStoreReactFlightUtils.js.flow +4 -11
- package/store/RelayStoreSubscriptions.js.flow +19 -11
- package/store/RelayStoreTypes.js.flow +209 -43
- package/store/RelayStoreUtils.js.flow +24 -11
- package/store/ResolverCache.js.flow +249 -0
- package/store/ResolverFragments.js.flow +121 -0
- package/store/StoreInspector.js.flow +2 -2
- package/store/TypeID.js.flow +1 -1
- package/store/ViewerPattern.js.flow +2 -2
- package/store/cloneRelayHandleSourceField.js.flow +5 -6
- package/store/cloneRelayScalarHandleSourceField.js.flow +5 -6
- package/store/createFragmentSpecResolver.js.flow +3 -4
- package/store/createRelayContext.js.flow +3 -3
- package/store/normalizeRelayPayload.js.flow +6 -7
- package/store/readInlineData.js.flow +7 -8
- package/subscription/requestSubscription.js.flow +53 -41
- package/util/NormalizationNode.js.flow +10 -3
- package/util/ReaderNode.js.flow +38 -2
- package/util/RelayConcreteNode.js.flow +5 -0
- package/util/RelayFeatureFlags.js.flow +24 -10
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +9 -9
- package/util/RelayRuntimeTypes.js.flow +72 -3
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +3 -3
- package/util/getFragmentIdentifier.js.flow +27 -15
- package/util/getOperation.js.flow +2 -2
- package/util/getPaginationMetadata.js.flow +72 -0
- package/util/getPaginationVariables.js.flow +108 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +79 -0
- package/util/getRelayHandleKey.js.flow +1 -2
- package/util/getRequestIdentifier.js.flow +3 -3
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +1 -0
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/resolveImmediate.js.flow +1 -1
- 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
|
@@ -12,17 +12,83 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
16
|
+
import type {RecordState} from './RelayRecordState';
|
|
17
|
+
import type {
|
|
18
|
+
MutableRecordSource,
|
|
19
|
+
Record,
|
|
20
|
+
RecordObjectMap,
|
|
21
|
+
} from './RelayStoreTypes';
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
const RelayRecordState = require('./RelayRecordState');
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
const {EXISTENT, NONEXISTENT, UNKNOWN} = RelayRecordState;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* An implementation of the `MutableRecordSource` interface (defined in
|
|
29
|
+
* `RelayStoreTypes`) that holds all records in memory (JS Map).
|
|
30
|
+
*/
|
|
31
|
+
class RelayRecordSource implements MutableRecordSource {
|
|
32
|
+
_records: Map<DataID, ?Record>;
|
|
33
|
+
|
|
34
|
+
constructor(records?: RecordObjectMap) {
|
|
35
|
+
this._records = new Map();
|
|
36
|
+
if (records != null) {
|
|
37
|
+
Object.keys(records).forEach(key => {
|
|
38
|
+
this._records.set(key, records[key]);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
22
41
|
}
|
|
23
42
|
|
|
24
43
|
static create(records?: RecordObjectMap): MutableRecordSource {
|
|
25
|
-
return new
|
|
44
|
+
return new RelayRecordSource(records);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
clear(): void {
|
|
48
|
+
this._records = new Map();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
delete(dataID: DataID): void {
|
|
52
|
+
this._records.set(dataID, null);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get(dataID: DataID): ?Record {
|
|
56
|
+
return this._records.get(dataID);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getRecordIDs(): Array<DataID> {
|
|
60
|
+
return Array.from(this._records.keys());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getStatus(dataID: DataID): RecordState {
|
|
64
|
+
if (!this._records.has(dataID)) {
|
|
65
|
+
return UNKNOWN;
|
|
66
|
+
}
|
|
67
|
+
return this._records.get(dataID) == null ? NONEXISTENT : EXISTENT;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
has(dataID: DataID): boolean {
|
|
71
|
+
return this._records.has(dataID);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
remove(dataID: DataID): void {
|
|
75
|
+
this._records.delete(dataID);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
set(dataID: DataID, record: Record): void {
|
|
79
|
+
this._records.set(dataID, record);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
size(): number {
|
|
83
|
+
return this._records.size;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
toJSON(): {[DataID]: ?Record, ...} {
|
|
87
|
+
const obj = {};
|
|
88
|
+
for (const [key, value] of this._records) {
|
|
89
|
+
obj[key] = value;
|
|
90
|
+
}
|
|
91
|
+
return obj;
|
|
26
92
|
}
|
|
27
93
|
}
|
|
28
94
|
|
|
@@ -12,18 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayConcreteNode = require('../util/RelayConcreteNode');
|
|
16
|
-
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
17
|
-
const RelayModernRecord = require('./RelayModernRecord');
|
|
18
|
-
const RelayStoreReactFlightUtils = require('./RelayStoreReactFlightUtils');
|
|
19
|
-
const RelayStoreUtils = require('./RelayStoreUtils');
|
|
20
|
-
|
|
21
|
-
const cloneRelayHandleSourceField = require('./cloneRelayHandleSourceField');
|
|
22
|
-
const getOperation = require('../util/getOperation');
|
|
23
|
-
const invariant = require('invariant');
|
|
24
|
-
|
|
25
|
-
const {generateTypeID} = require('./TypeID');
|
|
26
|
-
|
|
27
15
|
import type {
|
|
28
16
|
NormalizationFlightField,
|
|
29
17
|
NormalizationLinkedField,
|
|
@@ -36,12 +24,24 @@ import type {
|
|
|
36
24
|
DataIDSet,
|
|
37
25
|
NormalizationSelector,
|
|
38
26
|
OperationLoader,
|
|
27
|
+
ReactFlightReachableExecutableDefinitions,
|
|
39
28
|
Record,
|
|
40
29
|
RecordSource,
|
|
41
|
-
ReactFlightReachableExecutableDefinitions,
|
|
42
30
|
} from './RelayStoreTypes';
|
|
43
31
|
|
|
32
|
+
const getOperation = require('../util/getOperation');
|
|
33
|
+
const RelayConcreteNode = require('../util/RelayConcreteNode');
|
|
34
|
+
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
35
|
+
const cloneRelayHandleSourceField = require('./cloneRelayHandleSourceField');
|
|
36
|
+
const {getLocalVariables} = require('./RelayConcreteVariables');
|
|
37
|
+
const RelayModernRecord = require('./RelayModernRecord');
|
|
38
|
+
const RelayStoreReactFlightUtils = require('./RelayStoreReactFlightUtils');
|
|
39
|
+
const RelayStoreUtils = require('./RelayStoreUtils');
|
|
40
|
+
const {generateTypeID} = require('./TypeID');
|
|
41
|
+
const invariant = require('invariant');
|
|
42
|
+
|
|
44
43
|
const {
|
|
44
|
+
ACTOR_CHANGE,
|
|
45
45
|
CONDITION,
|
|
46
46
|
CLIENT_COMPONENT,
|
|
47
47
|
CLIENT_EXTENSION,
|
|
@@ -125,7 +125,6 @@ class RelayReferenceMarker {
|
|
|
125
125
|
'RelayReferenceMarker(): Undefined variable `%s`.',
|
|
126
126
|
name,
|
|
127
127
|
);
|
|
128
|
-
// $FlowFixMe[cannot-write]
|
|
129
128
|
return this._variables[name];
|
|
130
129
|
}
|
|
131
130
|
|
|
@@ -136,6 +135,10 @@ class RelayReferenceMarker {
|
|
|
136
135
|
selections.forEach(selection => {
|
|
137
136
|
/* eslint-disable no-fallthrough */
|
|
138
137
|
switch (selection.kind) {
|
|
138
|
+
case ACTOR_CHANGE:
|
|
139
|
+
// TODO: T89695151 Support multi-actor record sources in RelayReferenceMarker.js
|
|
140
|
+
this._traverseLink(selection.linkedField, record);
|
|
141
|
+
break;
|
|
139
142
|
case LINKED_FIELD:
|
|
140
143
|
if (selection.plural) {
|
|
141
144
|
this._traversePluralLink(selection, record);
|
|
@@ -144,7 +147,9 @@ class RelayReferenceMarker {
|
|
|
144
147
|
}
|
|
145
148
|
break;
|
|
146
149
|
case CONDITION:
|
|
147
|
-
const conditionValue =
|
|
150
|
+
const conditionValue = Boolean(
|
|
151
|
+
this._getVariableValue(selection.condition),
|
|
152
|
+
);
|
|
148
153
|
if (conditionValue === selection.passingValue) {
|
|
149
154
|
this._traverseSelections(selection.selections, record);
|
|
150
155
|
}
|
|
@@ -155,18 +160,22 @@ class RelayReferenceMarker {
|
|
|
155
160
|
if (typeName != null && typeName === selection.type) {
|
|
156
161
|
this._traverseSelections(selection.selections, record);
|
|
157
162
|
}
|
|
158
|
-
} else
|
|
163
|
+
} else {
|
|
159
164
|
const typeName = RelayModernRecord.getType(record);
|
|
160
165
|
const typeID = generateTypeID(typeName);
|
|
161
166
|
this._references.add(typeID);
|
|
162
167
|
this._traverseSelections(selection.selections, record);
|
|
163
|
-
} else {
|
|
164
|
-
this._traverseSelections(selection.selections, record);
|
|
165
168
|
}
|
|
166
169
|
break;
|
|
167
|
-
// $FlowFixMe[incompatible-type]
|
|
168
170
|
case FRAGMENT_SPREAD:
|
|
171
|
+
const prevVariables = this._variables;
|
|
172
|
+
this._variables = getLocalVariables(
|
|
173
|
+
this._variables,
|
|
174
|
+
selection.fragment.argumentDefinitions,
|
|
175
|
+
selection.args,
|
|
176
|
+
);
|
|
169
177
|
this._traverseSelections(selection.fragment.selections, record);
|
|
178
|
+
this._variables = prevVariables;
|
|
170
179
|
break;
|
|
171
180
|
case LINKED_HANDLE:
|
|
172
181
|
// The selections for a "handle" field are the same as those of the
|
|
@@ -197,11 +206,9 @@ class RelayReferenceMarker {
|
|
|
197
206
|
case SCALAR_HANDLE:
|
|
198
207
|
break;
|
|
199
208
|
case TYPE_DISCRIMINATOR: {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
this._references.add(typeID);
|
|
204
|
-
}
|
|
209
|
+
const typeName = RelayModernRecord.getType(record);
|
|
210
|
+
const typeID = generateTypeID(typeName);
|
|
211
|
+
this._references.add(typeID);
|
|
205
212
|
break;
|
|
206
213
|
}
|
|
207
214
|
case MODULE_IMPORT:
|
|
@@ -253,8 +260,15 @@ class RelayReferenceMarker {
|
|
|
253
260
|
}
|
|
254
261
|
const normalizationRootNode = operationLoader.get(operationReference);
|
|
255
262
|
if (normalizationRootNode != null) {
|
|
256
|
-
const
|
|
257
|
-
this.
|
|
263
|
+
const operation = getOperation(normalizationRootNode);
|
|
264
|
+
const prevVariables = this._variables;
|
|
265
|
+
this._variables = getLocalVariables(
|
|
266
|
+
this._variables,
|
|
267
|
+
operation.argumentDefinitions,
|
|
268
|
+
moduleImport.args,
|
|
269
|
+
);
|
|
270
|
+
this._traverseSelections(operation.selections, record);
|
|
271
|
+
this._variables = prevVariables;
|
|
258
272
|
}
|
|
259
273
|
// Otherwise, if the operation is not available, we assume that the data
|
|
260
274
|
// cannot have been processed yet and therefore isn't in the store to
|