Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions spec/graphql/dataloader/async_dataloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,70 @@ class TraceAsyncSchema < AsyncSchema
check_snapshot(data, if_exec_next("example-next.json", "example.json"))
end
end

if testing_rails? && ISOLATION_LEVEL_FIBER
describe "with activerecord" do
class ActiveRecordAsyncSchema < GraphQL::Schema
class Author < GraphQL::Schema::Object
field :name, String
end

class Book < GraphQL::Schema::Object
field :title, String
field :author, Author
end

Author.field(:books, Book.connection_type)

class Query < GraphQL::Schema::Object
field :book, Book do
argument :title, String
end

def book(title:)
dataload_record(::Book, title, find_by: :title)
end

field :author, Author do
argument :name, String
end

def author(name:)
dataload_record(::Author, name, find_by: :name)
end
end

query(Query)
use GraphQL::Dataloader::AsyncDataloader
end

it "works with repeated queries" do
query_str = <<~GRAPHQL
{
author(name: "William Shakespeare") { name }
b1: book(title: "A Midsummer Night's Dream") { title author { name } }
b2: book(title: "Hamlet") { title author { name } }
}
GRAPHQL

results = []
10.times do
stdout, stderr = capture_io do
result = ActiveRecordAsyncSchema.execute(query_str)
results << [
result["data"]["author"]["name"],
result["data"]["b2"]["title"]
]
end
assert_equal "", stdout, "Nothing to stdout"
assert_equal "", stderr, "Nothing to stderr (like warnings from Task errors)"
rescue
:failed
end

assert_equal Array.new(10, ["William Shakespeare", "Hamlet"]), results
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def role
end

before {
skip("Only test when isolation_level = :fiber") unless ENV["ISOLATION_LEVEL_FIBER"]
skip("Only test when isolation_level = :fiber") unless ISOLATION_LEVEL_FIBER
}

it "cleans up database connections" do
Expand Down
5 changes: 4 additions & 1 deletion spec/integration/rails/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
require "sqlite3"
end

if ENV["ISOLATION_LEVEL_FIBER"]
ISOLATION_LEVEL_FIBER = if ENV["ISOLATION_LEVEL_FIBER"]
ActiveSupport::IsolatedExecutionState.isolation_level = :fiber
puts "ActiveSupport::IsolatedExecutionState: #{ActiveSupport::IsolatedExecutionState.isolation_level}"
true
else
false
end

require_relative "generators/base_generator_test"
Expand Down
Loading