-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
prototype create and update input types for prisma #703
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: 132b6dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Thank you @hayes this has been so helpful. I have found one issue that I'm not bright enough to fix. Happy to make a repo if needed. for
But for Prisma to update we need...
Did that make any sense? |
@LawJolla yup! Great catch, makes total sense. This is definitely an oversight on my part. There are so many different combinations of options for mutating relations. This should be pretty straightforward to fix, I'll try to look into it this weekend. |
Terrific thank you! I did find one other. For Enum lists, Prisma Client adds push/set methods, e.g.
The generator.getUpdateInput("User") is generating...
vs
Happy to test any of it if you get a moment! Thanks as always. |
Cool, was just opening branch again to check this out |
910cd5b
to
63547bf
Compare
63547bf
to
1696d92
Compare
@LawJolla just published new snapshots (PR description has been updated) and also updated the example generator code. For update and updateMany on list relations, the fields now take an array of update objects that have For non-relation list fields, the builder now takes an array of values. prisma can update enum lists either using |
unfortunately sqlite doesn't support enums or scalar lists, so those are features I haven't really tested. I probably need to set up a way to test against postgres or something as well |
I use railway.app to set up a free postgres test server and it seems to work great, and I can connect to it fine using PGAdmin. In schema.prisma:
|
For generated input types that are ending up in the graphql schema I think a well-known convention is to suffix them with "Input" for example "UserCreateInput" instead of "UserCreate". Seems I'm just getting "UserCreate" from I believe this line of code: |
Awesome work! Can confirm it's working on my big mono repo. The only issue remaining is nested relation methods are objects instead of arrays. E.g. doesn't work as an array Maybe better illustrated in Prisma Client. |
1696d92
to
31e3878
Compare
@LawJolla just published a new version and posted an updated generator that fixes a bunch more issues. @thuperthecret2 updated some more of the input types to end with |
05a3dfe
to
c0a09aa
Compare
Thanks @hayes ! Almost there. I've only found a few more minor issues and am happy to make a repo if needed. On the Create and Updates, booleans are not available. E.g.
Using the generator Otherwise I have everything working and it's awesome! Thank you again. |
Cool! Will look at getting that fixed tomorrow or Monday. On my end I have a couple more things to finish up, but should be able to release this soon. Working on a codegen version of the generator that statically generates the Pothos definitions rather than doing it at run time, and need to add a flag to the Prisma generator to avoid generating the extra types when only using the main plugin (including the types for updates in the generated types adds a lot of new types into the Prisma types that can slow down type checking on large schemas) |
7706e48
to
f799c55
Compare
This adds support for new utils for creating Create/Update input types.
To test this out install the snapshot packages below:
🦋 @pothos/plugin-prisma@0.0.0-preview-20230107233924
🦋 @pothos/plugin-prisma-utils@0.0.0-preview-20230107233924
New methods:
UserCreateInput
)PostCreateNestedManyWithoutAuthorInput
)builder.prismaCreate
UserWhereUniqueInput
)UserUpdate
)PostUpdateManyWithoutAuthorNestedInput
)example usage:
Example generator
Here is an example generator class that can be used with
@pothos/plugin-prisma-utils
to automatically generate input types following some reasonable conventions. This can be modified to fit the patterns and use cases that make sense for your app:Click here to expand generator code
Generator ussage