ash_json_api icon indicating copy to clipboard operation
ash_json_api copied to clipboard

Add action metadata to the meta field

Open m9tdev opened this issue 1 year ago • 0 comments

Feature request

I tried to return an additional field for my resource by adding a metadata option to my create action like this:

      metadata :additional_data, :string, allow_nil?: false

And setting this value in a change using:

        result = Ash.Resource.put_metadata(result, :signed_url, url)

But unfortunately this did not result in filling this field in the meta field of the returned resource data.

Would be convenient for certain use cases to be able to pass additional data this way. I'm for example generating a signed url with write permissions for a storage bucket on creation of a resource. I only want to return this after creation. On reads I may want a read-only url.

@zachdaniel suggested to use the metadata option on the route instead of the action instead, or use a calculated field. A combination of both options would do the job for me (action metadata for write-enabled url, calculated field for read-only url), but if I add a graphql api as well I've got to declare metadata for create there again, which this feature would prevent.

Also, for batch create actions, I think it makes sense to have this metadata per resource instead of on the route.

Curious for options on this :)

m9tdev avatar Sep 30 '24 08:09 m9tdev