typegraphql-prisma icon indicating copy to clipboard operation
typegraphql-prisma copied to clipboard

Tackle the circular imports without needing to use `commonjs`

Open MichalLytek opened this issue 4 years ago • 4 comments

Fantastic work on transpiling @MichalLytek. I was thinking about how we could tackle the circular imports without needing to use commonjs on everything. I was wondering if bundling all the transpiled code into a single file would be possible 🤔
Bundling would also reduce the size if only by removing all the import statements which in turn may reduce write time to disk as there is less to write and it is all in only a few files rather then what could be up to hundreds.

If we can reduce generation times that would be great as then we could also improve testing speed.

Originally posted by @wSedlacek in https://github.com/MichalLytek/typegraphql-prisma/issues/1#issuecomment-685188342

MichalLytek avatar Oct 12 '20 11:10 MichalLytek

I think a way to support that would be a generator option emitSingleFile. Then we could just easily change default tsconfig setting and generate one big transipiled file instead of tons of files.

However I'm not sure if it fixes the circular imports issues then. While TypeGraphQL decorators are lazy and can handle that, Typescript reflection could break in that situation because of referencing not existing yet values.

I need to check that idea first on two simple TypeGraphQL classes before digging more into it.

MichalLytek avatar Oct 12 '20 12:10 MichalLytek

I finally figured out this was the building problem I had.

After emitting the generated resolver non-transpiled into a different folder, my project would build but trying to run the bundle would crash instantly with a "Cannot access X before initialization" error, because my tsconfig didn't have the module option set to commonjs.

Maybe mention it in the docs in the meantime ?

doei avatar Aug 15 '21 08:08 doei

@doei Done via fbd3b6f 😉

MichalLytek avatar Dec 08 '21 12:12 MichalLytek

Given the issue I described in https://github.com/MichalLytek/typegraphql-prisma/issues/10#issuecomment-1137308858, this seems like a good strategy to resolve it. I'm going to look into this futher

mattkindy avatar May 25 '22 21:05 mattkindy