undefined root_level_errors? true

Hello, small problem here. I am doing something like this
change fn changeset, _struct ->
changeset
|> Ash.Changeset.change_attribute(
:confirmation_token,
Utils.hash_token(token) |> Base.encode64()
)
|> case do
%Ash.Changeset{valid?: true} = changeset ->
Ash.Changeset.after_action(changeset, fn _changeset, customer ->
# enqueue job to send email here

})
{:ok, customer}
end)

changeset ->

{:error, changeset}
end
end
change fn changeset, _struct ->
changeset
|> Ash.Changeset.change_attribute(
:confirmation_token,
Utils.hash_token(token) |> Base.encode64()
)
|> case do
%Ash.Changeset{valid?: true} = changeset ->
Ash.Changeset.after_action(changeset, fn _changeset, customer ->
# enqueue job to send email here

})
{:ok, customer}
end)

changeset ->

{:error, changeset}
end
end
where I return {: error, changeset} I want the errors to bubble up and be returned by the graphql layer but root_level_errors? seems to be undefined. right now when you enter an invalid email the error returned is a generic something went wrong.
3 Replies
ZachDaniel
ZachDaniel3y ago
So, you should probably see something in the logs showing a stack trace. The basic problem here is that changes don’t return {:error, changeset} if you want to add an error use Ash.Changeset.add_error. In your case however it looks like you just only want to run the after action hook if the changeset is valid, but that is already how it works (we don’t do the action on invalid changes) So you should be able to just change the attribute and add the after action hook and return that
edwinofdawn
edwinofdawnOP3y ago
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.
ZachDaniel
ZachDaniel3y ago
You should be getting a log message explaining what the error was. Only errors that implement AshGraphql.Error are shown to the client for security reasons And for things like a pattern match error, we definitely don’t want to show that over the api

Did you find this page helpful?