I’m trying to do cursor-based pagination across a union
of several different types
, each representing different Ecto
schemas like so:
union :event do
types([:identify, :page, :track])
resolve_type(fn
%Events.Identify{}, _ -> :identify
%Events.Page{}, _ -> :page
%Events.Track{}, _ -> :track
end)
end
connection(node_type: :event)
I’m trying to figure out a way to use Absinthe.Relay.Connection.from_query/4
so I can pass the pagination_args
into my query and honestly not sure how to even approach the problem.
Has anyone dealt with this before or can point me in the right direction?
The way I have this working right now is to simply execute three different SQL queries and then sort them in Elixir (results = identifies ++ pages ++ tracks
), then do Absinthe.Relay.Connection.from_list(results, pagination_args)
. This obviously means I have to do three very large queries in order to retrieve everything and is not ideal.
I attempted an approach using Ecto.Query.union/2
but really am not sure how this would work either.
Thanks in advance!