Is there a way to make an Attribute from a computed source?

Is there a way to make an Attribute from a computed source. I see that an attribute can be marked as generated not sure if that supports my use case or not.

An example would be you have an Order Resource and an Attribute called status that may be one of [:started, :paid, :fulfilled] And the status can be derived from the Attributes and Relationships of the Order. (I don’t want to track the status independent of the underlying data so that I can eliminate a whole host of state related bugs)

And a step further would be, if not an Attribute, how would you get that computed value into a GraphQL graph so that you can request it in a Query?

It sounds like you want to define a calculation called status – it will then be treated as if it were an attribute in terms being able to sort and filter on it, and it will be available in your GQL layer as well.

The caveat is that you must define your calculation as an expression. More information here: Calculations — ash v2.17.0 and the ash source code test suite is a good reference for these things.


Ah, so calculations are essentially computed attributes (when done with expressions) NICE!

I’ve not used the test suite up till now to learn, I’m going to take a look now.

Thank you very much!

1 Like