edwinofdawn
edwinofdawn
AEAsh Elixir
Created by edwinofdawn on 7/18/2023 in #support
Calculatated fields and AshGraphQL
It works thanks, I had copied some code marking them as private, my bad
3 replies
AEAsh Elixir
Created by edwinofdawn on 6/13/2023 in #support
Policies Usage
I was trying to avoid code forking and using the same action to filter and return results depending on whether the user is an admin or normal member I opted against it though
9 replies
AEAsh Elixir
Created by edwinofdawn on 5/24/2023 in #support
Returns type
this worked thanks @barnabasj
16 replies
AEAsh Elixir
Created by edwinofdawn on 5/23/2023 in #support
Intercept Identities Behaviour
Update my code to this elixir
change fn changeset, _struct ->
token = Utils.generate_token()

changeset
|> Ash.Changeset.change_attribute(
:confirmation_token,
Utils.hash_token(token) |> Base.encode64()
)
|> Ash.Changeset.before_action(fn changeset ->
IO.inspect(changeset)
changeset
end)
|> Ash.Changeset.after_action(fn
_changeset, {:ok, result} ->
{:ok, _} =
EmailWorker.enqueue(%{
customer: result,
token: Base.encode64(token)
})

{:ok, result}

_changeset, {:error, error} ->
IO.inspect(error, label: "error")
# generate token
token = Utils.generate_token()
{:ok, customer} =
GF.Customers.Customer
|> Ash.Changeset.for_update(:update, %{confirmation_token: token})
|> GF.Ash.update()

# send email
{:ok, customer}
end)
change fn changeset, _struct ->
token = Utils.generate_token()

changeset
|> Ash.Changeset.change_attribute(
:confirmation_token,
Utils.hash_token(token) |> Base.encode64()
)
|> Ash.Changeset.before_action(fn changeset ->
IO.inspect(changeset)
changeset
end)
|> Ash.Changeset.after_action(fn
_changeset, {:ok, result} ->
{:ok, _} =
EmailWorker.enqueue(%{
customer: result,
token: Base.encode64(token)
})

{:ok, result}

_changeset, {:error, error} ->
IO.inspect(error, label: "error")
# generate token
token = Utils.generate_token()
{:ok, customer} =
GF.Customers.Customer
|> Ash.Changeset.for_update(:update, %{confirmation_token: token})
|> GF.Ash.update()

# send email
{:ok, customer}
end)
The problem ispre_check_with clearly states it can only be used in a before_action hook. The above solution does not work . I can only see the error being thrown by the database("Postgres ") itself.
26 replies
AEAsh Elixir
Created by edwinofdawn on 5/24/2023 in #support
Returns type
since the return type is a User the fields I query need to exist on the user.
16 replies
AEAsh Elixir
Created by edwinofdawn on 5/24/2023 in #support
Returns type
this does not work as this is a graphql API
16 replies
AEAsh Elixir
Created by edwinofdawn on 5/24/2023 in #support
Returns type
Oh okay, I still don't how this will look like , will the API still return a user type ? If so how can the token be accessed?
16 replies
AEAsh Elixir
Created by edwinofdawn on 5/23/2023 in #support
Intercept Identities Behaviour
Nice let me try this
26 replies
AEAsh Elixir
Created by tommasop#2001 on 5/22/2023 in #support
Bulk create action Changeset Error
Not sure what's going on here . maybe elixir

I'm using bulk create action with upsert and I'm tryong to test that not valid resources will not be created.

I'm using bulk create action with upsert and I'm tryong to test that not valid resources will not be created.
elixir upsert_identity: :unique_esolver_id, `` :unique_esolver_id should be unique_resolver_id`
59 replies
AEAsh Elixir
Created by edwinofdawn on 5/16/2023 in #support
Ecto.Multi Usage
tested it and it works
41 replies
AEAsh Elixir
Created by edwinofdawn on 5/16/2023 in #support
Ecto.Multi Usage
🎉 thank you @Zach Daniel
41 replies
AEAsh Elixir
Created by edwinofdawn on 5/16/2023 in #support
Ecto.Multi Usage
okay and how is the token param passed from the update to read_action read_action because that is failing elixir

key :token not found in: %{}

key :token not found in: %{}
41 replies
AEAsh Elixir
Created by edwinofdawn on 5/16/2023 in #support
Ecto.Multi Usage
lastly, what is the acceptance criteria for the fetched resource in read_action. for update. I tried elixir

argument :user , :struct

argument :user , :struct
which was a bad idea . elixir

argument :email, :string

argument :email, :string
but the above should have worked but I get The field "email" is not unique in type "UpdateUserInput I have identities setup elixir

identities do
identity :email, [:email]
identity :token, [:token]
end

identities do
identity :email, [:email]
identity :token, [:token]
end
for uniqueness and the unique_index is migrated in my migrations file. whats missing and how do I receive the user fetched from read_action ?
41 replies
AEAsh Elixir
Created by edwinofdawn on 5/16/2023 in #support
Ecto.Multi Usage
thanks that got it the first part working .
41 replies
AEAsh Elixir
Created by edwinofdawn on 5/16/2023 in #support
Ecto.Multi Usage
elixir

prepare fn query, _ ->
token = query.arguments.token |> Utils.hash_token() |> Base.encode64()
Ash.Query.filter(query, token == ^token)
end

prepare fn query, _ ->
token = query.arguments.token |> Utils.hash_token() |> Base.encode64()
Ash.Query.filter(query, token == ^token)
end

I get two errors from this token is flagged as undefined but it exists in my resource attributes and ^token cannot be used outside of match clauses.
41 replies
AEAsh Elixir
Created by edwinofdawn on 5/16/2023 in #support
Ecto.Multi Usage
Thanks let me try this out 👍
41 replies
AEAsh Elixir
Created by edwinofdawn on 5/16/2023 in #support
Ecto.Multi Usage
Yes into graphql
41 replies
AEAsh Elixir
Created by edwinofdawn on 4/27/2023 in #support
undefined root_level_errors? true
The problem I have is that the error is not bubbling up to graphql and the web layer. instead I get a generic something went wrong in my tests when I expect the message to be an email being invalid message. How would you structure this in a way that the errors are sent back to the web layer when the changeset is invalid.
6 replies
AEAsh Elixir
Created by edwinofdawn on 4/17/2023 in #support
Ash Query filter function
follow up if try and pull_out the token then pin it in my query like below:
%{id: id, token: token} = user = insert(:user)


assert {:ok, _user}
|> Ash.Query.filter(token == ^token)
|> My_App.Ash.read_one()
%{id: id, token: token} = user = insert(:user)


assert {:ok, _user}
|> Ash.Query.filter(token == ^token)
|> My_App.Ash.read_one()
the error changes to (Postgrex.Error) ERROR 22021 (character_not_in_repertoire) invalid byte sequence for encoding "UTF8": 0x97
22 replies
AEAsh Elixir
Created by edwinofdawn on 4/13/2023 in #support
Casting Binary from Ash.Type.Binary to GraphQL type
I just fixed the issue, so absinthe does not have a binary type hence the problem. but in Elixir all binaries are just bitstrings so I can represent the token as binaries in my data layer and bit_strings(: string) in my resources and that bypasses my initial problem.
3 replies