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

What Is the Best Way to Load Related Data with GET Requests, Paginated Posts of a category?

What Is the Best Way to Load Related Data with GET Requests, Such as Paginated Posts of a Specific category? For example i do like this, i create media_limit and media_offset and i put it manually inside Ash.Query, but i think AshJson has better way? ```elixir...
Solution:
I don't know if ash_json_api supports paginated relationships. You may need to open a feature request.

mix igniter.install ash_authentication_phoenix fails to compile

``` mix deps.get mix ingiter.install ash mix ingiter.install ash_postgres mix ingiter.install ash_phoenix...
Solution:
Something is strange with the last release there if you add it in your mix exs like this it should work {:ash_authentication_phoenix, "~> 2.0 and < 2.11.0"},

"Second Newest" in has_many

I'm trying to set up a relationship or calculation that can let me express the "second newest" item in a has_many relationship. Grabbing the most recent is easy peasy: ```elixir ...

Codegen keeps recreating foreign key

I think this happened after I added on_delete: delete. It keeps adding this in for every subsequent codegen even though this was previously migrated. Is there possible circular logic? ``` def up do drop constraint(:github_installs, "github_installs_app_install_id_fkey")...
Solution:
As it turns out, making multitenancy changes for different resources across multiple commits, instead of all in one go, makes the resource snapshots go a little crazy with attribute changes. I decided to just do all the resource changes in one shot.

Suggestion how to add a title and description to each change in AshPaperTrail

Hi sorry, I’m planning to build a document system where each change must have a title and a short description provided by the user making the change. What would you suggest as the best way to implement this? If I add such fields, I believe I could easily integrate AshPaperTrail for version tracking in this part as well. ...

Ash GraphQL Subscriptions

Do AshGraphQL subscriptions fire when resources are updated via code interface or only when updated through GraphQL mutations? Having some trouble with getting my subscriptions to fire on my frontend when updating changes on my backend as part of a workflow...

Constantly having to sign in

Hi, I've had several users complain about having to sign into their account every time they visit our site I personally don't have this issue - potentially since I never close all my tabs whereas one user with the issue "usually closes all their tabs, plus closing chrome and turning off pc" so my thinking is their cookies are being cleared...

Authentication error

```elixir def user_fixture(attrs \ %{}) do email = Map.get(attrs, :email, "user-#{System.unique_integer()}@example.com") {:ok, user} =...
Solution:
Like usually i would set current_user: user on my conn but it appears ash is doing something different

GraphQL input type with `Ash.Changeset.manage_relationship` instead of `change manage_relationship(`

I'm working with Ash and AshGraphql and running into an issue with GraphQL input type generation when handling relationships in custom changes. Setup: - I have a File resource with a has_one :image relationship...

Populate relationships in autogenerated liveviews

Hi! Quick q: when I run the ash_phoenix generator, I end up with something like this in the image. Is there a way of populating the entries that are foreign keys with the actual content of the resource? Or is that something that must be done manually for every liveview? In my example, I would switch the UUID input with a dropdown of province names in the UI...
No description

mix ash_postgres.gen.resources is slow for large codebases

We're investigating using Ash with our existing codebase, which is quite large. We're looking to generate resources for existing Ecto schemas using mix ash_postgres.gen.resources, but we're experiencing slow performance with that command. It seems others have experienced this also (see https://elixirforum.com/t/integrating-ash-into-an-existing-project/66927/6). I've added some debug logging in ash_postgres, and it seems that the majority of the time is being spent in Ash.Resource.Igniter.list_resources(igniter): Generating resources from [OgatApp.Repo]...

Code interface struct argument

Is it possible to accept the resource struct as the code interface argument? Use case is I have an action that doesn't have any arguments and just toggles a value.
Solution:
then that's the default behaviour, unless I'm missing something in your question

For non data layer backed resources, prefer manual reads or generic actions to retrieve?

I'm going to get the data via Req.
Solution:
Depends on the interface you want, you get load and filter and all of that in reads, not necessarily in generic actions. so if it makes sense for you and you can turn the filter into params on the request, I would go with manual read, and if its just a simple call I would go with generic actions

Modifying the argument clashes with AshCloak changing the argument's type

Hello! I have a resource Platform with an attribute called credentials I want to have encrypted. This attribute is a union of embedded resources (representing credentials for different platforms). I have a change that sets the type attribute on the credentials union changeset to the same value as the platform.type is set - to avoid having to pass the same value twice and ensure the credentials type matches the platform type. After adding the AshCloak encryption, it replaces my argument :credentials, :map with its own argument typed as a union.This causes my change to fail, because:...

How to set user as actor after login?

When logging in with the sign_in_with_password action provided by AshAuthentication, I would like to set the loaded user as an actor so that it is possible to apply policies and load relationships already at login.

Changing attributes in action

I am trying to simplify the commented out code by using expr() , but i get an InvalidAttributeError with the hint string_downcase(nil) ```ex create :create do accept [:name]...
Solution:
You can't use expressions in that context

How to write a policy to ensure the user belongs to the tenant through a membership relation?

I have read many examples on multitenancy implementation with Ash, but most of these examples assume that the user belongs to one tenant. In my case, a user can belong to one or more tenants and can switch from one to another using a select list. We therefore have three resources, Organization, User, and Membership, to make the connection. Our application mainly uses a JSON API where we pass an authentication token in each request, as well as a custom X-Org-Id header with the current tenant ID the user selected....
Solution:
You should be able to create a SimpleCheck that can confirm that the actor has a membership for the tenant though: https://hexdocs.pm/ash/Ash.Policy.SimpleCheck.html#content

Anonymous Function Queries (Preparations)

I can't seem to get the syntax right, what am I doing wrong? ``` preparations do prepare fn query, context ->...

Loading data from an external API for a calculation

Hello! I have a resource that I would like to enhance in certain reads with a calculation that needs to be based off data from an external API. I'm mindful of not wanting to make the API request from within a transaction if possible. I thought of adding a preparation to the read action that will fetch the API data and put it into the context, which the calculation can use. ...
Solution:
🤔 yeah, its not great but that is probably the best way. YOu will likely want to switch on whether or not the given calculation is being loaded

Flattening Polymorphic Relationships in Ash GraphQL

Hey folks 👋 I’m working with polymorphic relationships in Ash and followed the guide here: https://hexdocs.pm/ash/polymorphic-relationships.html. I tried exposing it through the GraphQL API, and I’m a bit unsure if there’s a way to shape the schema the way I want. Right now, when I query bankAccounts, I get something like this:...
Solution:
no that would be graphql interfaces IIRC and we don't really have anything for this at the moment