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

Handling an %Ash.Error.Invalid{} in LiveView

Sorry for the noob question, but the AshPhoenix guide doesn't show any error handling. This is the code that I assumed would work, but update returns a {:error, %Ash.Error.Invalid{} } How do I get those errors onto the form? ```...

AshAuthenticationPhoenix Override Register Form

I want to add a form field on the register form, specifically tenant information for attribute based multitenancy. I see that there is a register_extra slot which receives the form, so I was thinking I could use that. Is there a way to override just the Password.RegisterForm to a custom component (assuming that is how I'd add the slot)?...

Ash Query filter function

For background information I have binary field in my datalayer called token when I call this the following function: ```elixir %{id: id} = user = insert(:user) assert {:ok, %My_App.Ash.User{id: ^id} = _user} =...

Does attribute `default: _` not set the struct's default value?

It appears that when defining an attribute's default: value, it doesn't set the default on the generated struct definition. I would expect it would, like Ecto.Schema does. Is there a reason it doesn't? Or is there a way of accomplishing this that I couldn't find in the documentation? ```elixir defmodule GF.Ash.WebComponent do use Ash.Resource,...

Issue using datetime_add

Hello, thanks again for the awesome library, I was trying to get into some more useful functionalities of Ash (calculations, etc.) and I'm mostly having a good time learning about it but there was one bit that I was having a hard time with. I was modeling an appointment, which I wanted to store the start date and the duration of. I thought calculating the end time would be useful, so I added made the following resource: ```elixir use Ash.Resource, data_layer: AshPostgres.DataLayer ...

Using Ash Resources as input types

I've occasionally encountered issues using Ash resources as input types to actions of other resources. The most common patterns I've seen to resolve this are to simply turn the inputs into a map and let manage_relationship figure it out, or to take as a parameter only the :uuid and similarly construct a map with just %{id: uuid} for manage_relationship. The culprit in some cases seems to be AshGraphql, which errors following this pattern: ``` == Compilation error in file lib/app/schema.ex ==...

Use Ash policies with simple functions

I was wondering if there is a way easy way to use Ash policies in places that you don't actually have an Ash resource. For example, I'm using FunWithFlags package for feature flags. I have a live view to handle the flags, and also a context module for it. Now I wan't to create some authorization code to this context module, and since I'm already using Ash for the rest of the system, I was wondering if there is a way to configure policies for a specific function....

Re-sort items in a form without submitting the form

Let's say I have a form to input a lit of to-do items, and want to give the user up/down buttons to reorder them based on priority. I can probably change the priority value via phx-click event, but I'm not sure what's the best way to display the items reordered based on the new priority values, without submitting the form. I'm guessing it should be done in the 'validate' handle_event, which currently only includes this.
form = AshPhoenix.Form.validate(socket.assigns.form, form_params)
form = AshPhoenix.Form.validate(socket.assigns.form, form_params)
...

cross_join on a Ash.Query

Hi I am able to do a cross_join on a Ecto.Query style. I am not able to convert to the Ecto.Query -> Ash.Query o r I am not able to perfrom Ecto.Query.from style cross_join on the Ash.Query in the prepare fn....

Destroying related resources

I have some related resources with existing actions utilizing manage_relationship to create and update them. For destroying, is it pretty much the same process, where the form has all the nested subforms and then I take those in through arguments and manage_relationship them and destroy them? I haven't seen anything explicitly on this topic in the documentation or here, pardon me if I've missed it. I want to make sure I don't leave any orphaned resources, which the loaded form on my edit pag...

Not seeing policy authorization errors

I'm adding policies to my app, feeling my way to the correct modeling of my domain, and when submitting an action all I see in iex is: `` [warning] Unhandled error in form submission for Panacea.Accounts.User.add_user This error was unhandled because it did not implement the AshPhoenix.FormData.Error` protocol....

Policy engine duplicates/optimizations

To what degree does the policy engine internally prevent reexecution of identical policy checks? Will it evaluate a given MFA only once per request? If so, is there a way to indicate that a policy check is e.g. not dependant on the underlying record?...

Guides or advice for migrating to Ash?

I have a small app with 3 tables in Postgres using Ecto.Table. I am migrating them to use Ash.Resource. When I run mix ash_postgres.generate_migrations for the first time, the generated migrations are to create tables that already exist and the table structures are different. Are there any guides or do you have any advice for reconciling the differences? Original ecto migration:...

Change storage_type of Ash.Type.Term to :binary?

When trying to persist a Term to postgres, I got this error because the term type is string. Changing the storage type/rerunning migrations fixed the issue for me. I can open up a PR if this change seems to make sense to you ** (Postgrex.Error) ERROR 22021 (character_not_in_repertoire) invalid byte sequence for encoding "UTF8": 0x83...

Integrating Google Login via Ash Aunthentication

I’m not sure if this is the right place to ask a question. But I wanted to integrate Google Oauth sign up and login via Ash Authentication. There’s no example of that in the docs, and I’m assuming it works only for email and password. I might be wrong here though 🙈...

Sequence type

Is there a way to get serial or bigserial for an :integer type in AshPostgres?

How to filter associations when preloading them?

I could probably do this with Ecto.Query instead, but I was wondering how I would do it with Ash.Query The scenario, I want to list out all of the Post and I also want to preload the Category association of each post. I also want to filter the categories to only ones that contain a specific category_id....

Casting Binary from Ash.Type.Binary to GraphQL type

Hello, I Have field with type :binary in my resource user which just represents a token generate using :crypto but I get this error Could not determine graphql field type for Ash.Type.Binary any ideas on how to solve this?...

How do I use relationship_display_fields

Could you please explain how to use relationship_display_fields? I couldn't figure it out from the docs or the tweet. Alternatively, is there a way to link the referencing id to the object in the admin panel? eg. if you have a user_id, clicking the user_id takes you to the page for that user...

Proxying actions to other actions

I've found it a useful pattern to do some transformations that then proxy the remainder of the work to another action—often the primary action of its type. The way I'm doing that is roughly: ```elixir actions do...