Repository navigation
Prevent self-referential imports in code generation - #25
Open
kac-axelor wants to merge 2 commits into
Open
kac-axelor wants to merge 2 commits into
kac-axelor wants to merge 2 commits into
Conversation
Contributor
Author
|
Merge coordination with #33 — no git conflict, but a test interaction: Whichever lands second should update the test to cover both collection shapes, e.g. add a ManyToMany self-relation: // entity fields: + { name: "related", type: "ManyToMany", target: "Category" }
expect(code).not.toMatch(/from "\.\/Category"/);
expect(code).toMatch(/parent\?:\s*Relation<Category>/);
expect(code).toMatch(/children\?:\s*ToMany<Category, "parent">/);
expect(code).toMatch(/related\?:\s*Relation<Category>\[\]/); |
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.
Reopens the fix from #20 (closed as superseded, but the cases it covers are still broken on
dev).What this fixes
Self-referential relation imports. A tree-shaped entity like:
…causes
RelationalField.actualType(src/schema/schema-generator.ts:232-236) to registerimport { Category } from "./Category"in the generatedCategory.ts, producing:Relationship to d2ce123
d2ce123 ("Drop self-referential extends/implements at the source") fixes a different layer — the
extends/implementsclauses in the class declaration. It does not touch relation imports, so this PR is complementary, not redundant.Approach
Filter self-referential imports at the
CodeFilelevel — a single choke point that covers any generator that happens to emitimport { X } from "./X"for the file currently being written. Cheap, local, and future-proof against new generators.Test
Added a regression test (
schema-generator.test.ts) using a self-referencingCategoryentity withparent: ManyToOne(target: "Category")andchildren: OneToMany(target: "Category", mappedBy: "parent"). The test asserts:import { Category } from "./Category"line in the generated file.Relation<Category>andRelation<Category>[].The test fails on
devwithout this PR'sCodeFilefilter and passes with it.