Sharing field implementation with different field names #813
Unanswered
danielbuechele
asked this question in
Q&A
Replies: 1 comment 2 replies
-
I think you just need to make the parent shape a generic in your helper, and type the field name arg as keyof ParentShape |
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
-
A few of my nodes expose access to an image asset type, which is defined as follows:
However, the name of this field is different for my nodes. On some it might be called
image
, on otherspreview
orthumbnail
. What is a good way of sharing the implementation of this field and args, while allowing different field names? I could just have a function which returns the arg and another one which resolves the field, but now args and resolver are disconnected, and making this type safe is hard.I ideally I'd have something like, which generates the entire field, but again I'm running into trouble making this type-safe.
Any other alternatives how to do this? If all of the fields had the same name, it would be easy to implement using an interface, but because they have different names, this isn't really possible?
Beta Was this translation helpful? Give feedback.
All reactions