ash-project / ash-project/ash_json_api

Add action metadata to the meta field

Open
#236 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Elixir
Stars
94
Forks
80
Avg merge
5h 5m
Merged PRs (30d)
4

Description

### 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](https://elixirforum.com/t/use-metadata-to-return-additional-information/66398) 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 :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.