class GraphQL::Execution::Finalize
Public Class Methods
Source
# File lib/graphql/execution/finalize.rb, line 6 def initialize(query, data, runner) @query = query @data = data @static_type_at = runner.static_type_at @runner = runner @current_exec_path = query.path.dup @current_result_path = query.path.dup @finalizers = runner.finalizers ? runner.finalizers[query] : {}.compare_by_identity @finalizers_count = 0 @finalizers.each do |key, values| values.each do |key2, values2| case values2 when Array @finalizers_count += values2.size else @finalizers_count += 1 end end end query.context.errors.each do |err| err_path = err.path - @current_exec_path key = err_path.pop targets = [data] while (part = err_path.shift) targets.map! { |t| t[part] } targets.flatten! end targets.each_with_index do |target, idx| if target.is_a?(Hash) value_at_key = target[key] if value_at_key.equal?(err) tf = @finalizers[target] ||= {}.compare_by_identity tf[key] = err @finalizers_count += 1 elsif value_at_key.is_a?(Array) pending_arrays = [value_at_key] while (array = pending_arrays.pop) array.each_with_index do |el, idx| if el.equal?(err) array_tf = @finalizers[array] ||= {}.compare_by_identity array_tf[idx] = err @finalizers_count += 1 elsif el.is_a?(Array) pending_arrays << el end end end end end end end end
Public Instance Methods
Source
# File lib/graphql/execution/finalize.rb, line 61 def run if (selected_operation = @query.selected_operation) && @data if @data.is_a?(Hash) check_object_result(@data, @query.root_type, selected_operation.selections) elsif @data.is_a?(Array) check_list_result(@data, @query.root_type, selected_operation.selections) elsif @data.is_a?(Finalizer) dummy_data = {} dummy_key = "__dummy" @data.path = @query.path @data.finalize_graphql_result(@query, dummy_data, dummy_key) dummy_data[dummy_key] else raise ArgumentError, "Unexpected @data: #{@data.inspect}" end else @data end end