Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composition-go/index.global.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composition/src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export function unexpectedEdgeFatalError(typeName: string, edgeNames: Array<stri
return new Error(
`Fatal: The type "${typeName}" visited the following unexpected edge` +
(edgeNames.length > 1 ? 's' : '') +
`:\n " ${edgeNames.join(QUOTATION_JOIN)}".`,
`:\n "${edgeNames.join(QUOTATION_JOIN)}".`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,23 @@ export class EntityWalker {
if (edge.node.isLeaf) {
return { visited: true, areDescendantsResolved: true };
}
const edgeSelectionPath = `${selectionPath}.${edge.edgeName}`;

// If the edge and all its descendants are already resolved, there is nothing further to check.
const data = this.getNodeResolutionData({
node: edge.node,
selectionPath: edgeSelectionPath,
});
if (data.areDescendantsResolved()) {
return { visited: true, areDescendantsResolved: true };
}
if (!add(edge.visitedIndices, this.index)) {
/* This check is necessary to avoid infinite loops inexpensively.
* If the edge has been visited before, any unresolvable will be propagated by the first instance.
* Descendant paths need to be cleaned up to avoid false positives.
*/
this.removeUnresolvablePaths({
selectionPath: `${selectionPath}.${edge.edgeName}`,
selectionPath: edgeSelectionPath,
removeDescendantPaths: true,
});
return { visited: true, areDescendantsResolved: true, isRevisitedNode: true };
Expand All @@ -90,22 +100,18 @@ export class EntityWalker {
return { visited: true, areDescendantsResolved: true };
}
this.encounteredEntityNodeNames.add(edge.node.nodeName);
getValueOrDefault(
this.selectionPathByEntityNodeName,
edge.node.nodeName,
() => `${selectionPath}.${edge.edgeName}`,
);
getValueOrDefault(this.selectionPathByEntityNodeName, edge.node.nodeName, () => edgeSelectionPath);
return { visited: true, areDescendantsResolved: false };
}
if (edge.node.isAbstract) {
return this.visitEntityDescendantAbstractNode({
node: edge.node,
selectionPath: `${selectionPath}.${edge.edgeName}`,
selectionPath: edgeSelectionPath,
});
}
return this.visitEntityDescendantConcreteNode({
node: edge.node,
selectionPath: `${selectionPath}.${edge.edgeName}`,
selectionPath: edgeSelectionPath,
});
}

Expand All @@ -115,10 +121,8 @@ export class EntityWalker {
return { visited: true, areDescendantsResolved: true };
}
const data = this.getNodeResolutionData({ node, selectionPath });
if (data.isResolved()) {
if (data.areDescendantsResolved()) {
return { visited: true, areDescendantsResolved: true };
}
if (data.isResolved() && data.areDescendantsResolved()) {
return { visited: true, areDescendantsResolved: true };
}
let removeDescendantPaths: true | undefined = undefined;
for (const [fieldName, edge] of node.headToTailEdges) {
Expand Down
19 changes: 1 addition & 18 deletions composition/tests/v1/resolvability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1711,17 +1711,7 @@ describe('Field resolvability tests', () => {
subgraphNames: new Set<string>([haab.name]),
typeName: 'EntityA',
};
const unresolvableFieldDataFour: UnresolvableFieldData = {
fieldName: 'c',
selectionSet: renderSelectionSet(generateSelectionSetSegments('query.a.b.nodes'), {
isLeaf: false,
name: 'c',
} as GraphFieldData),
subgraphNames: new Set<string>([haac.name]),
typeName: 'EntityB',
};

expect(errors).toHaveLength(4);
expect(errors).toHaveLength(3);
expect(errors).toStrictEqual([
unresolvablePathError(
unresolvableFieldDataOne,
Expand All @@ -1747,13 +1737,6 @@ describe('Field resolvability tests', () => {
unresolvableFieldData: unresolvableFieldDataThree,
}),
),
unresolvablePathError(
unresolvableFieldDataFour,
generateResolvabilityErrorReasons({
rootFieldData,
unresolvableFieldData: unresolvableFieldDataFour,
}),
),
]);
});
});
Expand Down
Loading