Module: GraphQL::Execution::Interpreter::Resolve

Defined in:
lib/graphql/execution/interpreter/resolve.rb

Class Method Summary collapse

Class Method Details

.resolve(results) ⇒ Array

After getting results back from an interpreter evaluation, continue it until you get a response-ready Ruby value.

results is one level of depth of a query or multiplex.

Resolve all lazy values in that depth before moving on to the next level.

It's assumed that the lazies will return Lazy instances if there's more work to be done, or return Hash/Array if the query should be continued.

Parameters:

  • results (Array)

Returns:

  • (Array)

    Same size, filled with finished values


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
# File 'lib/graphql/execution/interpreter/resolve.rb', line 29

def self.resolve(results)
  next_results = []

  # Work through the queue until it's empty
  while results.size > 0
    result_value = results.shift

    if result_value.is_a?(Lazy)
      result_value = result_value.value
    end

    if result_value.is_a?(Lazy)
      # Since this field returned another lazy,
      # add it to the same queue
      results << result_value
    elsif result_value.is_a?(Hash)
      # This is part of the next level, add it
      next_results.concat(result_value.values)
    elsif result_value.is_a?(Array)
      # This is part of the next level, add it
      next_results.concat(result_value)
    end
  end

  next_results
end

.resolve_all(results) ⇒ void

This method returns an undefined value.

Continue field results in results until there's nothing else to continue.


9
10
11
12
13
# File 'lib/graphql/execution/interpreter/resolve.rb', line 9

def self.resolve_all(results)
  while results.any?
    results = resolve(results)
  end
end