Class: GraphQL::Analysis::ReducerState

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/analysis/reducer_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reducer, query) ⇒ ReducerState


7
8
9
10
11
# File 'lib/graphql/analysis/reducer_state.rb', line 7

def initialize(reducer, query)
  @reducer = reducer
  @memo = initialize_reducer(reducer, query)
  @errors = []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors


5
6
7
# File 'lib/graphql/analysis/reducer_state.rb', line 5

def errors
  @errors
end

#memoObject

Returns the value of attribute memo


5
6
7
# File 'lib/graphql/analysis/reducer_state.rb', line 5

def memo
  @memo
end

#reducerObject (readonly)

Returns the value of attribute reducer


4
5
6
# File 'lib/graphql/analysis/reducer_state.rb', line 4

def reducer
  @reducer
end

Instance Method Details

#call(visit_type, irep_node) ⇒ Object


13
14
15
16
17
# File 'lib/graphql/analysis/reducer_state.rb', line 13

def call(visit_type, irep_node)
  @memo = @reducer.call(@memo, visit_type, irep_node)
rescue AnalysisError => err
  @errors << err
end

#finalize_reducerAny

Respond with any errors, if found. Otherwise, if the reducer accepts final_value, send it the last memo value. Otherwise, use the last value from the traversal.


23
24
25
26
27
28
29
30
31
# File 'lib/graphql/analysis/reducer_state.rb', line 23

def finalize_reducer
  if @errors.any?
    @errors
  elsif reducer.respond_to?(:final_value)
    reducer.final_value(@memo)
  else
    @memo
  end
end