How to get DataLayer transformer to run after optional Extension
Hi I’m working on an Ash DataLayer for Neo4j and I’ve noticed that the AshStateMachine has a transformer which adds the extended resource’s state_attribute to attributes so it introspects using Ash.Resource.Info, however this seems to only happen after my DataLayer transformer has already been run for the resource.
How can I ensure in my DataLayer that my transformer runs after the optional Extension transformer?
3 Replies
Solution
You can use
def after
and def before
to order transformersits a bit hacky, unfortunately, but it works
If you have a transformer who's only job is to persist some information about the resource, then put it in the
persisters
list instead of the transformers list. Just promise not to modify the resource in a persister and you're goodThanks Zach. I'd tried after? before however didn't understand the nuances and had another go after your answer. I see that after? and before? default to false and presume this when either is true this introduces an ordering constraint. I have a design choice about whether to simply and go after everything (put possibly conflict with other code where others have done the same, and/or limit future flexibility), or be explicit about what I need to go after. I did the latter, but to avoid spark 'Cycle detected in transformer order' on compilation, I did This was because AshStateMachine's AddState transformer has been set to run before Ash.Resource.Transformer.DefaultAccept, and after everything else except that. So I'm coupled to some Transformer module names in both Ash and AshStateMachine. What is best practice with these before and after clauses.?