fix(pg-many-to-many): auto-disambiguate type name collisions instead of crashing#1059
Merged
pyramation merged 3 commits intomainfrom May 6, 2026
Merged
fix(pg-many-to-many): auto-disambiguate type name collisions instead of crashing#1059pyramation merged 3 commits intomainfrom
pyramation merged 3 commits intomainfrom
Conversation
…of crashing Two fixes for the many-to-many plugin type naming collision: 1. Fix inflector counting logic in _manyToManyRelation to properly count self-junction tables (where junction === rightTable). Previously, the condition excluded these paths, so two junction tables targeting the same left→right pair would both get the simplified name, causing a crash in graphile-build's register(). 2. Add defense-in-depth in ManyToManyOptInPlugin: wrap registerObjectType to catch type naming conflicts for many-to-many types and silently skip duplicates. This prevents crashes even if the inflector produces a collision in some unforeseen edge case. Closes constructive-io/constructive-planning#797
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
The m2m connection field name doesn't contain 'connection' — that suffix is only on the GraphQL type. Check for Bucket*ManyToManyEdge types in the schema introspection instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
pg-many-to-manyplugin crash when two different FK paths from table A to table B produce the same GraphQL edge type name (e.g.AppBucketAppFilesManyToManyEdge).Root cause: The custom
_manyToManyRelationinflector incustom-inflector.tshad a counting bug — it skipped junction tables where the junction IS the right table (rel.remoteResource?.codec?.name !== rightTable.codec.name). Whenfilesacts as both junction and right table (self-referential FK), it wasn't counted, so both paths got the simplified name → same type name → crash.Two fixes applied:
Inflector counting fix (
custom-inflector.ts): Removed the!== rightTable.codec.namecondition so self-junction paths are properly counted. When multiple m2m paths to the same right table exist, the inflector falls back to the verbose (unique) naming.Defense-in-depth (
many-to-many-preset.ts): Added abuildhook that wrapsregisterObjectTypeto catch type naming conflicts specifically for many-to-many types and silently skip the duplicate. This prevents crashes even in unforeseen edge cases.Why opt-in didn't prevent this: The
ManyToManyOptInPlugingates field creation viapgManyToManybehavior, but the upstream plugin'sinithook callscreateManyToManyConnectionType(which registers types) for all discovered relationships unconditionally — before behavior filtering. So even with-manyToManydefault, types still get registered and can collide.Closes constructive-io/constructive-planning#797
Review & Testing Checklist for Human
registerObjectTypewrapper doesn't silently swallow legitimate type conflicts in non-m2m scenarios (it only catches errors whose origin string contains "many-to-many")Notes
buckets,files(with self-referentialparent_idFK), andfile_eventstables to the existingpreset-integration.test.tsto reproduce the exact collision scenario from the issue@behavior +manyToManyLink to Devin session: https://app.devin.ai/sessions/1db04105a50342578181794804059512
Requested by: @pyramation