Class: GraphQL::Execution::SelectionsStep

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/execution/selections_step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_type:, field_resolve_step:, selections:, objects:, results:, runner:, query:, path:, clobber: true) ⇒ SelectionsStep

Returns a new instance of SelectionsStep.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/graphql/execution/selections_step.rb', line 5

def initialize(parent_type:, field_resolve_step:, selections:, objects:, results:, runner:, query:, path:, clobber: true)
  @path = path
  @field_resolve_step = field_resolve_step
  @parent_type = parent_type
  @selections = selections
  @runner = runner
  @objects = objects
  @results = results
  @query = query
  @graphql_objects = nil
  @all_selections = nil
  @killed = false
  @clobber = clobber
end

Instance Attribute Details

#field_resolve_stepObject (readonly)

Returns the value of attribute field_resolve_step.



20
21
22
# File 'lib/graphql/execution/selections_step.rb', line 20

def field_resolve_step
  @field_resolve_step
end

#killedObject

Returns the value of attribute killed.



22
23
24
# File 'lib/graphql/execution/selections_step.rb', line 22

def killed
  @killed
end

#objectsObject (readonly)

Returns the value of attribute objects.



20
21
22
# File 'lib/graphql/execution/selections_step.rb', line 20

def objects
  @objects
end

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/graphql/execution/selections_step.rb', line 20

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



20
21
22
# File 'lib/graphql/execution/selections_step.rb', line 20

def query
  @query
end

#resultsObject (readonly)

Returns the value of attribute results.



20
21
22
# File 'lib/graphql/execution/selections_step.rb', line 20

def results
  @results
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/graphql/execution/selections_step.rb', line 30

def call
  @all_selections = [{}, (prototype_result = {})]
  @runner.gather_selections(@parent_type, @selections, self, self.query, @all_selections, @all_selections[1], into: @all_selections[0])
  continue_selections = []
  i = 0
  l = @all_selections.length
  while i < l
    grouped_selections = @all_selections[i]
    selections_prototype_result = @all_selections[i + 1]
    if (directives_owner = grouped_selections.delete(:__node))
      directives = directives_owner.directives
      continue_execution = true
      directives.each do |dir_node|
        dir_defn = @runner.runtime_directives[dir_node.name]
        if dir_defn # not present for `skip` or `include`
          dir_args, _errors = @runner.input_values[query].argument_values(dir_defn, dir_node.arguments, nil) # rubocop:disable Development/ContextIsPassedCop
          result = case directives_owner
          when Language::Nodes::FragmentSpread
            dir_defn.resolve_fragment_spread(directives_owner, @parent_type, @objects, dir_args, self.query.context)
          when Language::Nodes::InlineFragment
            dir_defn.resolve_inline_fragment(directives_owner, @parent_type, @objects, dir_args, self.query.context)
          else
            raise ArgumentError, "Unhandled directive owner (#{directives_owner.class}): #{directives_owner.inspect}"
          end
          if result.is_a?(Finalizer)
            result.path = path
            @results.each do |r|
              @runner.add_finalizer(@query, r, nil, result)
            end
            if result.is_a?(HaltExecution)
              continue_execution = false
              break
            end
          end

          if continue_execution
            prototype_result.merge!(selections_prototype_result)
            grouped_selections.each_value { |v| continue_selections << v }
          end
        else
          grouped_selections.each_value { |v| continue_selections << v }
        end
      end
    else
      grouped_selections.each_value { |v| continue_selections << v }
    end

    if @clobber
      i2 = 0
      l2 = @results.length
      while i2 < l2
        @results[i2].replace(prototype_result)
        i2 += 1
      end
    end

    continue_selections.each do |frs|
      @runner.add_step(frs)
    end

    i += 2
  end
end

#graphql_objectsObject



24
25
26
27
28
# File 'lib/graphql/execution/selections_step.rb', line 24

def graphql_objects
  @graphql_objects ||= @objects.map do |obj|
    @parent_type.scoped_new(obj, @query.context)
  end
end