feat(graphile-settings): enable many-to-many relations by default#854
Closed
pyramation wants to merge 2 commits into
Closed
feat(graphile-settings): enable many-to-many relations by default#854pyramation wants to merge 2 commits into
pyramation wants to merge 2 commits into
Conversation
Junction tables (e.g. contact_events, deal_contacts) now automatically generate clean shortcut fields that skip the junction table: event.contacts (instead of event.contactEventsByEventId) contact.deals (instead of contact.dealContactsByContactId) The InflektPlugin's _manyToManyRelation inflector picks short names (pluralized target table) and falls back to verbose defaults only when there is a naming conflict (direct relation to same target, or multiple m2m paths to the same target). To opt out for a specific junction table: COMMENT ON TABLE post_tags IS E'@behavior -manyToMany'; BREAKING CHANGE: many-to-many fields are now generated by default. Previously required @behavior +manyToMany on each junction table.
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:
|
…ault" This reverts commit 90f0548.
5 tasks
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
Flips the many-to-many preset from opt-in (
@behavior +manyToManyrequired per junction table) to enabled by default (upstream@graphile-contrib/pg-many-to-manydefault behavior).The
ManyToManyOptInPluginpreviously injected-manyToManyinto the inferred behavior phase, suppressing m2m fields unless explicitly opted in. ThatentityBehavioroverride is now removed, making the plugin a no-op passthrough. The upstream plugin's default (m2m enabled) takes effect.Combined with the existing
_manyToManyRelationinflector incustom-inflector.ts, this produces clean relation names likeevent.contactsinstead ofevent.contactEventsByEventId, with automatic fallback to verbose names on conflict.Export names (
ManyToManyOptInPlugin,ManyToManyOptInPreset) are preserved for backwards compatibility.Review & Testing Checklist for Human
graphql/server-test/__tests__/schema-snapshot.test.tsusestoMatchSnapshot()and the snapshot was NOT regenerated in this PR. New m2m fields will be added to every junction table in the test schema (post_tags). Run the test with--updateSnapshotand verify the new fields look correct.@graphile-contrib/pg-many-to-manyenables m2m by default when no behavior override is present. Confirm this matches the installed version's actual behavior.ConstructivePresetwill see new m2m connection fields appear on types with junction tables. Verify this is acceptable for all downstream projects, or consider a migration/versioning strategy.ConstructivePresetagainst a database with junction tables and confirm the generated schema has clean m2m field names (e.g.,contactsnotcontactEventsByEventId).Notes
ManyToManyOptInPluginis now semantically misleading since it no longer enforces opt-in. Consider renaming in a follow-up if that causes confusion.COMMENT ON TABLE ... IS E'@behavior -manyToMany'.Link to Devin session: https://app.devin.ai/sessions/5c8c35d8c2f3473dbc021b96fe2768c1
Requested by: @pyramation