Ecto.Multi Usage
I saw only one post about how to use
Ecto.Multi
it directed me to Ash.Flow
what I didn't find an example usage.
For context I have a record I want fetch using token provided its valid, after I get the record successfully I want to update a field on it and finally on success issue a JWT
or on error just return the error. How will this look like in the update function ?. Is this a candidate for to consider using ManualActions
?18 Replies
It depends 😄 There are a few options. Are you looking to hook this up to graphql/json_api?
Yes into graphql
I think you can likely get a way with some regular-old-actions
That should give you something like this:
Thanks let me try this out 👍
elixir
I get two errors from this
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.You need to
require Ash.Query
at the top of your resourcethanks that got it the first part working .
lastly, what is the acceptance criteria for the fetched resource in
read_action
. for update. I tried
elixir
which was a bad idea .
elixir
but the above should have worked but I get The field "email" is not unique in type "UpdateUserInput
I have identities setup
elixir
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 ?By default, update actions accept all public writable attributes
Adding an argument for
:email
is unnecessary
You’d say accept [:email]
I’ll fix the error though in future versions.okay and how is the
token
param passed from the update to read_action read_action
because that is failing
elixir does the read action have an argument?
you'd need to have the
token
argument on the read actionI'm picking this up from where @edwinofdawn left. I added an
:authenticate_by_token
action and GQL query, because that seemed more appropriate:
The :authenticate_by_token
uses :get_by_token
to get the record (Customer). However, :get_by_token
fails because of a missing :confirmation_token
, even though I am passing that.
When I call :get_by_token
directly (there's a GQL query for that too), it works fine.🤔
can I see how you're calling it?
Like this:
Here's the
get_by_token
action:
And here's get_by_token
being called:
I think I found out what's causing the issue: confirmation_token
is an attribute of the resource. If I switch to different name, like :token
that isn't an attribute, I don't see errors
Okay, yeah, that's the issue. It looks like the underlying Ash logic isn't passing :confirmation_token
to the read_action
when that field is an attribute of the resource. It only works when the field isn't the same as an attribute of the resource.Very interesting
Trying to figure out how that would be happening
have it reproduced
question
nvm
@moxley fixed in
0.25.3
Sorry it took so long to figure out 😢Yay!!! Thank you @Zach Daniel !
🎉 thank you @Zach Daniel
tested it and it works
Hey @Zach Daniel, after integrating
0.25.3
and then merging some newer changes into our main
branch, we're seeing this new error:
fixed in
0.25.4
Got it 👍