I have an Ecto schema like this:
schema "item" do
field :type, TypeEnum #some EctoEnum type
field :name, :string
field :data, :map
#other fields omitted
timestamps()
end
The :data field then utilizes a couple embedded schemas to display each specific “type”, similar to this:
embedded_schema do
field :specific_field, :string
#other fields omitted
end
I needed some form of hierarchy so that is how I developed it… I used this blog post as a reference: http://codeloveandboards.com/blog/2017/10/03/migrating-activerecord-sti-to-ecto/
My question is how do I define the Absinthe schema correctly?
I figured I could define an object for each specific type (and omit the “item” object definition):
@desc "Type 1"
object :type1 do
field :type, :string
field :name, :string
field :specific_field, :string
end
@desc "Type 2"
#...
But then how would I set up relationships that reference the “Item” object type?
Ie:
@desc "An Item Response"
object :item_response do
field :id, non_null(:id)
field :person, :person, resolve: dataloader(:people)
field :casted_vote, non_null(:id)
field :item, :item, resolve: dataloader(:items) #will need to add the item definition as well
end
and then define the item object and leave out the :map field? That might work I think but what if I then want to get the actual full definition of the specific type?
Or maybe the question is, how can I use a :map type with absinthe?
Overall I just want to make sure I am headed down the right path here.
Thanks… I am new to this so please bare with me.