Skip to content

Commit

Permalink
Avoid marking the same type as used twice (#308)
Browse files Browse the repository at this point in the history
Fixes #305
  • Loading branch information
kamilkisiela authored Aug 23, 2022
1 parent 5761d9e commit 5a212f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-rats-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/client': patch
---

Avoid marking the same type as used twice
10 changes: 10 additions & 0 deletions packages/libraries/client/src/internal/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export function createCollector({ schema, max, ttl }: { schema: GraphQLSchema; m

function collect(doc: DocumentNode): CacheResult {
const entries = new Set<string>();
const collected_entire_named_types = new Set<string>();

function markAsUsed(id: string) {
if (!entries.has(id)) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5a212f6

Please sign in to comment.