diff --git a/.changeset/unlucky-actors-tease.md b/.changeset/unlucky-actors-tease.md new file mode 100644 index 00000000000..00ac3720d2a --- /dev/null +++ b/.changeset/unlucky-actors-tease.md @@ -0,0 +1,5 @@ +--- +"@graphql-tools/stitch": patch +--- + +Prevent infinite loop while visiting over the computed field types diff --git a/packages/stitch/src/subschemaConfigTransforms/isolateComputedFieldsTransformer.ts b/packages/stitch/src/subschemaConfigTransforms/isolateComputedFieldsTransformer.ts index b3cb9277f45..c40445d28a8 100644 --- a/packages/stitch/src/subschemaConfigTransforms/isolateComputedFieldsTransformer.ts +++ b/packages/stitch/src/subschemaConfigTransforms/isolateComputedFieldsTransformer.ts @@ -227,14 +227,16 @@ type IsolatedSubschemaInput = Exclude & { function filterIsolatedSubschema(subschemaConfig: IsolatedSubschemaInput): SubschemaConfig { const rootFields: Record = {}; const computedFieldTypes: Record = {}; // contains types of computed fields that have no root field - + const visitedTypes = new WeakSet(); function listReachableTypesToIsolate( subschemaConfig: SubschemaConfig, type: GraphQLNamedOutputType, - typeNames?: string[], + typeNames: string[] = [], ) { - typeNames = typeNames || []; - + if (visitedTypes.has(type)) { + return typeNames; + } + visitedTypes.add(type); if (isScalarType(type)) { return typeNames; } else if (