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:, 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
# File 'lib/graphql/execution/selections_step.rb', line 5

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

Instance Attribute Details

#objectsObject (readonly)

Returns the value of attribute objects.



18
19
20
# File 'lib/graphql/execution/selections_step.rb', line 18

def objects
  @objects
end

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/graphql/execution/selections_step.rb', line 18

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



18
19
20
# File 'lib/graphql/execution/selections_step.rb', line 18

def query
  @query
end

#resultsObject (readonly)

Returns the value of attribute results.



18
19
20
# File 'lib/graphql/execution/selections_step.rb', line 18

def results
  @results
end

Instance Method Details

#callObject



26
27
28
29
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
# File 'lib/graphql/execution/selections_step.rb', line 26

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 = @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



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

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