From e9602f89542eab5465577c0ecaebbb2028f6c371 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Thu, 25 May 2023 09:07:21 -0400 Subject: [PATCH] Replace `each`+`break` with `include?` --- lib/graphql/execution/interpreter/runtime.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/graphql/execution/interpreter/runtime.rb b/lib/graphql/execution/interpreter/runtime.rb index 7ec6cf85e3..19af3e1412 100644 --- a/lib/graphql/execution/interpreter/runtime.rb +++ b/lib/graphql/execution/interpreter/runtime.rb @@ -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 @@ -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}"