absinthe icon indicating copy to clipboard operation
absinthe copied to clipboard

[Feature suggestion] Pass context to the callback function of Absinthe.Resolution.Helpers.dataloader/2 options

Open jstlroot opened this issue 1 year ago • 2 comments

Hello everyone!

According to the docs, the callback function of Absinthe.Resolution.Helpers.dataloader/2 options

Can be used to e.g. compute fields on the return value of the loader.

This is a very useful way of transforming the data.

I think it this function would benefit from being passed the context, in case the data transformation needed to e.g. take session state into consideration.

Like this:

resolve dataloader(source, callback: fn (result, _parent, _args, context) ->
  {:ok, transform_data(result, context)}
end)

What do you think? Would a PR be welcome?

jstlroot avatar Sep 04 '22 17:09 jstlroot

I can see value in that for some use cases. Instead of the context I think it makes more sense to pass through the resolution struct just like normal resolver functions.

maartenvanvliet avatar Sep 07 '22 07:09 maartenvanvliet

Agreed. PR welcome.

benwilson512 avatar Sep 07 '22 21:09 benwilson512