diff --git a/lib/graphql/batch/loader.rb b/lib/graphql/batch/loader.rb index dc294cd..be039bc 100644 --- a/lib/graphql/batch/loader.rb +++ b/lib/graphql/batch/loader.rb @@ -58,6 +58,7 @@ def resolve #:nodoc: # For Promise#sync def wait #:nodoc: if executor + executor.loaders.delete(loader_key) executor.resolve(self) else resolve diff --git a/test/graphql_test.rb b/test/graphql_test.rb index 2d4470d..20b6e6c 100644 --- a/test/graphql_test.rb +++ b/test/graphql_test.rb @@ -342,6 +342,6 @@ def test_mutation_batch_subselection_execution } } assert_equal expected, result - assert_equal ["Product/1,2", "Product/3"], queries + assert_equal ["Product/1,2", "Product/2,3"], queries end end diff --git a/test/support/loaders.rb b/test/support/loaders.rb index c237f4d..c947a04 100644 --- a/test/support/loaders.rb +++ b/test/support/loaders.rb @@ -26,16 +26,12 @@ def perform(owners) end class CounterLoader < GraphQL::Batch::Loader - def initialize(hash) - @hash = hash - end - - def load(key=Object.new) - super(key) + def cache_key(counter_array) + counter_array.object_id end def perform(keys) - keys.each { |key| fulfill(key, @hash[:counter][0]) } + keys.each { |counter_array| fulfill(counter_array, counter_array[0]) } end end diff --git a/test/support/schema.rb b/test/support/schema.rb index 1abf802..437d068 100644 --- a/test/support/schema.rb +++ b/test/support/schema.rb @@ -128,7 +128,7 @@ end field :load_value, !types.Int do - resolve ->(_, _, ctx) { CounterLoader.for(ctx).load } + resolve ->(_, _, ctx) { CounterLoader.load(ctx[:counter]) } end end @@ -136,11 +136,13 @@ name "Mutation" field :increment_counter, !CounterType do - resolve ->(_, _, ctx) { ctx[:counter][0] += 1; CounterLoader.for(ctx).load } + resolve ->(_, _, ctx) { ctx[:counter][0] += 1; CounterLoader.load(ctx[:counter]) } end field :counter_loader, !types.Int do - resolve ->(_, _, ctx) { CounterLoader.for(ctx).load } + resolve ->(_, _, ctx) { + CounterLoader.load(ctx[:counter]) + } end field :no_op, !QueryType do