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

Defined Under Namespace

Modules: NullAccumulator

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



80
81
82
83
84
85
86
87
88
89
# File 'lib/graphql/execution/lazy/resolve.rb', line 80

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/graphql/execution/lazy/resolve.rb', line 53

def self.each_lazy(acc, value)
  case value
  when Hash
    value.each do |key, field_result|
      acc = each_lazy(acc, field_result)
    end
  when Array
    value.each do |field_result|
      acc = each_lazy(acc, field_result)
    end
  when Query::Context::SharedMethods
    field_value = value.value
    case field_value
    when Lazy
      acc = acc << value
    when Enumerable # shortcut for Hash & Array
      acc = each_lazy(acc, field_value)
    end
  end

  acc
end

.resolve(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.



27
28
29
30
# File 'lib/graphql/execution/lazy/resolve.rb', line 27

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.



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

def self.resolve_in_place(value)
  acc = each_lazy(NullAccumulator, value)

  if acc.empty?
    Lazy::NullResult
  else
    Lazy.new {
      acc.each_with_index { |ctx, idx|
        acc[idx] = GraphQL::Tracing.trace("execute_field_lazy", { context: ctx }) do
          ctx.value.value
        end
      }
      resolve_in_place(acc)
    }
  end
end