Depth respecting types on local API #8229
AndKenneth
started this conversation in
Feature Requests & Ideas
Replies: 3 comments 3 replies
-
This would hugely improve DX ;) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey @AndKenneth @HriBB! This is actually planned and I added it to the roadmap |
Beta Was this translation helpful? Give feedback.
1 reply
-
Opened a PR - #9782 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there, I've been using the local api in 3.0, and I've run into a bit of a pain point when it comes to the depth of relationship fields.
Lets say I have a type like this
The type
profileImage?: (number | null) | Media
means that whenever I retrieve profile using payload.find(), the returned documents will almost always return something with the type of Media, but the return type of payload.find() does not know this and types the result asnumber | Media | null | undefined
.This means that for every relationship, I have to check if the relationship exists, and do some type guarding logic to see if it's actually the ID (number) or if it's an object. At that point I could either return null on the items that are ids, or do seperate fetching logic to merge it in manually.
Ideally, the payload.find() function should know what it's returning based on depth, and therefore be represented in it's return type.
I think using gql even though I have access to the local api is a workaround, but feels like adding quite a bit of complexity for something that could be done fully within the local API.
Let me know what you think and if such a thing could potentially be on the roadmap!
Beta Was this translation helpful? Give feedback.
All reactions