-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathpartial.rb
90 lines (75 loc) · 2.27 KB
/
partial.rb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true
module GraphQL
class Query
# This class is _like_ a {GraphQL::Query}, except
# @see Query#run_partials
class Partial
def initialize(path:, object:, query:)
@path = path
@object = object
@query = query
@context = GraphQL::Query::Context.new(query: self, schema: @query.schema, values: @query.context.to_h)
@multiplex = nil
@result_values = nil
@result = nil
end
attr_reader :context
attr_accessor :multiplex, :result_values
def result
@result ||= GraphQL::Query::Result.new(query: self, values: result_values)
end
def valid?
true
end
def analyzers
EmptyObjects::EMPTY_ARRAY
end
def current_trace
@query.current_trace
end
def analysis_errors=(_errs)
end
def subscription?
false
end
def selected_operation
selection = @query.selected_operation
@path.each do |name_in_doc|
selection = selection.selections.find { |sel| sel.alias == name_in_doc || sel.name == name_in_doc }
end
selection
end
def schema
@query.schema
end
def types
@query.types
end
def root_value
@object
end
def root_type
# Eventually do the traversal upstream of here, processing the group of partials together.
selection = @query.selected_operation
type = @query.schema.query # TODO could be other?
@path.each do |name_in_doc|
selection = selection.selections.find { |sel| sel.alias == name_in_doc || sel.name == name_in_doc }
field_defn = type.get_field(selection.name, @query.context) || raise("Invariant: no field called #{selection.name.inspect} on #{type.graphql_name}")
type = field_defn.type.unwrap
end
type
end
# TODO dry with query
def after_lazy(value, &block)
if !defined?(@runtime_instance)
@runtime_instance = context.namespace(:interpreter_runtime)[:runtime]
end
if @runtime_instance
@runtime_instance.minimal_after_lazy(value, &block)
else
@schema.after_lazy(value, &block)
end
end
end
end
end