Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular dependencies with generated builder files #1815

Open
Swahvay opened this issue Jun 7, 2024 · 3 comments
Open

Circular dependencies with generated builder files #1815

Swahvay opened this issue Jun 7, 2024 · 3 comments

Comments

@Swahvay
Copy link
Contributor

Swahvay commented Jun 7, 2024

This is maybe a little fringe, but I'm hoping it's also an easy fix.

When my core library is packaged and used externally, the generated files' references that go through index.ts, will sometimes cause circular dependencies. Specifically, the builders. I've figured out that simple referencing the files directly prevents the loop. I think this stems from a builder being imported through index.ts, so when it also tries to load ents through the same file it won't wait for all of the imports to finish, causing ents to try to load before their bases.

The only fix that needs to happen is to just reference the ents directly. I make these changes manually in my builders and everything works. It's just annoying to have to revert changes in git every time I run codegen for the builders (unless they have meaningful changes, which means I make this change manually again).

src/ent/generated/vaulting_entry/actions/vaulting_entry_builder.ts
image

@lolopinto
Copy link
Owner

hmm, why is a builder being imported through index.ts? do you know where that's from? that should be fixed?

if you set userOverridenFiles in ent.yaml to a list of relative paths, they won't be overridden by codegen

i.e.

userOverridenFiles:
    - src/ent/generated/user_base.ts
    - src/graphql/generated/resolvers/user_type.ts

added in #1520

@Swahvay
Copy link
Contributor Author

Swahvay commented Jun 7, 2024

Maybe the builder isn't being included in index.ts. But this definitely is fixing my problems. In general I've always found it safer to import files directly than through an index list. I realize I'm sort of solving the symptom more than the problem, but a couple bandaids might be all that are needed here. Also, I'll remember what you did to fix this and if I need to also apply this change to any other types of files (like ent actions), then I can submit a PR instead of making an issue.

As for using userOverridenFiles, I don't actually want codegen to ignore these files since they do occasionally still get updates from schema changes and I want to make sure codegen doesn't skip them.

@Swahvay
Copy link
Contributor Author

Swahvay commented Jul 10, 2024

I believe the fix could be made here:

uniqueNodes := nodeData.getUniqueNodes(true)
for _, unique := range uniqueNodes {
ret = append(ret, &tsimport.ImportPath{
Import: unique.Node,
ImportPath: codepath.GetExternalImportPath(),
})
}

If the codepath.GetExternalImportPath() would take the nodeData, then it could simply reference nodeData.PackageName and append that to the import path. Alternatively, the filename could be generated via names.ToFilePathName.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants