Why don't read actions filter by attributes?
Given a read action
There are no arguments for the action, so the following does not select on
email
.
I would assume any filterable attributes would be automatically applied as a filter. You could also have an accepts
option on the action to limit it certain filterable attributes.6 Replies
https://ash-hq.org/docs/guides/ash/latest/code-interface#using-the-code-interface
you can use a query for filtering
e.g.
Membership.read(authorize?: false, query: MemberShip |> Ash.Query.new() |> Ash.Query.filter(email: "[email protected]"))
Yep! And if you want to parse a filter from input (like query params), you'd use
Ash.Filter.parse_input!
That would prevent any funny business, only allowing basic attribute references to public attributes
(and not functions, for example)This is a question more about the philosophy and intent, and less asking "how to?".
Yes, we're currently using Ash.Query to filter. My question was "why?" because it seems like such a common use case. I think of using query as an escape hatch of sorts, because I really want my actions to define the intended usecases.
It's similar to how the GraphQL interface creates the input automatically from what's filterable. You don't have to define a read action with arguments for the filterable attributes.
It's similar to how the GraphQL interface creates the input automatically from what's filterable. You don't have to define a read action with arguments for the filterable attributes.
Yes, but it does that by using the same feature just laid out, the fact that any given read action can be given a narrowing query
And as such
ash_graphql
supports things like {or: [{...}, {...}]}
as opposed to just a key/value of attributes to filter on
Its not an escape hatch, its a design benefit of read actions
You can support explicit arguments with filters, like:
Or you could even write an extension that would add those arguments to all read actions (although I probably wouldn't)I see. It's more about being more robust than a simple key/value filter.
Thanks for helping me understand
👍 any time!