You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the deprecation of BatchLoader.for in favor of BatchLoader::GraphQL.for in #62, we noticed there was a change in the API. We have a test that looks something like:
require'spec_helper'require'batch-loader'RSpec.describeGitlab::Utils::BatchLoaderdolet(:stubbed_loader)dodouble(# rubocop:disable RSpec/VerifiedDoubles'Loader',load_lazy_method: [],)endlet(:test_module)doModule.newdodefself.lazy_method(id)BatchLoader.for(id).batch(key: :my_batch_name)do |ids,loader|
stubbed_loader.load_lazy_method(ids)ids.each{ |id| loader.call(id,id)}endendendbeforedoBatchLoader::Executor.clear_currentallow(test_module).toreceive(:stubbed_loader).and_return(stubbed_loader)enddescribe'.clear_key'doit'clears batched items which match the specified batch key'dotest_module.lazy_method(1)described_class.clear_key(:my_batch_name)test_module.lazy_method(4).to_iendend
When we changed BatchLoader::for to use BatchLoader::GraphQL.for, this failed:
1) Gitlab::Utils::BatchLoader.clear_key clears batched items which match the specified batch key
Failure/Error: test_module.lazy_method(4).to_i
NoMethodError:
undefined method `to_i' for #<BatchLoader::GraphQL:0x00007f2dd33f6d50 @batch_loader=#<BatchLoader:0x545480>>
Did you mean? to_s
# ./spec/lib/gitlab/utils/batch_loader_spec.rb:x:in `block (3 levels) in <main>'
This happens because BatchLoader has a method_missing that auto-syncs:
Is the expectation now that we must call sync to evaluate a lazy method? Or should BatchLoader::GraphQL also implement its own method_missing like the following?
The text was updated successfully, but these errors were encountered:
stanhu
changed the title
BatchLoader::GraphQL.for
BatchLoader::GraphQL.for doesn't delegate missing methods as BatchLoader.for does
Feb 15, 2023
stanhu
changed the title
BatchLoader::GraphQL.for doesn't delegate missing methods as BatchLoader.for doesBatchLoader::GraphQL.for doesn't delegate missing methods as BatchLoader.for does
Feb 15, 2023
With the deprecation of
BatchLoader.for
in favor ofBatchLoader::GraphQL.for
in #62, we noticed there was a change in the API. We have a test that looks something like:When we changed
BatchLoader::for
to useBatchLoader::GraphQL.for
, this failed:This happens because
BatchLoader
has amethod_missing
that auto-syncs:batch-loader/lib/batch_loader.rb
Line 73 in e8148d8
Is the expectation now that we must call
sync
to evaluate a lazy method? Or shouldBatchLoader::GraphQL
also implement its ownmethod_missing
like the following?The text was updated successfully, but these errors were encountered: