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

An aggregate field loaded in create action isn't available for pub_sub?

publish :create, ["update", :aggregate_field1] in one of my resources fails with the following error, despite the fact that change load(:aggregate_field1) is in the action definition. If I remove the publish setting from pub_sub, the create action succeeds, with the :aggregate_field1 properly loaded to the changeset. I wonder if something changed about how pub_sub works in Ash lately, because my pub_sub and create action codes used to work fine. I did recently update ash to the latest version. Thanks....

Policies Usage

I am guessing policies always get evaluated before the action is called. Can I set an argument based on the results of a policies evaluation ?

Return aggregate after GraphQL mutation

I have an aggregate defined like this: ```elixir aggregates do count :events_count, :events...

Ash Record without persitance to the database

How can you manually create a record, so I can use it in my code, but not persist it to the database?

Parameterized custom policy checks?

Is there a way to pass a parameter to a SimpleCheck implementation module? Across most resources in my app, several checks need to be performed. Many of these checks are invariable, and can be put into a SimpleCheck module, but but one checks is variable, depending on a case-by-case basis. I would like to define one SimpleCheck module that does all these checks, and pass a parameter to it to handle that one variable case. Otherwise, I have to define repetitive checks in each of the resource modu...

Possible to skip validation for an action? (or best practices for working with external credentials)

My app has a resource called Vendor for interacting with external vendors, so we store user credentials for those vendors encrypted in the resource. I've now added a validation when creating vendors, that validates that the credentials are actually valid (by talking to the external API). This works great! However, I have a test suite that generates lots of Vendor resources in the course of testing things, and 99% of them don't use valid credentials (nor should they!) so now all the tests are failing due to this new validation. I can see a couple of options:...

No Absinthe schemas generated for resource

I've been using AshGraphql just fine, having created several resources that work with it. Then today, I created a new resource, and no Absinthe schemas are created from it.

How to have a "virtual field" in a resource based from another resource?

I have a Organization resource that has a many to many relationship with my User resource. That relationship is defined by this field in the Organization resource: ```elixir...

Keyset pagination with calculations

I have the following action in my resource: ```elixir read :all_by_name_or_address do argument :text, :string, allow_nil?: false...

Custom / virtual fields on read

Hi All, I am creating an API based on an old system and can't modify the original, but I want to change the way the resources are read. More specifically I want to set a certain virtual field based on the value of an existing database field. Normally this is something I would achieve with a virtual field and then modify the output in the view layer. But I understand the idiomatic way in Ash is to push as much as possible into the resource....

builk_create upsert seems to be broken

I have the following create in my resource: ```elixir create :create do description "Creates a new predefined school"...

Can I expose a generic resource action via an Ash GraphQL mutation?

Hi, suppose I have an Ash resource with a generic action: ```elixir action :my_generic_action, MyApi.MyResource do argument(:arg_1, :string, allow_nil?: false)...

What happens when :prev page request is used but there is no previous page?

Need help understanding how keyset pagination works. Here are the steps I took. 1. 'search-change' handle_event does the initial search properly. The query output is saved in a variable called page. 2. When the 'prev'' button is clicked triggering 'prev-page' handler, (as expected) nothing happens. 3. When the "next" button is clicked triggering 'next-page' handler, nothing happens. I expected it to return the iintial search results again, or the set after that. ...

Expand Ash.Query.Operator built_in operators

Right now, ash comes with a bunch of built-in operator for queries (is_nil, eq, in, less_than, etc). These are great, but it is not enough in some cases. For example, let's say I want to create a similarity operator? The obvious answer is that I can implement it myself using the Ash.Query.Operator.__using__/1 macro....

Custom type don't show all possible filters in GraphQL Api

In my project I have the following type: ```elixir defmodule Marketplace.Ash.Types.Currency do @moduledoc false...

Can't destroy record, would leave records behind

I'm trying to destroy a record from my database but I'm getting the following error: ``` ** (Ash.Error.Invalid) Input Invalid * Invalid value provided for id: would leave records behind....

Bulk create form

I currently have a phoenix form to create an invite. The form is connected to the create action on the Invite resource. The only field is email. I want to change the form to accept multiple email addresses--comma separated--and then create multiple invites. The create action currently generates a token and sends an email, so it's bit more complicated than a db insert. I haven't used manual actions, the new bulk_create feature, or Ash.Flow yet. I'm not sure which is the best route....

Metaprogramming with expressions

I am generating a module at compile time, and my Ash.Query.filter doesn't work as intended. Please see comment below ```elixir defp generate_oban_worker_module(module, cache) do
contents =...

Ash.Error as application's exception/error module

Hello.
In a previous project (which did not use Ash) we had a top-level Error module that had a defexception in it with all the typical error things, like codes, messages, and metadata. It also had some other functions to do things like, for example, report the error to various sinks (Logger and an APM platform). The idea was to replace returns like {:error, :some_error_code} or {:error, "some message"} with {:error, MyApp.Error.exception(...)} and let code that receives such errors decide it it wants to report, re-raise, etc etc. With the existence of Ash.Error and all the helper code around it, I wonder if it makes sense to build an application's top-level error off of Ash.Error instead of something custom? Even if those errors might not have anything to do with Ash? Is it the intention of Ash.Error to be used purely for errors coming from the framework, or is it a building block for user-defined errors?...