m9t

m9t

Use metadata to return additional information

Hi there!

I’m using ash_json_api and I’m trying to add metadata to the response of a create action, but it doesn’t seem to be included in the meta field. I’ve got the following relevant pieces in my resource:

  json_api do
    type "asset"

    routes do
      base "/assets"
      get :read
      index :read
      post :create
    end
  end

  actions do
    defaults [:read]

    create :create do
      # Set the current user as the owner of the asset
      change relate_actor(:user)
      # Create signed url for the asset
      metadata :signed_url, :string, allow_nil?: false
      change Swoop.Media.Changes.GeneratePresignedUrl
    end
  end

In GeneratePresignedUrl I’m returning this in a after_action function:

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

But unfortunately after doing a POST to the endpoint with curl, I’m getting empty meta fields:

{"data":{"attributes":{},"id":"11700f40-c37b-4776-b3b0-7d1207cbb6d0","links":{},"meta":{},"relationships":{},"type":"asset"},"jsonapi":{"version":"1.0"},"links":{"self":"http://localhost:4000/api/json/assets"},"meta":{}}

What am I missing?

Thanks in advance!

Most Liked

zachdaniel

zachdaniel

Creator of Ash

The way you are attempting to use it is actually its intended use case :slight_smile: However, it just hasn’t been hooked up to ash_json_api yet. AshGraphql has a way to expose metadata in exactly that same way. It requires some adjustments to our open api schema generation logic, because we need to do one of three things:

  1. allow you to configure a special type name for the results of the action, i.e asset-with-url
  2. we have to add that meta to all types
  3. we have to keep meta as untyped “object”

Its a solvable problem, just hasn’t been implemented yet :slight_smile:

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

We're in Beta

About us Mission Statement