Module: GraphQL::Execution::Lazy::Resolve Private

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

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helpers for dealing with data structures containing GraphQL::Execution::Lazy instances

Class Method Summary collapse

Class Method Details

.deep_sync(val) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Traverse val, triggering resolution for each GraphQL::Execution::Lazy. These GraphQL::Execution::Lazys are expected to mutate their owner data structures during resolution! (They're created with the .then calls in resolve_in_place).



56
57
58
59
60
61
62
63
64
65
# File 'lib/graphql/execution/lazy/resolve.rb', line 56

def self.deep_sync(val)
  case val
  when Lazy
    deep_sync(val.value)
  when Array
    val.each { |v| deep_sync(v.value) }
  when Hash
    val.each { |k, v| deep_sync(v.value) }
  end
end

.each_lazy(value, &block) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

If value is a collection, call block with any GraphQL::Execution::Lazy instances in the collection



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/graphql/execution/lazy/resolve.rb', line 32

def self.each_lazy(value, &block)
  case value
  when SelectionResult
    value.each do |key, field_result|
      each_lazy(field_result, &block)
    end
  when Array
    value.each do |field_result|
      each_lazy(field_result, &block)
    end
  when FieldResult
    field_value = value.value
    if field_value.is_a?(Lazy)
      yield(value)
    else
      each_lazy(field_value, &block)
    end
  end
end

.resolve(value) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Mutate value, replacing GraphQL::Execution::Lazy instances in place with their resolved values



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

def self.resolve(value)
  lazies = resolve_in_place(value)
  deep_sync(lazies)
end

.resolve_in_place(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphql/execution/lazy/resolve.rb', line 15

def self.resolve_in_place(value)
  lazies = []

  each_lazy(value) do |field_result|
    inner_lazy = field_result.value.then do |inner_v|
      field_result.value = inner_v
      resolve_in_place(inner_v)
    end
    lazies.push(inner_lazy)
  end

  Lazy.new { lazies.map(&:value) }
end