Hi all! My GraphQL education is still in a fairly nascent stage and I’ve run into an issue that seems like it should be easy to solve, yet I can’t figure out a solution. This makes me think I have a flawed mental model and/or a suboptimal implementation.
Here’s a brief rundown of the relevant pieces of my application, with some of my possibly incorrect understandings made explicit:
- A PostgreSQL table,
datapoints
, that contains apayload
column (among others) which is set to themap
type in my Ecto migration. As far as I understand, this configuration means that Ecto will create that column asjsonb
and encode/decode as appropriate. - The
payload
map should contain a:value
key which is one of data shapes: a boolean value, a string, or a list of strings. I am enforcing this rule via various strategies which I can’t imagine have any bearing on my GraphQL conundrum. - An Elixir module that defines an Ecto schema for the
datapoints
table withfield(:payload, :map)
. - An Elixir module that defines an Absinthe schema. It defines an object,
:datapoint
, as part of the root query object.
My issue comes into play when I try to define the :payload
field on the :datapoint
object in my schema, i.e.:
object :datapoint do
field(:id, :id)
field(:name, :string)
field(:type, :string)
field(:payload, # ??? #)
end
How should I tell Absinthe that this field should be one of type :boolean
, :string
, or list_of(:string)
? I’ve gone down quite the rabbit hole of unions, interfaces, and custom scalars, but nothing seems quite right… I can share more code upon request, but I don’t want to start this off with a giant wall of text, and I’m hoping I’m missing something simple.
Any help is very greatly appreciated!