Skip to content

Commit bc971ce

Browse files
committed
Use a plain hash even when the selection set has directives
1 parent a107673 commit bc971ce

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/graphql/execution/interpreter/runtime.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ def values
182182
end
183183
end
184184

185-
class GraphQLSelectionSet < Hash
186-
attr_accessor :graphql_directives
187-
end
188-
189185
# @return [GraphQL::Query]
190186
attr_reader :query
191187

@@ -280,7 +276,10 @@ def run_eager
280276
st = get_current_runtime_state
281277
st.current_object = query.root_value
282278
st.current_result = selection_response
283-
directives = selections.respond_to?(:graphql_directives) ? selections.graphql_directives : nil
279+
# This is a less-frequent case; use a fast check since it's often not there.
280+
if (directives = selections[:graphql_directives])
281+
selections.delete(:graphql_directives)
282+
end
284283
call_method_on_directives(:resolve, object_proxy, directives) do
285284
evaluate_selections(
286285
object_proxy,
@@ -326,8 +325,8 @@ def gather_selections(owner_object, owner_type, selections, selections_to_run =
326325
else
327326
# This is an InlineFragment or a FragmentSpread
328327
if @runtime_directive_names.any? && node.directives.any? { |d| @runtime_directive_names.include?(d.name) }
329-
next_selections = GraphQLSelectionSet.new
330-
next_selections.graphql_directives = node.directives
328+
next_selections = {}
329+
next_selections[:graphql_directives] = node.directives
331330
if selections_to_run
332331
selections_to_run << next_selections
333332
else
@@ -810,7 +809,10 @@ def continue_field(value, owner_type, field, current_type, ast_node, next_select
810809
st.current_result_name = nil
811810
st.current_result = this_result
812811

813-
directives = selections.respond_to?(:graphql_directives) ? selections.graphql_directives : nil
812+
# This is a less-frequent case; use a fast check since it's often not there.
813+
if (directives = selections[:graphql_directives])
814+
selections.delete(:graphql_directives)
815+
end
814816
call_method_on_directives(:resolve, continue_value, directives) do
815817
evaluate_selections(
816818
continue_value,

0 commit comments

Comments
 (0)