Skip to content

Commit 8beb141

Browse files
committed
fix(federation): prevent infinite loop while visiting over the computed field types
1 parent b07b76d commit 8beb141

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.changeset/unlucky-actors-tease.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphql-tools/stitch": patch
3+
---
4+
5+
Prevent infinite loop while visiting over the computed field types

packages/stitch/src/subschemaConfigTransforms/isolateComputedFieldsTransformer.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,16 @@ type IsolatedSubschemaInput = Exclude<SubschemaConfig, 'merge'> & {
227227
function filterIsolatedSubschema(subschemaConfig: IsolatedSubschemaInput): SubschemaConfig {
228228
const rootFields: Record<string, boolean> = {};
229229
const computedFieldTypes: Record<string, boolean> = {}; // contains types of computed fields that have no root field
230-
230+
const visitedTypes = new WeakSet<GraphQLNamedOutputType>();
231231
function listReachableTypesToIsolate(
232232
subschemaConfig: SubschemaConfig,
233233
type: GraphQLNamedOutputType,
234-
typeNames?: string[],
234+
typeNames: string[] = [],
235235
) {
236-
typeNames = typeNames || [];
237-
236+
if (visitedTypes.has(type)) {
237+
return typeNames;
238+
}
239+
visitedTypes.add(type);
238240
if (isScalarType(type)) {
239241
return typeNames;
240242
} else if (

0 commit comments

Comments
 (0)