absinthe-graphql/absinthe_relay

Integration with Dataloader

dolfinus opened this issue · 6 comments

Hey @dolfinus, thanks for these helpers. Until recently, this kind of integration wasn't possible because there wasn't an easy way for Ecto (and by extension dataloader) do unique limits for each parent. However now that Dataloader does support limits, this sort of thing can re-evaluated again.

hi @benwilson512 circling back from our conversation on slack. I'm trying to think about how we can do this in a good way. Here's my idea:

import Absinthe.Relay.Resolution.Helpers, only: [dataloader: 1]

then for the type:

object :parent do
    field :id, :integer
    field :child, resolve: dataloader(Module, order: [desc: :inserted_at])
end

I think the most difficult part is trying to get the sorting correct, so we may consider the above OR maybe rely on the dataloader source to specify the sort?

I'm using both Absinthe Relay and Dataloader in a project as well, but haven't used Dataloader for Relay connection fields yet. In my case, I'd require the sorting to be handled by the query function of the Dataloader source, without the need to specify the order as in the code example above (potentially taking the sort field/order from query arguments).

IMHO, sorting should be handled by a query function, because some of users could want to pass ordering as an argument. There should be no hard coded values.

Agreed about sorting. @HangingClowns I guess I'm a bit confused by your example snippet. That code works today. The "integration with dataloader" part of this issue has to do with combining connection fields with dataloader. Using dataloader on node entity subfields works just fine already.

hi @benwilson512 from what I understand, paginating the data using relay doesnt' work? hence i was thinking we can do this: import Absinthe.Relay.Resolution.Helpers, only: [dataloader: 1], notice how it's importing from Absinthe.Relay INSTEAD of just Absinthe. Maybe the name is too ambiguous, though?