Skip to content
Merged
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
6 changes: 3 additions & 3 deletions cop/development/context_is_passed_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class ContextIsPassedCop < RuboCop::Cop::Base

def on_send(node)
if (
method_doesnt_receive_second_context_argument?(node) ||
method_doesnt_receive_first_context_argument?(node) ||
is_enum_values_call_without_arguments?(node)
method_doesnt_receive_second_context_argument?(node) ||
method_doesnt_receive_first_context_argument?(node) ||
is_enum_values_call_without_arguments?(node)
) && !likely_query_specific_receiver?(node.to_a[0])
add_offense(node)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/dataloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def self.with_dataloading(&block)
end

def initialize(nonblocking: self.class.default_nonblocking, fiber_limit: self.class.default_fiber_limit)
@source_cache = Hash.new { |h, k| h[k] = {} }
@source_cache = Hash.new { |h, k| h[k] = {} }.compare_by_identity
@pending_jobs = []
if !nonblocking.nil?
@nonblocking = nonblocking
Expand Down
28 changes: 18 additions & 10 deletions lib/graphql/dataloader/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def load_all(values)
sync(pending_keys)
end

result_keys.map { |k| result_for(k) }
result_keys.map! { |k| result_for(k) }
result_keys
end

# Subclasses must implement this method to return a value for each of `keys`
Expand Down Expand Up @@ -138,22 +139,25 @@ def merge(new_results)
# @api private
# @return [void]
def run_pending_keys
if !@fetching.empty?
@fetching.each_key { |k| @pending.delete(k) }
end
@fetching.each_key { |k| @pending.delete(k) }
return if @pending.empty?
fetch_h = @pending
@pending = {}
@fetching.merge!(fetch_h)
@pending = {}
results = fetch(fetch_h.values)
fetch_h.each_with_index do |(key, _value), idx|
idx = 0

fetch_h.each_key do |key|
@results[key] = results[idx]
@fetching.delete(key)
idx += 1
end
nil
rescue StandardError => error
fetch_h.each_key { |key| @results[key] = error }
ensure
fetch_h && fetch_h.each_key { |k| @fetching.delete(k) }
fetch_h.each_key { |key|
@results[key] = error
@fetching.delete(key)
}
end

# These arguments are given to `dataloader.with(source_class, ...)`. The object
Expand All @@ -171,7 +175,11 @@ def run_pending_keys
# @param batch_kwargs [Hash]
# @return [Object]
def self.batch_key_for(*batch_args, **batch_kwargs)
[*batch_args, **batch_kwargs]
if batch_kwargs.any? # rubocop:disable Development/NoneWithoutBlockCop
[*batch_args, **batch_kwargs]
else
batch_args
end
end

# Clear any already-loaded objects for this source
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/execution/finalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def check_object_result(result_h, parent_type, ast_selections)
when Language::Nodes::InlineFragment
static_type_at_result = @static_type_at[result_h]
if static_type_at_result && (
(t = ast_selection.type).nil? ||
@runner.type_condition_applies?(@query.context, static_type_at_result, t.name)
(t = ast_selection.type).nil? ||
@runner.type_condition_applies?(@query.context, static_type_at_result, t.name)
)
result_h = check_object_result(result_h, parent_type, ast_selection.selections)
return nil if result_h.nil?
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/dataloader/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def fetch(keys)

# The value of this changed in Ruby 3.3.3, see https://bugs.ruby-lang.org/issues/20180
# In previous versions, it was `[{}]`, but now it's `[]`
empty_execution_next_key = [*[], **{}]
empty_execution_next_key = [*[]]
source_inst = source_cache_for_source[empty_execution_next_key]
assert_instance_of FailsToLoadSource, source_inst, "The cache includes a pending source (#{source_cache_for_source.inspect})"
assert source_inst.pending?
Expand Down
Loading