joshsmith
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!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 1- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
venkatd
I would setup a table named something like
eventswith a polymorphic association to the identify, page, track tables. This table would have identify_id, page_id, track_id columns.See here for more details:
You’ll have a bit more complexity to deal with in maintaining this 4th
eventstable, but it should simplify your query logic and result in better performance.