-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexecution_scope.rb
More file actions
55 lines (47 loc) · 1.32 KB
/
execution_scope.rb
File metadata and controls
55 lines (47 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
# frozen_string_literal: true
module GraphQL::Cardinal
class Executor
class ExecutionScope
attr_reader :parent_type, :selections, :sources, :responses, :path, :parent
attr_accessor :fields
def initialize(
parent_type:,
selections:,
sources:,
responses:,
loader_cache: nil,
loader_group: nil,
path: [],
parent: nil
)
@parent_type = parent_type
@selections = selections
@sources = sources
@responses = responses
@loader_cache = loader_cache
@loader_group = loader_group
@path = path.freeze
@parent = parent
@fields = nil
end
def defer(loader_class, keys:, group: nil)
loader = loader_cache[[loader_class, group]] ||= loader_class.new(group)
loader.load(keys)
end
def lazy_fields?
@fields&.each_value&.any? { _1.result.is_a?(Promise) } || false
end
# is this scope ungrouped, or have all scopes in the group built their fields?
def lazy_fields_ready?
!@loader_group || @loader_group.all?(&:fields)
end
private
def loader_cache
@loader_cache ||= {}
end
def lazy_exec!
loader_cache.each_value { |loader| loader.send(:lazy_exec!) }
end
end
end
end