Add select
for hooks to fetch relationship data
#8912
wysher
started this conversation in
Feature requests
Replies: 1 comment
-
Hi @wysher,
However, it is different in that it isn't asking to change the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
all hooks have access to item and for most cases it works fine, but for many relation fields it doesn't include any data for them (or even a key). No matter if hook is part of field config or list config.
Here's example schema for Post:
when using hook, let's say
validateInput
,item
arg looks like this:but there's no tags here.
Under the hood,
item
comes from asyncprisma.findFirst
method. By design this method returns only ids for single relationship fields (like authorId above).As a developer I would like to get all the information for item, but to get them I need to call another
prisma.findFirst
within validateInput hook. So there's two async calls for the "same" data.I change some keystone code to have those data, which additionally passes to
prisma.findFirst
for missing many relationships and map them, so the result is:
Here's the code:
https://github.com/wysher/keystone/pull/1/files#diff-cafe5f9fd16c4aff83f4b1bc269237512a4e3ea5ef17e6f48e97b49e3537b3aaR33
I'm not sure if you deliberately doesn't include relationship data here for performance reasons.
If it's the case, my proposal here will be to refactor item a little bit, and call
prisma.findFirst
on demand.item
may be a function, or to not have breaking changes we can use object getter.Let me know what do you think of change I made. If it's ok with you I'll make proper pull request.
Beta Was this translation helpful? Give feedback.
All reactions