Hi everyone, so working with graphql and absinthe, I tried to define scalar type :tags
witch is just list of string like: ["one", "two", "etc"]
and you can define it like field :tags , list_of(:string)
. But having then transform this list to just one string "one, two, etc"
it would be much better having a custom type! So after trying figured out how is defined List in absinth i ended up with this implementation: `
scalar :tags do
parse(fn input ->
with %Absinthe.Blueprint.Input.List{items: list} <- input do
tags =
Enum.reduce(list, "", fn %{normalized: %{value: value}}, acc -> acc <> value <> ", "
_, acc -> acc end)
{:ok, tags}
else
_ -> :error
end
end)
serialize(fn tags -> String.split(tags, ", ") end)
end
Witch isn’t the best but should give me at least "one, two, etc,"
But instead it gives me error:
“Argument "input" has invalid value $input.\nIn field "tags": Expected type "Tags", found ["one", "two", "etc"].”
if i change inside input field from :tags
to list_of(:string)
everything work but then i need to transform list inside my app domain, witch look not so clean. IO.inspecting input
get:
%Absinthe.Blueprint.Input.List{ errors: [], flags: %{}, items: [ %Absinthe.Blueprint.Input.Value{ data: nil, normalized: %Absinthe.Blueprint.Input.String{ errors: [], flags: %{}, schema_node: nil, source_location: nil, value: "one" }, raw: %Absinthe.Blueprint.Input.RawValue{ content: %Absinthe.Blueprint.Input.String{ errors: [], flags: %{}, schema_node: nil, source_location: nil, value: "one" } }, schema_node: nil }, ...}
So pattern matching and my function works, so how i can define list_of(:string)
== :tags
?
I read the book but still can’t figured out this… Please if some one know where to find answers or how to solve this issue, i would be very grateful