Ash Elixir

AE

Ash Elixir

Join the community to ask questions about Ash Elixir and get answers from other members.

Join

support

showcase

today-i-learned

Resource MyApp.Accounts.FriendLink is not present in any known Ash.Api module.

I'm getting the above warning even though this module is indeed listed in the registry. What am I missing? ``` defmodule MyApp.Accounts.Registry do use Ash.Registry,...

Implementing token inactivity timeout with automatic expiry extend

Hi folks, I am using the ash_authentication password strategy with my resource configured to store all tokens, and require token presence. The project has a VueJS frontend that communicates with the backend via GQL. When a user logs in, the frontend receives the token and includes it in the header as a bearer token. This is all working well. I have set a short-lived token_lifetime, and would now like to add a way to log the user out after a period of inactivity, and also extend their session expiry whenever they make a request to keep them logged in beyond the initial expiry time. I have realised that this may be at odds with using JWTs as the token, as they are effectively tamper proof....

How to: DateTime validation with compare/2

Im trying to compare datetime in an action with compare/2. Code looks like this: ```elixir validate compare(:resumes_at, greater_than: DateTime.utc_now(:microsecond)), message: "resumes_at must be in the future", where: [present(:resumes_at)]...

Using code_interface args

When I use ``` code_interface do define_for Office.ToDoList define :create, args: [:subject]...

ManualRead not resolving in graphQL

Hi All, I have created a ManualRead module to implement a tricky relationship which has defaults that can be overridden. Before going too much into details, this ManualRead is working fine when I use the code interface, but when I call the same action through graphQL the values I expect are all nil. It is a bit too long to paste here, but was wondering if there is something general I need to think of when doing this?...

AshAuthentication missing notifications when running Expunger

I noticed that, for time to time, AshAuthentication Expunger is running and it will generate a warning because of a missing nofitication for removing tokens. Here is one of these warnings with the full stacktrace:...

How to effiently add thousands+ of entries to `many_to_many` relations

I'm having a brain freeze at the moment. I have Controls and Requirements with a many_to_many relation (ControlRequirement). I can set those using manage_relationship... however I now have the use case where I need to add new relations one by one ... thousands of them. My understanding is that manage_relationship with :append_and_remove expects a list ... so I'd need to fetch the list, add an item, remove duplicates and then provide this to manage_relationship, correct? I assume `:ap...

(Postgrex.Error) ERROR 42P18 (indeterminate_datatype) could not determine data type of parameter $1

Gotting the above error while try this code for a regex search. Ash.Query.filter(fragment("task_id ~* '?\\d+'", ^prefix)) The Ecto doc suggests explicitly defining type withtype(^prefix, :string) but I'm not sure how it's supposed to fit in as an Ash.Query. expression....

InvalidFilterValue for read action

I have this relatively simple read action, but it keeps on failing with a %Ash.Error.Query.InvalidFilterValue ```elixir read :for_organisation do argument(:organisation_id, :integer) do...

Use without data layers

Hi, I'm trying to fit the example from https://hexdocs.pm/ash/use-without-data-layers.html to call a web api, `defmodule Asher.Edge.FetchMyip do...

How To: Atomic update with a where clause

I'm trying to implement this workflow: Update a timestamp atomically on an existing record if the new timestamp is greater than the old one, and the old one hasn't changed while im updating it(optimistic update). I know atomics just dropped on Ash core so wondering if this could be achieved with it. This is the ash action in question:...

Adding Postgres NULLS LAST to an Ash prepare build sort

Hi! I spent a little bit trying to figure this out and wanted to share to make it more searchable. Ash's sorts actually support NULLS FIRST and NULLS LAST as different options passed instead of the normal :asc, :desc, etc: ```elixir...

How To: Exclusion constraints in AshPostgres

Im setting up an exclusion constraint an a few time attributes. I dont see anywhere in the docs an affordance for exclusion constraints, only check constraints, so what I did is create the migration for the exclusion manually, but now im getting an ecto error asking me to add it to the changeset. ``elixir If you would like to stop this constraint violation from raising an exception and instead add it as an error to your changeset, please call exclusion_constraint/3` on your changeset with the constraint...

Ash Authentication TOTP

Just exploring some of the features of Ash as I am considering it for a new service I am implementing. I went through the tutorial of setting up Ash authentication for a Phoenix app which worked just fine. However I was unable to determine how I could extend it to implement 2FA / TOTP using say Nimble TOTP at https://github.com/dashbitco/nimble_totp ...

Using pgsodium with Ash

Wondering if there would be an Ash way to do column encryption with pgsodium? Currently I have just done them directly in the migrations files with execute("SECURITY LABEL FOR pgsodium ON COLUMN table.column IS 'ENCRYPT WITH KEY COLUMN key_id NONCE nonce ASSOCIATED association_id'") for each column I want to get encrypted. Would custom_statements in the Ash resource be the place to do this?...

AshOban trigger `read_metadata` passed to action as argument?

Hello! In the AshOban code, there is this documentation statement: https://github.com/ash-project/ash_oban/blob/main/lib/ash_oban.ex#L129 I can't see where metadata is passed to the update action. I presume it would be somewhere here: https://github.com/ash-project/ash_oban/blob/main/lib/transformers/define_schedulers.ex#L477-L492 What am I missing? Has this part of the feature been missed, or was it never the intention to grab the metadata back out of the Oban job table into Ash land again?...

Is there a good way to version string documents in ash?

I have a table of TODOs, with one column, a :description. A user can modify a TODO's description. I'd like to efficiently store the history of a document, so that the user can look through different past versions of the doc. Is there an easy/built-in way to do this in Ash?

set action argument in form

I have two resources: User and Account I'm creating an AshFrom and use that to create an User. On submit, just before creating the User i need to create an account and pass it as argument to the action used in the for_create of the form. Unfortunately i can't manage to find a way to set the argument in the form before it calls the action...

White labeling the Ash Admin

Hi all! I'm looking at having the Ash Admin as part of the internal product of ours. Some questions: - Is it possible to customize the UI components? - Is it possible to show the admin pages below the tab interface of our website? - Is it possible to have the root layout apply to the Ash Admin pages?...

Migration from MySQL or use thereof?

Hi All, This may be a strange question. I am learning ASH and Phoenix which are excellent....