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
2 changes: 1 addition & 1 deletion lib/graphql/pagination/relation_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def build_limited_nodes
end

def async_dataloader?
@context&.[](:dataloader).is_a?(GraphQL::Dataloader::AsyncDataloader)
@context&.dataloader.is_a?(GraphQL::Dataloader::AsyncDataloader)
end

# Load nodes after applying first/last/before/after,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ def total_count
require "async"

describe "when Fibers share a connection" do
let(:async_context) {
async_schema = Class.new(schema) { use GraphQL::Dataloader::AsyncDataloader }
GraphQL::Query.new(async_schema, "{ __typename }").context
}

class SlowCountingRelationConnection < GraphQL::Pagination::ActiveRecordRelationConnection
attr_reader :count_calls

Expand All @@ -271,7 +276,7 @@ def relation_count(relation)
end

it "loads the page only once when several Fibers resolve it" do
connection = GraphQL::Pagination::ActiveRecordRelationConnection.new(Food.all, first: 2, max_page_size: 10, context: { dataloader: GraphQL::Dataloader::AsyncDataloader.new })
connection = GraphQL::Pagination::ActiveRecordRelationConnection.new(Food.all, first: 2, max_page_size: 10, context: async_context)
results = []

log = with_active_record_log do
Expand All @@ -285,7 +290,7 @@ def relation_count(relation)
end

it "counts the relation only once when page fields resolve in separate Fibers" do
connection = SlowCountingRelationConnection.new(Food.all, last: 2, max_page_size: 10, context: { dataloader: GraphQL::Dataloader::AsyncDataloader.new })
connection = SlowCountingRelationConnection.new(Food.all, last: 2, max_page_size: 10, context: async_context)
nodes = nil
has_previous_page = nil

Expand Down
Loading