logoalt Hacker News

sphyesterday at 8:52 AM6 repliesview on HN

I have shipped half a dozen projects based on Phoenix, Ecto and Live View. I love them all, and the language itself the most.

What does Ash Framework offer me? What pain points that I don’t think I have does it solve for me? This I still do not understand.


Replies

sansworkyesterday at 9:04 AM

I started using it because I just found it a much nicer way to define my data, auth and interactions with it compared to contexts. It also makes it easier to reuse it and because of the way the data is modeled you get a lot of nice things like the ashphoenix forms which make dealing with them a lot nicer in my opinion.

I'm also likely to be hiring soon so having a well defined way to well..define things seems like it will make it easier with onboarding but I haven't tested this yet.

(Been using elixir for about a decade)

mike1o1yesterday at 3:46 PM

I'm also very comfortable with Phoenix and Ecto (and LiveView), and initially found Ash a challenge to wrap my head around. After working through the book and really keeping an open-mind on my next project, I've found it a real joy to work with.

Keep in mind that Ash doesn't really replace Phoenix or LiveView (or Ecto), but it's built on top of it. You can still use Phoenix and LiveView the same way you are today, and just rely on Ash to build your context for you and how you interact with your resources. So I'd say it "replaces" Ecto in that sense (though it's all Ecto under the hood).

For me, I'm building a native app with a GraphQL backend and it has been an amazing productivity increase. With Ash, GraphQL on the backend and React and gql.tada (https://gql-tada.0no.co/) on the front-end providing a fully typed experience, I feel even more productive than using LiveView.

As a quick example - I have an existing derived GraphQL endpoint with a query for getting a resource, and I can have basic filters and sorting out of the box from Ash (i.e. filter by status, sort by name, filter by date greater than X, etc.)

Recently, I needed to build a feature to support adding a tag to a resource. I modeled the relationships (join models, etc.), made the necessary additions to my create/update actions and without _any_ changes to my GraphQL setup, I was able to support filtering my resource by tag (or tags) basically for free.

Can I build that in Ecto directly within my Phoenix context? Of course, but I didn't need to - Ash derived that functionality for me, and built that in, with all of the necessary preloading through dataloader and all of that for me, so the queries are optimized.

Ash is a huge mindset shift, and I think it'd be tough to incorporate it into an existing project, but if you're able to start a new project from scratch, I really recommend you give it an honest try. Especially if you think you might need to have additional data channels (i.e. LiveView and GraphQL or Json API).

arcanemachineryesterday at 9:29 AM

If you've tried to make a JSON API with Phoenix, it can be pretty cumbersome to generate an OpenAPI spec for the project. It's a very manual and tedious process, even when working with OpenApiSpex (the go-to Elixir library for generating an OpenAPI specs). And if your code implementation changes, then you often have to update your spec to match it.

With Ash, the same data used to model your application is also used to derive the data needed to build the OpenAPI spec. So there's a real value proposition there IMO. It eliminates much of the problems of keeping your spec in line with your code, since they are both modeled in a single location.

Disclaimer: I only learned this by working through the book, so I haven't actually gotten to experience anything off the happy path.

joshpriceyesterday at 10:24 AM

There is a post that Mike wrote that describes the thinking behind Ash's declarative approach

https://alembic.com.au/blog/declarative-programming

I just wrote a post which attempts to explain the big ideas in Ash as I see it. Would love your feedback on whether this helps answer your excellent questions

https://alembic.com.au/blog/essence-of-ash-framework

username3yesterday at 10:39 AM

Add an attribute to a model, run `mix ash.codegen`, it creates migrations for you.

Ash can do paging for you.

You don’t need to create a context file with CRUD functions for your Repo.

See the example repository for the Ash book.

https://github.com/sevenseacat/tunez/tree/end-of-chapter-10