-
Notifications
You must be signed in to change notification settings - Fork 344
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
Discussion: replace-field transform #2975
Comments
Thanks for your feedback @ntziolis. I understand it takes some time to learn the transform, because is very powerful and you can achieve a lot, the configuration has also several options.
|
Thanks for taking the time to write such a detailed response. I will weave in my responses below. After playing more with the transform and taking into consideration the new functionality:
Please bear with me as I understand the below would change the nature of the transport significantly. What I think the transform should be able todo:
Based on the above lets reimagine how the import configuration could be structured transforms:
- copy-fields: # Not married to the name, but replace seems incorrect now since its only one of the use cases
steps:
- source:
field: Book.code # this notation opens up enabling regex later on
removeAfterCopy: true # default should be false if the name of the transform is copy
target:
field: NewBook.isAvailable # if field exists it gets overridden when it does not exists it is added automatically
removeAfterCopy: anyFieldNameOnSameTypeAsTargetField # this is to emulate replace + rename
scope: hoistValue What do we gain from this:
Side note on why regex patterns might be interesting:
I wanted to get your feel for what you think about the above prior to diving into each of the points you mentioned above. |
Thanks, @ntziolis. Reading your message makes me think that perhaps what you need is a different transform. Having a single transform that does it all might probably become too much as it even gets more complex. If I understand, what you probably need is a "move-field" transform that is able to move and/or copy/duplicate fields from one Type to one or more Types across your schema. Once you move all your fields in the way you want you can then apply replace-field to override the behavior of a field. I wouldn't mess with things like "remove any field on the target type". I would still leave that to the good old filter-schema transform. We can start thinking about the new transforms as I am stating above. |
@santino I think you are spot on with this.
I agree that having smaller less complex transforms would be preferred. Until then lets keep the replace field as is. I will have a look at creating the move/copy transform heavily borrowing from replace-field. I think the hoist transform can stay as is. That said I would wait to PR both these transforms together in sync with you. I'd love some input on the copy / move transform:
Let me know which route you prefer in regards to move + copy and I will start the work on those. |
From my response above:
So from there, I see a single transform that takes scopes to perform move/copy actions. The naming is a real point, not dumb at all. To start with it can have an API like this: transforms:
- transfer-field:
transfers:
- from: Query.availableBooks
to: Author.books
scope: copy Note how the field name is changing from "availableBooks" (source) to "books" (target). Probably From/to can be named source/target potentially, I am not passionate about it; I'd feel like from/to should be fine and in line with Rename transform. RegEx would be useful, but it doesn't necessarily need to be part of the initial layout. As a Mesh transform, this would be really useful when developers need to move fields that are automatically placed in Mutation/Query, since not all handlers are able to do this correctly. transforms:
- transfer-field:
transfers:
- from: Mutation.authors
to: Query.authors
scope: move
- from: Query.availableBooks
to: Author.books
scope: copy Finally, it might be nice to copy a field to multiple types, so Let me know your thoughts. It's great that you're willing to work on this transform but keep in mind that I'm also happy to help with this. |
This looks exactly like what i would need too. Ideally lets not forget the very powerfull regex options which can help reduce the size of the config.yaml transforms:
- transfer-field:
transfers:
- from: Mutation.(get.*)
to: Query.$1
useRegex: true
scope: move Has some work on this already started which i could contribute to? |
@santino I was aiming for working on this on the weekend, but If you want to get started no issues from my end. @Lappihuan We are running into very similar issues with legacy / badly designed REST endpoints, We are already making heavy use of the regex ability of rename-transform. Any regex functionality would be similar to that. That said Regex is def secondary right now. It might not be included in the first versions of these transforms. But it won't be forgotten as we need it ourselves as well ;) |
@Lappihuan I created an initial version of what I think the transfer-field transform should be able todo, see here #3041. Some deliberate limitations
Please let me know your thoughts. |
@santino As suggested moving this into separate issue in #2862
We have been successfully using the transform. Here are some comments:
from
/to
are backwards. Any chance this could be reversed? This actually cost us the majority of time.The text was updated successfully, but these errors were encountered: