Class: GraphQL::Query::SerialExecution::SelectionResolution
- Inherits:
-
Object
- Object
- GraphQL::Query::SerialExecution::SelectionResolution
- Defined in:
- lib/graphql/query/serial_execution/selection_resolution.rb
Instance Attribute Summary collapse
-
#execution_strategy ⇒ Object
readonly
Returns the value of attribute execution_strategy.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#selections ⇒ Object
readonly
Returns the value of attribute selections.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(target, type, selections, query, execution_strategy) ⇒ SelectionResolution
constructor
A new instance of SelectionResolution.
- #result ⇒ Object
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_strategy ⇒ Object (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 |
#query ⇒ Object (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 |
#selections ⇒ Object (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 |
#target ⇒ Object (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 |
#type ⇒ Object (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
#result ⇒ Object
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 |