diff --git a/.changeset/shiny-rats-rule.md b/.changeset/shiny-rats-rule.md new file mode 100644 index 0000000000..3235c50f1f --- /dev/null +++ b/.changeset/shiny-rats-rule.md @@ -0,0 +1,5 @@ +--- +'@graphql-hive/client': patch +--- + +Avoid marking the same type as used twice diff --git a/packages/libraries/client/src/internal/usage.ts b/packages/libraries/client/src/internal/usage.ts index d8af14e333..bc744c3f2e 100644 --- a/packages/libraries/client/src/internal/usage.ts +++ b/packages/libraries/client/src/internal/usage.ts @@ -195,6 +195,7 @@ export function createCollector({ schema, max, ttl }: { schema: GraphQLSchema; m function collect(doc: DocumentNode): CacheResult { const entries = new Set(); + const collected_entire_named_types = new Set(); function markAsUsed(id: string) { if (!entries.has(id)) { @@ -244,6 +245,15 @@ export function createCollector({ schema, max, ttl }: { schema: GraphQLSchema; m function markEntireTypeAsUsed(type: GraphQLInputType): void { const namedType = unwrapType(type); + if (collected_entire_named_types.has(namedType.name)) { + // No need to mark this type as used again + return; + } else { + // Add this type to the set of types that have been marked as used + // to avoid infinite loops + collected_entire_named_types.add(namedType.name); + } + if (isScalarType(namedType)) { markAsUsed(makeId(namedType.name)); return;