zar1978

zar1978

Dynamo ExAws read table with complex field - inclassparameter is NULL

Good morning. I have the following problem. I should read the contents of the following Dynamo table through the ExAws library:

{
  "actorengine": "HOT-TCM",
  "actortype": "BUSINESS_ACTOR",
  "actorversionclass": 1,
  "classified": "UNCLASSIFIED",
  "creatorclass": "ivan.casiraghi@gmail.com",
  "datadeploy": "2019-02-11 16:55:13",
  "encryption": "NOENCRYPTION",
  "id": "1234567890",
  "inclassparameters": [
    {
      "id": "1222",
      "keyspace": "eyspace"
    }
  ],
  "keyspace": "it0125maxwellgroup",
  "linknamemodel": "https://s3-eu-west.amazonaws.com/maxwell-abe-deploy/actor/it0125maxwellgroup/prova01_1.0.json",
  "name": "prova01",
  "security": "PUBLIC",
  "statedeploy": "ACTIVE"
}

This is my module:

defmodule ElixirCrudWeb.Resolver.Resolver do
  @moduledoc false


  alias ExAws.Dynamo


  defmodule InClassParameter do
    @derive [ExAws.Dynamo.Encodable]
    defstruct [:keyspace, :id]
  end



  defmodule ActorClassBusiness do
        @derive [ExAws.Dynamo.Encodable]
        defstruct [:id, :actorversionclass, :actorengine, :actortype, :classified, :creatorclass, :datadeploy,
          :encryption, :keyspace, :linknamemodel, :name,  :security, :statedeploy,
          inClassParameter: [%InClassParameter{},]
        ]
      end
 def select_one(_parent, %{id: id}, _resolution)  do
    item = Dynamo.get_item("actorClassBusiness", %{id: id}) |> ExAws.request!
    wrap_result(id, item)
  end


  defp wrap_result(key, map) when map == %{} do
    {:error, "actorClassBusiness ID #{key} not found"}
  end

  defp wrap_result(_, map) do
    IO.puts("Ecco i dati  #{inspect(map)}")
    item = Dynamo.decode_item(map, as: ActorClassBusiness)
    {:ok, item}
  end

end

If I run the query from GraphiQl:

query read{
  selectOne(id: "14c41f17-38b8-41db-af8b-111f6165932a"){
    id
    actorengine
  actortype
  actorversionclass
  classified
  creatorclass
  datadeploy
  encryption
    statedeploy
    inclassparameters{
      id
      keyspace
    }
  }
}

I get the following:

{
  "data": {
    "selectOne": {
      "actorengine": "HOT-TCM",
      "actortype": "BUSINESS_ACTOR",
      "actorversionclass": 1,
      "classified": "UNCLASSIFIED",
      "creatorclass": "ascanio.casiraghi@gmail.com",
      "datadeploy": "2019-03-18 01:48:59",
      "encryption": "NOENCRYPTION",
      "id": "14c41f17-38b8-41db-af8b-111f6165932a",
      "inclassparameters": null,
      "statedeploy": "ACTIVE"
    }
  }
}

inclassparameter is NULL. Where am I wrong?
Thank you

First Post!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

If you’re also using GraphQL can you show the definitions?

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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 record...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
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 42633 214
New

We're in Beta

About us Mission Statement