From 2048ae4fdbb72c15921a27a5c1e9dee83ea8171d Mon Sep 17 00:00:00 2001 From: "Sachin D. Shinde" Date: Wed, 10 Jul 2024 20:02:33 -0400 Subject: [PATCH] Fix missing sources computation for composition hints/errors (#3075) This PR fixes the issue identified in [this review comment](https://github.com/apollographql/federation/pull/3069#discussion_r1672816904). Specifically, this PR fixes the bug in composition hint/error message generation where missing sources were computed incorrectly. (No changeset needed since the referenced PR hasn't been released yet.) --- composition-js/src/merging/reporter.ts | 31 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/composition-js/src/merging/reporter.ts b/composition-js/src/merging/reporter.ts index 42d1075d9..3a9888ed6 100644 --- a/composition-js/src/merging/reporter.ts +++ b/composition-js/src/merging/reporter.ts @@ -154,20 +154,31 @@ export class MismatchReporter { ) { const distributionMap = new MultiMap(); const astNodes: SubgraphASTNode[] = []; - for (const [i, subgraphElt] of subgraphElements.entries()) { - if (!subgraphElt) { - if (includeMissingSources) { - distributionMap.add('', this.names[i]); - } - continue; - } + const processSubgraphElt = (name: string, subgraphElt: TMismatched) => { if (ignorePredicate && ignorePredicate(subgraphElt)) { - continue; + return; } const elt = mismatchAccessor(subgraphElt, false); - distributionMap.add(elt ?? '', this.names[i]); + distributionMap.add(elt ?? '', name); if (subgraphElt.sourceAST) { - astNodes.push(addSubgraphToASTNode(subgraphElt.sourceAST, this.names[i])); + astNodes.push(addSubgraphToASTNode(subgraphElt.sourceAST, name)); + } + } + if (includeMissingSources) { + for (const [i, name] of this.names.entries()) { + const subgraphElt = subgraphElements.get(i); + if (!subgraphElt) { + distributionMap.add('', name); + continue; + } + processSubgraphElt(name, subgraphElt); + } + } else { + for (const [i, subgraphElt] of subgraphElements.entries()) { + if (!subgraphElt) { + continue; + } + processSubgraphElt(this.names[i], subgraphElt); } } const supergraphMismatch = (supergraphElement && mismatchAccessor(supergraphElement, true)) ?? '';