Using Ash.Query.add_error()

I tried this as well: Error Handling — ash v3.29.3, but Ash.Error.Changes.Required.new/1 is not defined.

So then I used struct literal syntax, and it resulted in the error appearing in the AshGraph response:

prepare fn query, _context do
  error =
    %Ash.Error.Changes.Required{
      field: :foo,
      type: :attribute
    }

  Ash.Query.add_error(query, error)
end

...

resp_body #=> %{
  "data" => nil,
  "errors" => [
    %{
      "code" => "required",
      "fields" => ["foo"],
      "locations" => [%{"column" => 3, "line" => 2}],
      "message" => "is required",
      "path" => ["listMemberSelfSubscriptions"],
      "short_message" => "is required",
      "vars" => []
    }
  ]
}

I think if I play around with one of the other Ash error modules, I’ll find what I need to make this work correctly.