Skip to content

Commit e137a0f

Browse files
committed
fix: review comments
1 parent cd52465 commit e137a0f

1 file changed

Lines changed: 20 additions & 35 deletions

File tree

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

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,38 +4164,6 @@ export class NormalizationFactory {
41644164
getOrInitializeEntityCaching(configurationData).entityCacheConfigurations.push(config);
41654165
}
41664166

4167-
/**
4168-
* Dispatches per-field @openfed__queryCache extraction and @openfed__is placement validation. Must run
4169-
* after {@link extractEntityCacheDirective} (reads {@link entityCacheConfigByTypeName}) and after key field
4170-
* sets are available. @openfed__cacheInvalidate/@openfed__cachePopulate are extracted inline during the
4171-
* parent walk (see {@link extractCacheInvalidateConfig}/{@link extractCachePopulateConfig}). All object types
4172-
* are walked, not just root operation types: @openfed__queryCache is declared `on FIELD_DEFINITION`, so it
4173-
* can be (mis)placed on any field. `getOperationTypeNodeForRootTypeName()` returns undefined for non-root
4174-
* types; the extractor then reports the misplacement via its operation-type check.
4175-
*/
4176-
processRootFieldCacheDirectives() {
4177-
for (const [parentTypeName, parentData] of this.parentDefinitionDataByTypeName) {
4178-
if (parentData.kind !== Kind.OBJECT_TYPE_DEFINITION) {
4179-
continue;
4180-
}
4181-
const operationType = this.getOperationTypeNodeForRootTypeName(parentTypeName);
4182-
// A renamed root type (e.g. `schema { query: MyQuery }`) is keyed in configurationDataByTypeName under
4183-
// its federated/canonical name (Query/Mutation/Subscription) by every other config writer (keys, provides,
4184-
// the root-node lookup). Cache configs must use the same key, or the router reads the canonical node and
4185-
// never sees them.
4186-
const configurationTypeName = getParentTypeName(parentData);
4187-
4188-
for (const [fieldName, fieldData] of parentData.fieldDataByName) {
4189-
const fieldCoords = `${parentTypeName}.${fieldName}`;
4190-
const hasQueryCache = fieldData.directivesByName.has(OPENFED_QUERY_CACHE);
4191-
if (hasQueryCache) {
4192-
this.extractQueryCacheConfig(parentTypeName, configurationTypeName, fieldName, fieldData, operationType);
4193-
}
4194-
this.validateIsDirectivePlacement(fieldCoords, fieldData, hasQueryCache);
4195-
}
4196-
}
4197-
}
4198-
41994167
extractCacheInvalidateConfig(fieldData: FieldData) {
42004168
if (!fieldData.directivesByName.has(OPENFED_CACHE_INVALIDATE)) {
42014169
return;
@@ -5441,6 +5409,26 @@ export class NormalizationFactory {
54415409
}
54425410

54435411
this.extractRequestScopedConfig(fieldData);
5412+
5413+
// @openfed__queryCache extraction and @openfed__is placement validation. Key field sets and
5414+
// entity-cache configs are already finalized at this point in normalize() (populated by
5415+
// upsertParentsAndChildren and extractEntityCacheDirective, invalid keys pruned by
5416+
// evaluateExternalKeyFields), so queryCache can read keyFieldSetDatasByTypeName to build
5417+
// argument→key mappings.
5418+
const hasQueryCache = fieldData.directivesByName.has(OPENFED_QUERY_CACHE);
5419+
if (hasQueryCache) {
5420+
// A renamed root type (e.g. `schema { query: MyQuery }`) is keyed in configurationDataByTypeName
5421+
// under its federated/canonical name (Query/Mutation/Subscription) by every other config writer.
5422+
// Cache configs must use the same key, or the router reads the canonical node and never sees them.
5423+
this.extractQueryCacheConfig(
5424+
parentTypeName,
5425+
getParentTypeName(parentData),
5426+
fieldName,
5427+
fieldData,
5428+
this.getOperationTypeNodeForRootTypeName(parentTypeName),
5429+
);
5430+
}
5431+
this.validateIsDirectivePlacement(`${parentTypeName}.${fieldName}`, fieldData, hasQueryCache);
54445432
} else if (fieldData.externalFieldDataBySubgraphName.get(this.subgraphName)?.isDefinedExternal) {
54455433
externalInterfaceFieldNames.push(fieldName);
54465434
}
@@ -5551,9 +5539,6 @@ export class NormalizationFactory {
55515539
this.addValidConditionalFieldSetConfigurations();
55525540
// this is where @key configurations are added to the ConfigurationData
55535541
this.addValidKeyFieldSetConfigurations();
5554-
// @openfed__queryCache extraction and @openfed__is placement validation — must run after key field sets
5555-
// are available (queryCache reads keyFieldSetDatasByTypeName to build argument→key mappings)
5556-
this.processRootFieldCacheDirectives();
55575542
// Check that explicitly defined operations types are valid objects and that their fields are also valid
55585543
for (const operationType of Object.values(OperationTypeNode)) {
55595544
const operationTypeNode = this.schemaData.operationTypes.get(operationType);

0 commit comments

Comments
 (0)