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).



59
60
61
62
63
64
65
66
67
68
# File 'lib/graphql/execution/lazy/resolve.rb', line 59

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(acc, 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.

If value is a collection, add any GraphQL::Execution::Lazy instances in the collection to acc



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

def self.each_lazy(acc, value)
  case value
  when SelectionResult
    value.each do |key, field_result|
      each_lazy(acc, field_result)
    end
  when Array
    value.each do |field_result|
      each_lazy(acc, field_result)
    end
  when FieldResult
    field_value = value.value
    if field_value.is_a?(Lazy)
      acc << value
    else
      each_lazy(acc, field_value)
    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
28
29
# File 'lib/graphql/execution/lazy/resolve.rb', line 15

def self.resolve_in_place(value)
  lazies = []
  acc = []
  each_lazy(acc, value)

  acc.each 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