Skip to content

Instantly share code, notes, and snippets.

@coderdan
Last active April 18, 2018 07:45
Show Gist options
  • Save coderdan/3a608753d6ee3852da42be7ca731c590 to your computer and use it in GitHub Desktop.
Save coderdan/3a608753d6ee3852da42be7ca731c590 to your computer and use it in GitHub Desktop.
Edge resolution with dataloader
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