We recently updated the API for Ecto Connections to accept arguments for sorting the connection by adding ordered_by and ordered_by_direction arguments. This works if you want to sort by the Connection's underlying table, but not if you want to sort by a joined table.
Thinking on this it became clear that we can simply look to see if the passed in Ecto query has an order_by clause from which we can then derive the sort field and direction. We don't need separate ordered_by and ordered_by_direction arguments. Just introspect the query.