`paginate_relationship_with :<resource> :relay` on manual relationship
I was trying to add relay pagination on a manual relationship, and I encountered problems.
First things first, the reason we've been using a manual relationship in the first place: the relationship is built dynamically when requested, by taking an attribute on the source and creating an ash expression out of it to filter the destination resource.
I started with adding the
I tried to hack something together, but without context nothing really worked. I then noticed that Ash's documentation for manual relationships (https://hexdocs.pm/ash/3.7.6/relationships.html#manual-relationships) actually suggests to try and avoid using them if possible, preferring instead the
More details on the solutions in the next message, and I can provide code if needed.
What I'd like to know: is there an easy way to achieve relay pagination on a manual relationship of this kind? Is it something that could be realistically automated by Ash, at least the AshPostgres callbacks, in the future? Is there maybe a better way to relate records dynamically than what we are doing that'd make things easier?
First things first, the reason we've been using a manual relationship in the first place: the relationship is built dynamically when requested, by taking an attribute on the source and creating an ash expression out of it to filter the destination resource.
I started with adding the
paginate_relationship_with :relay option in the graphql block like we did for all other relationships. For this, AshPostgres errors while using the application, asking to implement the ash_postgres_subquery/4 callback. I thought "no problem, i'll just check the docs and see what it needs", but the documentation on manual relationships for AshPostgres are lackluster: https://hexdocs.pm/ash_postgres/2.6.23/manual-relationships.html or https://hexdocs.pm/ash_postgres/2.6.23/AshPostgres.ManualRelationship.html, the best is a short description of the arguments (which I only really understood after diving into the Ecto docs for a while), but no real explanation about what either this or the other callback (ash_postgres_join/6) are used for or what they should return.I tried to hack something together, but without context nothing really worked. I then noticed that Ash's documentation for manual relationships (https://hexdocs.pm/ash/3.7.6/relationships.html#manual-relationships) actually suggests to try and avoid using them if possible, preferring instead the
no_attributes? true flag and filters. From this I came up with two possible solutions that I tried, both without success.More details on the solutions in the next message, and I can provide code if needed.
What I'd like to know: is there an easy way to achieve relay pagination on a manual relationship of this kind? Is it something that could be realistically automated by Ash, at least the AshPostgres callbacks, in the future? Is there maybe a better way to relate records dynamically than what we are doing that'd make things easier?

Ash