Accept subset of Ash.Type.Enum in action
I have an
Ash.Type.Enum
defined as
And the User
resource is using it with
In my create action I'd like to accept a role argument, but only :farmer
or :farmhand
should be allowed, and ideally I'd like to keep all the benefits of using Ash.Type.Enum
like automatic casting. What would be the idiomatic way of accomplishing this?Solution:Jump to solution
for your first question you can use a validation https://hexdocs.pm/ash/Ash.Resource.Validation.Builtins.html#attribute_in/2
7 Replies
Hang on, this is probably the wrong way forward actually. Since this is using ash auth, I'd probably have to create a
Profile
resource which belongs to a User
? As far as I can tell, there is no way to add arbitrary attributes to the generated User resource to be accepted in the signup flow?You can, but you'd need to build your own UI
or you can just let the user update the other fields after signup
and you can just add attributes to the resoruce the add attributes to the accept list, argument the real work is done in the changes/preparations
Solution
for your first question you can use a validation https://hexdocs.pm/ash/Ash.Resource.Validation.Builtins.html#attribute_in/2
I'm planning on building my own UI in any case, so that's no blocker. I'd also expose it via graphql, but I guess that shouldn't be an issue either?
yes, you can expose the action via the graphl
Don't know why I thought it would be harder than any other action, but this makes sense. Thanks a lot!