-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add transformations phase #3
Conversation
c529806
to
f852e33
Compare
b721be7
to
d93e928
Compare
lib/phase/apply_transforms.ex
Outdated
transform_camelized = | ||
transform_name | ||
|> Atom.to_string() | ||
|> Macro.camelize() | ||
|
||
transform_module = | ||
String.to_existing_atom("Elixir.AbsintheHelpers.Transforms.#{transform_camelized}Transform") | ||
|
||
apply(transform_module, :call, [input | transform_args]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚳
please no - I hate this pattern.
We can use full module names in as the parameters like
meta transforms: [AbsintheHelpers.Transforms.ToInteger]
That won't be a problem with with alias, and will help a lot with the code navigation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point, but this is what allows us to define custom transforms directly in the project that uses this lib. See PR/module doc:
New transformations can be added in the lib/transforms/ directory, like
AbsintheHelpers.Transforms.ToIntegerTransform, or within your own project,
as long as they follow the convention. For example, you could define a new
:increment transformation tag and create a corresponding
AbsintheHelpers.Transforms.IncrementTransform to increment numeric input
values.
Maybe we can leave it until we figure out how to use dynamic meta to directly pass custom transform functions to this phase, see here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you are making my point.
If I were to pass the module name (aliased), then I could define simply MyApp.Transforms.Increment
and pass it there (as long at is will follow the behaviour). And I don't need to create module with "namespace" of the helpers lib.
You can not just override the module from deps - that's an compilation warning, and most apps won't build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, updating it now 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done ✅ , I like it! thanks e2eb945
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going to update the docs now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs updated ✅
lib/phase/apply_transforms.ex
Outdated
|
||
apply(transform_module, :call, [input | transform_args]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that's an bug
apply(transform_module, :call, [input | transform_args]) | |
apply(transform_module, :call, [input, transform_args]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice one, now fixed here ✅
d93e928
to
7f5ef87
Compare
|
||
@behaviour AbsintheHelpers.Transform | ||
|
||
def call(%Input.Value{data: data} = item, _opts) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that fail if used on any different type?
Also, it will fail with 500
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done ✅
c7c1002
to
5fd6c7c
Compare
85d943b
to
6d0c492
Compare
0449da7
to
32644ff
Compare
32644ff
to
9f85f6f
Compare
a6fb6d6
to
951ecb7
Compare
Identifies input nodes with transformation metadata and applies
them to the values. These transformations can be applied to both single-value
nodes and lists of items.
New transformations can be added in the
lib/transforms/
directory, likeAbsintheHelpers.Transforms.ToInteger
, or within your own project,as long as they implement the same behaviour.
Example Usage
To add this phase to your pipeline, add the following to your router:
To define a custom transformation on a schema field:
or on a list:
To define a custom transformation on a schema arg:
In this case, both the
Trim
,ToInteger
, andIncrement
will be appliedto the
employee_id
field.