Class: GraphQL::Query::SerialExecution::SelectionResolution

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/query/serial_execution/selection_resolution.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, type, selections, query, execution_strategy) ⇒ SelectionResolution

Returns a new instance of SelectionResolution.



7
8
9
10
11
12
13
# File 'lib/graphql/query/serial_execution/selection_resolution.rb', line 7

def initialize(target, type, selections, query, execution_strategy)
  @target = target
  @type = type
  @selections = selections
  @query = query
  @execution_strategy = execution_strategy
end

Instance Attribute Details

#execution_strategyObject (readonly)

Returns the value of attribute execution_strategy.



5
6
7
# File 'lib/graphql/query/serial_execution/selection_resolution.rb', line 5

def execution_strategy
  @execution_strategy
end

#queryObject (readonly)

Returns the value of attribute query.



5
6
7
# File 'lib/graphql/query/serial_execution/selection_resolution.rb', line 5

def query
  @query
end

#selectionsObject (readonly)

Returns the value of attribute selections.



5
6
7
# File 'lib/graphql/query/serial_execution/selection_resolution.rb', line 5

def selections
  @selections
end

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/graphql/query/serial_execution/selection_resolution.rb', line 5

def target
  @target
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/graphql/query/serial_execution/selection_resolution.rb', line 5

def type
  @type
end

Instance Method Details

#resultObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql/query/serial_execution/selection_resolution.rb', line 15

def result
  # In a first pass, we flatten the selection by merging in fields from
  # any fragments - this prevents us from resolving the same fields
  # more than one time in cases where fragments repeat fields.
  # Then, In a second pass, we resolve the flattened set of fields
  selections
    .reduce({}){|memo, ast_node|
      flattened_selections = flatten_selection(ast_node)
      flattened_selections.each do |name, selection|
        merge_into_result(memo, selection)
      end
      memo
    }
    .values
    .reduce({}){|memo, ast_node|
      memo.merge(resolve_field(ast_node))
    }
end