diff --git a/.changeset/eighty-feet-sparkle.md b/.changeset/eighty-feet-sparkle.md new file mode 100644 index 000000000..392cef7e3 --- /dev/null +++ b/.changeset/eighty-feet-sparkle.md @@ -0,0 +1,5 @@ +--- +'@pothos/core': patch +--- + +Fix duplicate interfaces when building a schema multiple times diff --git a/packages/core/src/config-store.ts b/packages/core/src/config-store.ts index 6e2210812..044bfa127 100644 --- a/packages/core/src/config-store.ts +++ b/packages/core/src/config-store.ts @@ -443,8 +443,12 @@ export default class ConfigStore { this.pending = false; const fns = this.addFieldFns; + const interfaces = this.pendingInterfaces; + const unions = this.pendingUnionTypes; this.addFieldFns = []; + this.pendingInterfaces = new Map(); + this.pendingUnionTypes = new Map(); fns.forEach((fn) => void fn()); @@ -456,13 +460,13 @@ export default class ConfigStore { ); } - for (const [typeName, unionFns] of this.pendingUnionTypes) { + for (const [typeName, unionFns] of unions) { for (const fn of unionFns) { this.addUnionTypes(typeName, fn); } } - for (const [typeName, interfacesFns] of this.pendingInterfaces) { + for (const [typeName, interfacesFns] of interfaces) { for (const fn of interfacesFns) { this.addInterfaces(typeName, fn); }