absinthe-graphql/dataloader

Absinthe: Loading across sources

Closed this issue · 1 comments

I might have misunderstood what dataloader is trying to do, but I thought I could potentially use it to load data across sources (In this case two distinct databases).
An example could be:

  • IAM database:
    Contains BASIC user information

  • Core database:
    contains user preferences etc:

Example of what I would like to achieve in Absinthe:

object :user do
   field(:id, :string)
   field(:email, :string)
   field(:preferences, :user_preferences, resolve: dataloader(CoreDataSource))
end

If I try to do something similar to this I get the following error:
Valid association user_preferences not found on schema IAM.User.Schemas.User

It makes sense, I just hoped there was a way to use the ID provided to the dataloader to effectively load data from other sources. This case is trivial to solve, but the value of doing this with dataloader comes in handy when requesting a list of objects where you're loading subfields.

Hey @Aleksion this is definitely possible, but you'll want to roll some different helpers. The dataloader/1 helper is very tuned for loading database associations between tables in the same database, since that's a very common situation. This is just an absinthe helper though, nothing specific to Dataloader.

I'd start by using Dataloader more directly, see what patterns emerge, then build helpers around that.

To follow on with this though please use the forums, slack or, irc. The issue tracker isn't for general questions.