Last active
April 18, 2018 07:45
-
-
Save coderdan/3a608753d6ee3852da42be7ca731c590 to your computer and use it in GitHub Desktop.
Edge resolution with dataloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Absinthe.Resolution.Helpers | |
connection field :contracts, node_type: :contract do | |
resolve fn %{id: project_id}, args, %{context: %{current_user: current_user}, dataloader: loader} -> | |
loader | |
|> Dataloader.load_many(Engagement, :contract_ids_for_project_id, project_id) | |
|> on_load(fn loader -> | |
{ | |
:ok, | |
Connection.from_list( | |
Dataloader.get_many(loader, Engagement, :contract_ids_for_project_id, project_id), | |
Map.put(args, :project_contract, true) | |
) | |
} | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment