Skip to content

Commit 7240a3e

Browse files
authored
explicitly set nodes for override hints. (#1684)
explicitly set nodes for override hints. fixes #1682
1 parent 8a30c4d commit 7240a3e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

composition-js/src/merging/merge.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class FieldMergeContext {
123123
return this._props[idx].unusedOverridden;
124124
}
125125

126-
setUsedOverriden(idx: number) {
126+
setUsedOverridden(idx: number) {
127127
this._props[idx].usedOverridden = true;
128128
}
129129

@@ -1057,13 +1057,15 @@ class Merger {
10571057
subgraphsWithOverride.forEach((subgraphName) => {
10581058
const { overrideDirective } = subgraphMap[subgraphName];
10591059
const sourceSubgraphName = overrideDirective?.arguments()?.from;
1060+
const overridingSubgraphASTNode = overrideDirective?.sourceAST ? addSubgraphToASTNode(overrideDirective.sourceAST, subgraphName) : undefined;
10601061
if (!this.names.includes(sourceSubgraphName)) {
10611062
const suggestions = suggestionList(sourceSubgraphName, this.names);
10621063
const extraMsg = didYouMean(suggestions);
10631064
this.hints.push(new CompositionHint(
10641065
hintFromSubgraphDoesNotExist,
10651066
`Source subgraph "${sourceSubgraphName}" for field "${coordinate}" on subgraph "${subgraphName}" does not exist.${extraMsg}`,
10661067
coordinate,
1068+
overridingSubgraphASTNode,
10671069
));
10681070
} else if (sourceSubgraphName === subgraphName) {
10691071
this.errors.push(ERRORS.OVERRIDE_FROM_SELF_ERROR.err({
@@ -1080,6 +1082,7 @@ class Merger {
10801082
hintOverrideDirectiveCanBeRemoved,
10811083
`Field "${coordinate}" on subgraph "${subgraphName}" no longer exists in the from subgraph. The @override directive can be removed.`,
10821084
coordinate,
1085+
overridingSubgraphASTNode,
10831086
));
10841087
} else {
10851088
// check to make sure that there is no conflicting @provides, @requires, or @external directives
@@ -1102,27 +1105,31 @@ class Merger {
11021105
// if we get here, then the @override directive is valid
11031106
// if the field being overridden is used, then we need to add an @external directive
11041107
assert(fromField, 'fromField should not be undefined');
1108+
const overriddenSubgraphASTNode = fromField.sourceAST ? addSubgraphToASTNode(fromField.sourceAST, sourceSubgraphName) : undefined;
11051109
if (this.isExternal(fromIdx, fromField)) {
1106-
// The from field is explcitely marked external by the user (which means it is "used" and cannot be completely
1110+
// The from field is explicitly marked external by the user (which means it is "used" and cannot be completely
11071111
// removed) so the @override can be removed.
11081112
this.hints.push(new CompositionHint(
11091113
hintOverrideDirectiveCanBeRemoved,
11101114
`Field "${coordinate}" on subgraph "${subgraphName}" is not resolved anymore by the from subgraph (it is marked "@external" in "${sourceSubgraphName}"). The @override directive can be removed.`,
11111115
coordinate,
1116+
overridingSubgraphASTNode,
11121117
));
11131118
} else if (this.metadata(fromIdx).isFieldUsed(fromField)) {
1114-
result.setUsedOverriden(fromIdx);
1119+
result.setUsedOverridden(fromIdx);
11151120
this.hints.push(new CompositionHint(
11161121
hintOverriddenFieldCanBeRemoved,
11171122
`Field "${coordinate}" on subgraph "${sourceSubgraphName}" is overridden. It is still used in some federation directive(s) (@key, @requires, and/or @provides) and/or to satisfy interface constraint(s), but consider marking it @external explicitly or removing it along with its references.`,
11181123
coordinate,
1124+
overriddenSubgraphASTNode,
11191125
));
11201126
} else {
11211127
result.setUnusedOverridden(fromIdx);
11221128
this.hints.push(new CompositionHint(
11231129
hintOverriddenFieldCanBeRemoved,
11241130
`Field "${coordinate}" on subgraph "${sourceSubgraphName}" is overridden. Consider removing it.`,
11251131
coordinate,
1132+
overriddenSubgraphASTNode,
11261133
));
11271134
}
11281135
}

0 commit comments

Comments
 (0)