Ash Framework

AF

Ash Framework

The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.

Join

support

showcase

today-i-learned

spark warning on compilation

I get bombarded by these warnings: `` warning: Entity without __spark_metadata__ field is deprecated. Entity Reactor.Dsl.Middleware does not define a spark_metadata field. This field is required to acces s source annotations. Add spark_metadata: nil` to the defstruct for Reactor.Dsl.Middleware. (elixir 1.18.4) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2...

usage rules req me to change igniter `only`

In a default app igniter is not in prod but when i try to add usage rules via the expert LS it says that there's a version conflict.
Solution:
But I'm telling you to add that to your usage rules dep lol

Composite primary keys vs through

It looks like destination/source_attribute_on_join_resource both expect an atom. Is it possible to reference a composite key on a join table? I am trying to set up a many_to_many relationship.
Solution:
But you can use a has_many with a filter

Can I instruct Ash to force update a CiString value regardless of comparison result?

I'm using Ash.CiString on a resource field (backed by postgres citext) for all the uniqueness constraint validation goodness, but recently discovered that Ash is skipping updates to the field value when only the case has changed. I know, I know: why am I using a CiString if I don't want case-insensitive comparison? Because I don't want to clobber other records with the same case-insensitive name. But I do want to give the user control to update the casing of the value on an individual record. I have a NameCollissionPrevention validation that ignores the current record in question when deciding if the record update is valid, so I don't think this is programmer error, it feels like Ash is ignoring the field in the update b/c it compares as equal. Maybe CiString isn't the right tool for the job in this scenario. I'm curious if Ash provides a way to say "you can update this value to anything (and any case) you want". ...
Solution:
I ended up modifying it a bit b/c the :name arg isn't required: ``` change(fn changeset, _ctx -> case changeset.arguments[:name] do...

Ash Policy DSL Syntax Issues - Need Help with authorize_if and policy_group

I'm implementing role-based authorization in an Ash 3.5.42 application but running into compilation errors with the policy DSL. Despite following the documentation examples, I'm getting undefined function authorize_if/1 errors. Current Setup: ```ex...

Cinder keyboard bindings

How do I get keyboard bindings to work with Cinder filters?

Where/How to deploy my ash project

Hi folks, I'm new to ash and my app is getting very mature and reached at a point where i need to show to the people. But I'm wondering where and how to deploy a ash/elixir backend? My prev exp is with JS and we use an almost drag-n-drop deployment platforms railway/vercel/cf, etc...

Ash Union Calculations

I'm still wrapping my head around polymorphic relationships and was wondering why a calculation on one needs to return a %Ash.Union{}? E.g. ```...
Solution:
We don't check that calculation return values match their declaration (for performance reasons)

Ash for cli apps

I am very new to Ash. I am working in an existing Elixir app that is a cli tool (for now, but will evolve to several parts: web, api, etc). Is Ash suitable for this use case?

When to use Ash.Oban vs Ash.StateMachine

have a very simple pipeline that needs to be durable, i.e. automatic retry. I am porting a Python code that uses Temporal.io durable execution.
I am not sure if I have to use Oban or StateMachine, when is each more suitable?...
Solution:
in general combining ash_state_machine and ash_oban to trigger state transitions is one of my favorite combinations of Ash features out there

Primary key not guaranteed unique?

I configured a column on my resource with primary_key? true and noticed that I can insert multiple records with the same key. Is that intended behavior? I figured for a primary key I should not need to set up a separate identity.
Solution:
primary_key? true on multiple attributes creates a composite primary key

AshAuthentication and UserIdentity for Oauth / Scopes

I'm getting my head wrapped around the framework so I will ask some stupid questions, my apologies in advance. I want to use google oauth / refresh tokens to have access to a user's google account in order to provider them services. I currently have AshAuthentication set up with google oauth strategy and it's immediately working. I did some searching for how to access and to specify the scopes. I found some resources about UserIdentity but I'm struggling to learn more about how to implement it. I am still very much adapting to the mental model of the framework. But my question for you is.. what concept am I missing / why am I struggling to find resources to understand how to better implement UserIdentity. Of course my ignorance is 100% responsible for this. But I'm not currently seeing how I can learn these things on my own and I'd prefer not to bother you all every time I have a basic question....

Is it possible to work around AshAuthentication tokens with read only connection?

Hey everyone! 👋 I'm working with Ash Authentication using Google OAuth and Magic Link strategies. Sometimes we want to test with production data, but we connect via a read-only database for safety. The problem is that Magic Link token generation requires writes, which obviously fails on the read-only connection....

how to config user_id inside PaperTrail

Hi, sorry. based on this doc https://hexdocs.pm/ash_paper_trail/getting-started-with-ash-paper-trail.html#associating-versions-with-actors i configured my resource like these code, but when i see the user_id in Version with Ash.read all of them is nil ```elixir paper_trail do primary_key_type :uuid_v7...

Attempted to update stale record error update record in a loop

I think it is from ecto and i miss something, i do not want to use Ash generator here! so with a sleep it returns error ``` ** (Ash.Error.Invalid) Bread Crumbs:
Error returned from: MishkaCms.Runtime.Layout.update...
Solution:
I wrapped it inside, i think it fixed my code 🧑‍💻 ``` Ash.DataLayer.transaction(MishkaCms.Runtime.Layout, fn -> .... end)...

Extending a spark extension?

I'm working with ash_graphql. The codebase I'm working in has a bunch of old non-ash JSON:API routes. There's a part of the application that decides whether or not to send requests to the DB read replica or the writer, which for the old JSON:API stuff was wired up to go to the writer if it was a POST request, or also if it was in a list of ignored routes. For graphql this breaks down since everything comes through a POST, so I'm reworking how it decides to use the reader when it's an ash_graphql request. In general I can anchor on whether it's a query or mutation, however some queries will end up doing writes as well. So, I'm hoping to be able to have a simple way to just tack on an extra config to any query in the graphql queries block that allows marking that query as intended to use the writer. tl;dr, I'd like a way to add a new piece of config to the various queries config objects that some custom plug would be able to hook into. I swear I've seen some way to do this in docs somewhere but it's eluding me now 😅...

Load data works in terminal but in json api it returns empty

Inside this code i am trying to load all versions of a record for example, it works in my terminal and paper_trail_versions has some records as a list but in api json call the paper_trail_versions is [] empty ```elixir action :list_versions_api, :struct do constraints instance_of: MishkaCms.Runtime.Layout argument :layout_id, :uuid, allow_nil?: false...
Solution:
But you'd add a calculation like sorted_versions or something

Are there special requirements for returns :map in RPC actions?

Hi folks I have a custom action that works perfectly in the backend (logs show correct data) but AshTypescript RPC returns empty {} to the frontend. ```ex In Fmma.Inspections.Inspection resource...

Form validation message missing field name

Hey folks, I've just purchased the ash book and I'm just at the beginning. For some reason my form validation isn't showing any field names in the error message. I've done exactly as the book says, as far as I can tell, and I'm not sure if this is just how it's supposed to be. Any advice is very appreciated :) ```elixir...
Solution:
that's how it is supposed to be, as shown in the book 🙂

When trying to set password using my own update I get Postgres type error in AshAuthentication

This boils down to that Postgres can't find the correct type for a parameter. Is that something I can take care of or is it somewhere else? <former gist-link, replaced by many messages below>...