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

fix(client, generator): Fix TS issues with generated client and add tests #1117

Merged
merged 18 commits into from
Apr 3, 2024

Conversation

msfstef
Copy link
Contributor

@msfstef msfstef commented Apr 1, 2024

Relevant issues: #1001 #925 #1114

Only one thing is fixed in this PR, the Relation is no longer imported if the data model has no relations in order to avoid unused imports TS errors.

Main changes are moving all of the generator tests into their own test directory rather than inside the source code, for consistency with the TS client, ease of use, and improved reusability of test utilities.

I've also added a sort of integration test for the CLI generation step, which is crucial to getting a working, compileable TS client as it modifies some of the Prisma generated typings. This test generates the client given a Prisma schema and performs all appropriate modifications to it, and then attempts to compile it with TS and specified compiler options.

Also found that with TS version >=5.4 we have stricter conditional type checking which breaks clients generated with Prisma versions earlier than 4.16.0 (see issue #1114), however 4.16.0 introduces breaking changes with the "extensions" feature, so I've added a hacky workaround for it:
https://github.com/electric-sql/electric/pull/1117/files#diff-fb0a50df4fc86f09b81a210162984d7822276fe19c8ae6496cf5ffe7d09f5adb

We can add more tests that would test various compiler options, making it easier to avoid regressions when users report them with more complicated schemas and TS compiler options.

Finally, I've added a Caution banner in our Usage section in the docs about requiring TS strict mode, since Zod has that as a requirement as well and its the reason why we see some inconsistencies in bug reports.

@msfstef msfstef requested a review from alco April 1, 2024 14:29
@msfstef msfstef mentioned this pull request Apr 1, 2024
@msfstef msfstef marked this pull request as ready for review April 1, 2024 14:48
@msfstef msfstef requested a review from samwillis April 1, 2024 14:50
@msfstef msfstef linked an issue Apr 2, 2024 that may be closed by this pull request
@msfstef msfstef requested a review from kevin-dp April 3, 2024 07:39
@msfstef msfstef force-pushed the msfstef/fix-generator-ts-errors branch from c3ca593 to 005af03 Compare April 3, 2024 09:20
Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
Left some minor comments here and there.

@msfstef msfstef merged commit d8ee5f0 into main Apr 3, 2024
13 checks passed
@msfstef msfstef deleted the msfstef/fix-generator-ts-errors branch April 3, 2024 11:48
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

Successfully merging this pull request may close these issues.

npm run build fails after project generation
2 participants