Gonza

Gonza

Igniter for Express -> Ash rewrite?

Hey, I’m thinking about migrating a NodeJS backend to Ash. It’s one of those times in the life of a project where you start to think a full rewrite would be cheaper and better than fixing everything that’s been breaking up along the way.
Anyways, I was exploring a little the new Igniter project, and it got me thinking: is it a crazy idea if I try to replicate the old API surface via generators? It is a pretty standard REST interface with just a handful of main routes.
I know there’s going to be a lot of manual work migrating the actual core of the app and all the business rules, but the contract with the frontend clients is the one thing that must not change. Is this a good use case for using Igniter?
The general idea is to:

  1. Create and/or update a comprehensive OpenAPI spec of the entire existing backend
  2. Infer from there what the new resources should look like and transform this into Igniter commands (can probably be automated to a degree)
  3. Run the generators and let them create my resources and actions for each
  4. Fill all gaps with actual implementation details
  5. Profit?

Am I making sense here, or did I fundamentally misunderstand what codegen in Ash does and looks like?

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

Something like this is definitely possible. It is a big effort, and hard to say if it’s a good idea or not, I imagine it depends a lot on your domains. One difficulty may be the fact that Ash codegen tasks that you can use with igniter are not comprehensive by any means. They are made to produce useful starter points.

However, there are utilities you can all, like Ash.Resource.Igniter.add_new_action etc. to iteratively build up a resource, but those have basically been added over time as I’ve needed them.

The biggest challenge you may face realistically is that ash_json_api is primarily designed to help users create new JSON:API spec-compliant APIs. It is not necessarily designed to make building an API to an arbitrarily structured spec. You can absolutely write arbitrary API endpoints, generally by using generic actions, but you do end up hand-rolling some logic yourself if you do that.

Something worth pointing out is that if there is “just a handful of main routes”, you may not need to bother w/ all the fancy magic.

Not really a cohesive answer for you, but maybe some food for thought :laughing: Selfishly I love the idea of having something designed to reverse engineer API endpoints into an equivalent-ish internal resource structure and then allowing users to write in their own app logic. Sounds like a useful tool :smile:

Also Liked

Gonza

Gonza

Thanks! Yes, the old code looks standard-ish, but that’s obviously not the same as spec-compliant.
Still, now that I know it’s not a completely crazy idea, I might give it a try, even if just to learn how to work with generators. Thanks again!

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New

Other popular topics Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

We're in Beta

About us Mission Statement