Skip to content

Commit

Permalink
Merge pull request #4506 from amomchilov/replace-each-with-include
Browse files Browse the repository at this point in the history
Speed up lookup of possible types for Fragments
  • Loading branch information
rmosolgo committed Jun 9, 2023
2 parents 7efd8e6 + e9602f8 commit 250a724
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/graphql/execution/interpreter/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,8 @@ def gather_selections(owner_object, owner_type, selections, selections_to_run =
if node.type
type_defn = schema.get_type(node.type.name, context)

# Faster than .map{}.include?()
query.warden.possible_types(type_defn).each do |t|
if t == owner_type
gather_selections(owner_object, owner_type, node.selections, selections_to_run, next_selections)
break
end
if query.warden.possible_types(type_defn).include?(owner_type)
gather_selections(owner_object, owner_type, node.selections, selections_to_run, next_selections)
end
else
# it's an untyped fragment, definitely continue
Expand All @@ -357,12 +353,8 @@ def gather_selections(owner_object, owner_type, selections, selections_to_run =
when GraphQL::Language::Nodes::FragmentSpread
fragment_def = query.fragments[node.name]
type_defn = query.get_type(fragment_def.type.name)
possible_types = query.warden.possible_types(type_defn)
possible_types.each do |t|
if t == owner_type
gather_selections(owner_object, owner_type, fragment_def.selections, selections_to_run, next_selections)
break
end
if query.warden.possible_types(type_defn).include?(owner_type)
gather_selections(owner_object, owner_type, fragment_def.selections, selections_to_run, next_selections)
end
else
raise "Invariant: unexpected selection class: #{node.class}"
Expand Down

0 comments on commit 250a724

Please sign in to comment.