Skip to content

Commit 93b5cbc

Browse files
committed
fix: review comments
1 parent 7cc280b commit 93b5cbc

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

composition/src/v1/normalization/normalization-factory.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ import {
204204
fieldAlreadyProvidedWarning,
205205
invalidExternalFieldWarning,
206206
nonExternalConditionalFieldWarning,
207+
requestScopedSingleFieldWarning,
207208
singleSubgraphInputFieldOneOfWarning,
208209
unimplementedInterfaceOutputTypeWarning,
209210
} from '../warnings/warnings';
@@ -509,6 +510,7 @@ export class NormalizationFactory {
509510
referencedDirectiveNames = new Set<DirectiveName>();
510511
referencedTypeNames = new Set<TypeName>();
511512
renamedParentTypeName = '';
513+
requestScopedFieldCoordsByL1Key = new Map<string, Array<string>>();
512514
schemaData: SchemaData;
513515
subgraphName: SubgraphName;
514516
unvalidatedExternalFieldCoords = new Set<string>();
@@ -4255,6 +4257,10 @@ export class NormalizationFactory {
42554257
newConfigurationData(false, fieldData.renamedParentTypeName),
42564258
);
42574259
getOrInitializeEntityCaching(configurationData).requestScopedConfigurations.push(config);
4260+
// Track field coords per L1 key so the single-field warning can be emitted after the walk completes.
4261+
getValueOrDefault(this.requestScopedFieldCoordsByL1Key, config.l1Key, () => []).push(
4262+
`${config.typeName}.${config.fieldName}`,
4263+
);
42584264
}
42594265

42604266
addFieldNamesToConfigurationData(fieldDataByFieldName: Map<string, FieldData>, configurationData: ConfigurationData) {
@@ -4541,6 +4547,21 @@ export class NormalizationFactory {
45414547
}
45424548
}
45434549
}
4550+
// @openfed__requestScoped is meaningless unless >= 2 fields share a key (there'd be no second reader to
4551+
// benefit), so warn for any key used on only one field across the subgraph. extractRequestScopedConfig()
4552+
// populated requestScopedFieldCoordsByL1Key during the type walk above.
4553+
for (const [l1Key, fieldCoordsList] of this.requestScopedFieldCoordsByL1Key) {
4554+
if (fieldCoordsList.length === 1) {
4555+
this.warnings.push(
4556+
requestScopedSingleFieldWarning({
4557+
subgraphName: this.subgraphName,
4558+
// l1Key is `${this.subgraphName}.${key}`, so strip the prefix to recover the original key.
4559+
key: l1Key.slice(this.subgraphName.length + 1),
4560+
fieldCoords: fieldCoordsList[0],
4561+
}),
4562+
);
4563+
}
4564+
}
45444565
this.isSubgraphEventDrivenGraph = this.edfsDirectiveReferences.size > 0;
45454566
// this is where @provides and @requires configurations are added to the ConfigurationData
45464567
this.addValidConditionalFieldSetConfigurations();

0 commit comments

Comments
 (0)