Reading calculations in Ash GraphQL

I have an Ash GraphQL schema, with calculations, simplified like so:

  attributes do
    attribute :start_at, :utc_datetime, public?: true
  end

  calculations do
    calculate :end_at,
              :utc_datetime,
              expr(datetime_add(start_at, duration, :millisecond)),
              public?: true
    end
  end

  graphql do
    queries do
      get :get_event, :read
    end
  end

The issue is that the calculated end_at attribute is not loaded when performing the query. The start_at attribute, of course, loads fine since it is an actual db column.

 query GetEvent($id: ID!) {
    getEvent(id: $id) {
      startAt
      endAt
     }
  }

=>         end_at = #Ash.NotLoaded<:calculation, field: :end_at>

How can I load or resolve a calculated Ash attribute with Ash Graphql? I wasn’t able to find anything about calculations in AshGraphql documentation, nor anything about graphql in Ash documentation

Nvm, now it’s resolved. Error was in not loading the resource in my test! :man_facepalming:

1 Like

That should “just work”. When you say that it is a NotLoaded where are you seeing that?

      event = Ash.load!(event, [:end_at], authorize?: false)