Skip to content

Commit 1eca4a5

Browse files
lynnshaoyufacebook-github-bot
authored andcommitted
Stop unnecessary runtime transforms
Reviewed By: tyao1 Differential Revision: D74013247 fbshipit-source-id: d6aeae4b46fb82e4105638f98ea12afc3d35bee4
1 parent 1182ca6 commit 1eca4a5

File tree

8 files changed

+78
-14
lines changed

8 files changed

+78
-14
lines changed

packages/relay-runtime/store/DataChecker.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function check(
7373
getDataID: GetDataID,
7474
shouldProcessClientComponents: ?boolean,
7575
log: ?LogFunction,
76+
useExecTimeResolvers: ?boolean,
7677
): Availability {
7778
if (log != null) {
7879
log({
@@ -91,6 +92,7 @@ function check(
9192
getDataID,
9293
shouldProcessClientComponents,
9394
log,
95+
useExecTimeResolvers,
9496
);
9597
const result = checker.check(node, dataID);
9698
if (log != null) {
@@ -113,6 +115,7 @@ class DataChecker {
113115
_recordSourceProxy: RelayRecordSourceProxy;
114116
_recordWasMissing: boolean;
115117
_source: RecordSource;
118+
_useExecTimeResolvers: boolean;
116119
_variables: Variables;
117120
_shouldProcessClientComponents: ?boolean;
118121
+_getSourceForActor: (actorIdentifier: ActorIdentifier) => RecordSource;
@@ -138,6 +141,7 @@ class DataChecker {
138141
getDataID: GetDataID,
139142
shouldProcessClientComponents: ?boolean,
140143
log: ?LogFunction,
144+
useExecTimeResolvers: ?boolean,
141145
) {
142146
this._getSourceForActor = getSourceForActor;
143147
this._getTargetForActor = getTargetForActor;
@@ -147,6 +151,7 @@ class DataChecker {
147151
const [mutator, recordSourceProxy] = this._getMutatorAndRecordProxyForActor(
148152
defaultActorIdentifier,
149153
);
154+
this._useExecTimeResolvers = useExecTimeResolvers ?? false;
150155
this._mostRecentlyInvalidatedAt = null;
151156
this._handlers = handlers;
152157
this._mutator = mutator;
@@ -455,10 +460,14 @@ class DataChecker {
455460
break;
456461
case 'RelayResolver':
457462
case 'RelayLiveResolver':
458-
this._checkResolver(selection, dataID);
463+
if (!this._useExecTimeResolvers) {
464+
this._checkResolver(selection, dataID);
465+
}
459466
break;
460467
case 'ClientEdgeToClientObject':
461-
this._checkResolver(selection.backingField, dataID);
468+
if (!this._useExecTimeResolvers) {
469+
this._checkResolver(selection.backingField, dataID);
470+
}
462471
break;
463472
default:
464473
(selection: empty);

packages/relay-runtime/store/OperationExecutor.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class Executor<TMutation: MutationParameters> {
138138
_operationTracker: OperationTracker;
139139
_operationUpdateEpochs: Map<string, number>;
140140
_optimisticUpdates: null | Array<OptimisticUpdate<TMutation>>;
141+
_useExecTimeResolvers: boolean;
141142
_pendingModulePayloadsCount: number;
142143
+_getPublishQueue: (actorIdentifier: ActorIdentifier) => PublishQueue;
143144
_shouldProcessClientComponents: ?boolean;
@@ -193,6 +194,11 @@ class Executor<TMutation: MutationParameters> {
193194
this._operationTracker = operationTracker;
194195
this._operationUpdateEpochs = new Map();
195196
this._optimisticUpdates = null;
197+
this._useExecTimeResolvers =
198+
this._operation.request.node.operation.use_exec_time_resolvers ??
199+
this._operation.request.node.operation.exec_time_resolvers_enabled_provider?.get() ===
200+
true ??
201+
false;
196202
this._pendingModulePayloadsCount = 0;
197203
this._getPublishQueue = getPublishQueue;
198204
this._scheduler = scheduler;
@@ -617,6 +623,7 @@ class Executor<TMutation: MutationParameters> {
617623
shouldProcessClientComponents: this._shouldProcessClientComponents,
618624
treatMissingFieldsAsNull,
619625
},
626+
this._useExecTimeResolvers,
620627
);
621628
validateOptimisticResponsePayload(payload);
622629
optimisticUpdates.push({
@@ -727,6 +734,7 @@ class Executor<TMutation: MutationParameters> {
727734
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
728735
shouldProcessClientComponents: this._shouldProcessClientComponents,
729736
},
737+
this._useExecTimeResolvers,
730738
);
731739
}
732740

@@ -810,6 +818,7 @@ class Executor<TMutation: MutationParameters> {
810818
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
811819
shouldProcessClientComponents: this._shouldProcessClientComponents,
812820
},
821+
this._useExecTimeResolvers,
813822
);
814823
this._getPublishQueueAndSaveActor().commitPayload(
815824
this._operation,
@@ -1267,6 +1276,7 @@ class Executor<TMutation: MutationParameters> {
12671276
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
12681277
shouldProcessClientComponents: this._shouldProcessClientComponents,
12691278
},
1279+
this._useExecTimeResolvers,
12701280
);
12711281
this._getPublishQueueAndSaveActor().commitPayload(
12721282
this._operation,
@@ -1487,14 +1497,20 @@ class Executor<TMutation: MutationParameters> {
14871497
record: nextParentRecord,
14881498
fieldPayloads,
14891499
});
1490-
const relayPayload = this._normalizeResponse(response, selector, typeName, {
1491-
actorIdentifier: this._actorIdentifier,
1492-
getDataID: this._getDataID,
1493-
log: this._log,
1494-
path: [...normalizationPath, responseKey, String(itemIndex)],
1495-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
1496-
shouldProcessClientComponents: this._shouldProcessClientComponents,
1497-
});
1500+
const relayPayload = this._normalizeResponse(
1501+
response,
1502+
selector,
1503+
typeName,
1504+
{
1505+
actorIdentifier: this._actorIdentifier,
1506+
getDataID: this._getDataID,
1507+
log: this._log,
1508+
path: [...normalizationPath, responseKey, String(itemIndex)],
1509+
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
1510+
shouldProcessClientComponents: this._shouldProcessClientComponents,
1511+
},
1512+
this._useExecTimeResolvers,
1513+
);
14981514
return {
14991515
fieldPayloads,
15001516
itemID,

packages/relay-runtime/store/RelayModernStore.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ class RelayModernStore implements Store {
242242
const selector = operation.root;
243243
const source = this._getMutableRecordSource();
244244
const globalInvalidationEpoch = this._globalInvalidationEpoch;
245+
const useExecTimeResolvers =
246+
operation.request.node.operation.use_exec_time_resolvers ??
247+
operation.request.node.operation.exec_time_resolvers_enabled_provider?.get() ===
248+
true ??
249+
false;
245250

246251
const rootEntry = this._roots.get(operation.request.identifier);
247252
const operationLastWrittenAt = rootEntry != null ? rootEntry.epoch : null;
@@ -286,6 +291,7 @@ class RelayModernStore implements Store {
286291
this._getDataID,
287292
this._shouldProcessClientComponents,
288293
this.__log,
294+
useExecTimeResolvers,
289295
);
290296

291297
return getAvailabilityStatus(
@@ -743,12 +749,18 @@ class RelayModernStore implements Store {
743749

744750
// Mark all records that are traversable from a root that is still valid
745751
const selector = operation.root;
752+
const useExecTimeResolvers =
753+
operation.request.node.operation.use_exec_time_resolvers ??
754+
operation.request.node.operation.exec_time_resolvers_enabled_provider?.get() ===
755+
true ??
756+
false;
746757
RelayReferenceMarker.mark(
747758
this._recordSource,
748759
selector,
749760
references,
750761
this._operationLoader,
751762
this._shouldProcessClientComponents,
763+
useExecTimeResolvers,
752764
);
753765
// Yield for other work after each operation
754766
yield;

packages/relay-runtime/store/RelayReferenceMarker.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function mark(
4747
references: DataIDSet,
4848
operationLoader: ?OperationLoader,
4949
shouldProcessClientComponents: ?boolean,
50+
useExecTimeResolvers: ?boolean,
5051
): void {
5152
const {dataID, node, variables} = selector;
5253
const marker = new RelayReferenceMarker(
@@ -55,6 +56,7 @@ function mark(
5556
references,
5657
operationLoader,
5758
shouldProcessClientComponents,
59+
useExecTimeResolvers,
5860
);
5961
marker.mark(node, dataID);
6062
}
@@ -68,6 +70,7 @@ class RelayReferenceMarker {
6870
_recordSource: RecordSource;
6971
_references: DataIDSet;
7072
_variables: Variables;
73+
_useExecTimeResolvers: boolean;
7174
_shouldProcessClientComponents: ?boolean;
7275

7376
constructor(
@@ -76,9 +79,11 @@ class RelayReferenceMarker {
7679
references: DataIDSet,
7780
operationLoader: ?OperationLoader,
7881
shouldProcessClientComponents: ?boolean,
82+
useExecTimeResolvers: ?boolean,
7983
) {
8084
this._operationLoader = operationLoader ?? null;
8185
this._operationName = null;
86+
this._useExecTimeResolvers = useExecTimeResolvers ?? false;
8287
this._recordSource = recordSource;
8388
this._references = references;
8489
this._variables = variables;
@@ -238,6 +243,10 @@ class RelayReferenceMarker {
238243
field: NormalizationClientEdgeToClientObject,
239244
record: Record,
240245
): void {
246+
if (this._useExecTimeResolvers) {
247+
this._traverseLink(field.linkedField, record);
248+
return;
249+
}
241250
const dataID = this._traverseResolverField(field.backingField, record);
242251
if (dataID == null) {
243252
return;
@@ -290,6 +299,9 @@ class RelayReferenceMarker {
290299
field: NormalizationResolverField | NormalizationLiveResolverField,
291300
record: Record,
292301
): ?DataID {
302+
if (this._useExecTimeResolvers) {
303+
return;
304+
}
293305
const storageKey = getReadTimeResolverStorageKey(field, this._variables);
294306
const dataID = RelayModernRecord.getLinkedRecordID(record, storageKey);
295307

@@ -305,7 +317,6 @@ class RelayReferenceMarker {
305317
// Mark the contents of the resolver's data dependencies.
306318
this._traverseSelections([fragment], record);
307319
}
308-
309320
return dataID;
310321
}
311322

packages/relay-runtime/store/RelayResponseNormalizer.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ function normalize(
9090
response: PayloadData,
9191
options: NormalizationOptions,
9292
errors?: Array<PayloadError>,
93+
useExecTimeResolvers?: boolean,
9394
): RelayResponsePayload {
9495
const {dataID, node, variables} = selector;
9596
const normalizer = new RelayResponseNormalizer(
9697
recordSource,
9798
variables,
9899
options,
100+
useExecTimeResolvers ?? false,
99101
);
100102
return normalizer.normalizeResponse(node, dataID, response, errors);
101103
}
@@ -117,6 +119,7 @@ class RelayResponseNormalizer {
117119
_path: Array<string>;
118120
_recordSource: MutableRecordSource;
119121
_variables: Variables;
122+
_useExecTimeResolvers: boolean;
120123
_shouldProcessClientComponents: ?boolean;
121124
_errorTrie: RelayErrorTrie | null;
122125
_log: ?LogFunction;
@@ -125,6 +128,7 @@ class RelayResponseNormalizer {
125128
recordSource: MutableRecordSource,
126129
variables: Variables,
127130
options: NormalizationOptions,
131+
useExecTimeResolvers: boolean,
128132
) {
129133
this._actorIdentifier = options.actorIdentifier;
130134
this._getDataId = options.getDataID;
@@ -133,6 +137,7 @@ class RelayResponseNormalizer {
133137
this._incrementalPlaceholders = [];
134138
this._isClientExtension = false;
135139
this._isUnmatchedAbstractType = false;
140+
this._useExecTimeResolvers = useExecTimeResolvers;
136141
this._followupPayloads = [];
137142
this._path = options.path ? [...options.path] : [];
138143
this._recordSource = recordSource;
@@ -325,10 +330,14 @@ class RelayResponseNormalizer {
325330
break;
326331
case 'RelayResolver':
327332
case 'RelayLiveResolver':
328-
this._normalizeResolver(selection, record, data);
333+
if (!this._useExecTimeResolvers) {
334+
this._normalizeResolver(selection, record, data);
335+
}
329336
break;
330337
case 'ClientEdgeToClientObject':
331-
this._normalizeResolver(selection.backingField, record, data);
338+
if (!this._useExecTimeResolvers) {
339+
this._normalizeResolver(selection.backingField, record, data);
340+
}
332341
break;
333342
default:
334343
(selection: empty);

packages/relay-runtime/store/RelayStoreTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,7 @@ export type NormalizeResponseFunction = (
11721172
selector: NormalizationSelector,
11731173
typeName: string,
11741174
options: NormalizationOptions,
1175+
useExecTimeResolvers: boolean,
11751176
) => RelayResponsePayload;
11761177

11771178
/**

packages/relay-runtime/store/live-resolvers/LiveResolverCache.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,16 @@ class LiveResolverCache implements ResolverCache {
754754
outputTypeDataID,
755755
variables,
756756
);
757-
757+
// LiveResolverCache is only used by read time resolvers, so this flag should be hardcoded as false.
758+
const useExecTimeResolvers = false;
758759
const normalizationOptions =
759760
this._store.__getNormalizationOptions(fieldPath);
760761
// The resulted `source` is the normalized version of the
761762
// resolver's (@outputType) value.
762763
// All records in the `source` should have IDs that
763764
// is "prefix-ed" with the parent resolver record `ID`
764765
// and they don't expect to have a "strong" identifier.
766+
765767
return normalize(
766768
source,
767769
selector,
@@ -771,6 +773,8 @@ class LiveResolverCache implements ResolverCache {
771773
// $FlowFixMe[incompatible-variance]
772774
value,
773775
normalizationOptions,
776+
undefined,
777+
useExecTimeResolvers,
774778
).source;
775779
}
776780
// For weak models we have a simpler case. We simply need to update a

packages/relay-runtime/store/normalizeResponse.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function normalizeResponse(
2727
selector: NormalizationSelector,
2828
typeName: string,
2929
options: NormalizationOptions,
30+
useExecTimeResolvers: boolean,
3031
): RelayResponsePayload {
3132
const {data, errors} = response;
3233
const source = RelayRecordSource.create();
@@ -38,6 +39,7 @@ function normalizeResponse(
3839
data,
3940
options,
4041
errors,
42+
useExecTimeResolvers,
4143
);
4244
return {
4345
...relayPayload,

0 commit comments

Comments
 (0)