Vovchikan

Vovchikan

How to declare :map in Absinthe.Schema.Notation.object/3

I’m trying to impelent GraphQL API in my project. I’m new in GraphQL, only read one article. I don’t understand how to convert :map field from Ecto.Schema to Types for GraphQL Schema. How i can declare field :locales in Absinthe.Schema.Notation.object/3?

My Ecto.Schema is

defmodule Msg
  @primary_key {:id, MsgidType, autogenerate: false}
  typed_schema "messages" do
    field(:text, :string)
    field(:domain, :string)
    field(:locales, :map, default: %{})

    timestamps()
  end
end

Example of %Msg{}

 %Msg{
    id: "test_update_msg_id",
    text: "Update test",
    domain: "test",
    locales: %{
      "en" => "Check update",
      "ru" => "Proverka update",
      "uz" => "Imtihon update"
    }
  }

My Absinthe.Schema.Notation

  @desc "Message for sms and ussd"
  object :message do
    field(:id, non_null(:string), description: "Hardcoded id")
    field(:text, non_null(:string), description: "Default text")
    field(:domain, :string)
    field(:locales, ???)
  end

First Post!

Vovchikan

Vovchikan

Solution - Scalar Recipes · absinthe-graphql/absinthe Wiki · GitHub

Usage

defmodule MyApp.Schema.Types do
  use Absinthe.Schema.Notation
  ...
  import_types(MyApp.Schema.Types.Custom.JSON)

  @desc "Message for sms and ussd"
  object :message do
    field(:id, non_null(:string), description: "Hardcoded id")
    field(:text, non_null(:string), description: "Default text")
    field(:domain, :string)
    field(:locales, :json)
  end
end

easy :sunglasses:

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
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
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
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
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
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
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

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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

We're in Beta

About us Mission Statement