Skip to content

Commit

Permalink
Merge pull request #147 from absinthe-graphql/bugfix-async-behavior
Browse files Browse the repository at this point in the history
Bugfix async behavior
  • Loading branch information
benwilson512 authored Oct 31, 2022
2 parents 5c47f24 + 245225e commit 828c9e5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.13.0-rc.1-otp-24 1.12.0-otp-24
elixir 1.14.1-otp-24 1.12.0-otp-24
erlang 24.1.7 24.1.5 24.1.2 24.1.1 24.0
3 changes: 2 additions & 1 deletion lib/dataloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ defmodule Dataloader do
sync_sources,
fun,
[
timeout: dataloader_timeout(dataloader)
timeout: dataloader_timeout(dataloader),
async?: false
]
],
async?: false
Expand Down
25 changes: 25 additions & 0 deletions test/dataloader/ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,29 @@ defmodule Dataloader.EctoTest do
assert Enum.map(users, &Dataloader.get(loader, Test, {User, id: &1.id}, &1.id)) ==
users
end

test "run inside transaction" do
user = %User{username: "Ben Wilson"} |> Repo.insert!()

source = Dataloader.Ecto.new(Repo, async: false)

loader =
Dataloader.new(async: false)
|> Dataloader.add_source(Test, source)

Dataloader.load(loader, Test, User, user.id)

Repo.transaction(fn ->
loader =
loader
|> Dataloader.load(Test, User, user.id)
|> Dataloader.run()

loaded =
loader
|> Dataloader.get(Test, User, user.id)

assert ^user = loaded
end)
end
end

0 comments on commit 828c9e5

Please sign in to comment.