Closed sb8244 closed 6 months ago
In Ash, nil
is a valid actor. Currently, require_actor?
's job is to require that all places pass the actor
option, not to ensure that it is not nil
. This is to prevent typos, basically. AshGraphql always sets the actor option, even if one was not provided to it (but it may be nil
). A good argument could be made for that being not the best behavior, but it is currently the designed behavior.
Typically this would be implemented somewhere in the authentication flow, where if authentication fails or no authentication information is present you'd reject the user's request.
It is too late to change the semantics of require_actor?
, unfortunately, but we could potentially add something like validate_actor/1
that gives you the actor and a chance to provide an arbitrary error message about why that actor is invalid.
Then you could accomplish what you want with something like this:
require_actor? true
validate_actor fn nil ->
{:error, "...."}
%User{} = user ->
{:ok, user}
end
Thanks Zach. That's helpful to understand. You're right that my auth flow handles this, it was more of an interim state that felt off. But now I understand so all good.
I didn't have the AshGraphql plug in my pipeline at the time. Not sure if that changes anything.
Shouldn't affect things. I'll close this for now, but if it looks like validate_actor
or some similar set of behavior will help in other cases as well then we'll add it to the roadmap :)
Describe the bug
I have
require_actor? true
in my Ash.Domain. My functions generally require the user / tenant it's operating on, so I see this being the norm.I am doing TDD to implement the GQL layer, and haven't yet set the user/tenant in the context.
Ash is attempting to process the request and is raising an error due to null field value:
To Reproduce
Expected behavior
I expect a GQL error is returned (maybe generic), and a logged error from the domain, like function calls:
Runtime
Ash 3.0.0 AshGraphql 1.0.0
Additional context Very real chance I'm doing something wrong here and there's a root cause that's my fault.