Class: GraphQL::Query::Partial
- Inherits:
-
Object
- Object
- GraphQL::Query::Partial
show all
- Includes:
- Runnable
- Defined in:
- lib/graphql/query/partial.rb
Overview
This class is like a GraphQL::Query, except it can run on an arbitrary path within a query string.
It depends on a "parent" GraphQL::Query.
During execution, it calls query-related tracing hooks but passes itself as query:.
The Partial will use your Schema.resolve_type hook to find the right GraphQL type to use for
object in some cases.
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Runnable
#after_lazy, #arguments_cache, #arguments_for, #handle_or_reraise
Constructor Details
#initialize(path: nil, object:, query:, context: nil, fragment_node: nil, type: nil) ⇒ Partial
Returns a new instance of Partial.
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
|
# File 'lib/graphql/query/partial.rb', line 22
def initialize(path: nil, object:, query:, context: nil, fragment_node: nil, type: nil)
@path = path
@object = object
@query = query
@schema = query.schema
context_vals = @query.context.to_h
if context
context_vals = context_vals.merge(context)
end
@context = GraphQL::Query::Context.new(query: self, schema: @query.schema, values: context_vals)
@multiplex = nil
@result_values = nil
@result = nil
@finalizers = @top_level_finalizers = nil
if fragment_node
@ast_nodes = [fragment_node]
@root_type = type || raise(ArgumentError, "Pass `type:` when using `node:`")
@field_definition = nil
elsif path.nil?
raise ArgumentError, "`path:` is required if `node:` is not given; add `path:`"
else
set_type_info_from_path
end
@leaf = @root_type.unwrap.kind.leaf?
end
|
Instance Attribute Details
#ast_nodes ⇒ Object
Returns the value of attribute ast_nodes.
59
60
61
|
# File 'lib/graphql/query/partial.rb', line 59
def ast_nodes
@ast_nodes
end
|
#context ⇒ Object
Returns the value of attribute context.
59
60
61
|
# File 'lib/graphql/query/partial.rb', line 59
def context
@context
end
|
#field_definition ⇒ Object
Returns the value of attribute field_definition.
59
60
61
|
# File 'lib/graphql/query/partial.rb', line 59
def field_definition
@field_definition
end
|
#multiplex ⇒ Object
Returns the value of attribute multiplex.
61
62
63
|
# File 'lib/graphql/query/partial.rb', line 61
def multiplex
@multiplex
end
|
#object ⇒ Object
Returns the value of attribute object.
59
60
61
|
# File 'lib/graphql/query/partial.rb', line 59
def object
@object
end
|
#path ⇒ Object
Returns the value of attribute path.
59
60
61
|
# File 'lib/graphql/query/partial.rb', line 59
def path
@path
end
|
#query ⇒ Object
Returns the value of attribute query.
59
60
61
|
# File 'lib/graphql/query/partial.rb', line 59
def query
@query
end
|
#result_values ⇒ Object
Returns the value of attribute result_values.
61
62
63
|
# File 'lib/graphql/query/partial.rb', line 61
def result_values
@result_values
end
|
#root_type ⇒ Object
Returns the value of attribute root_type.
59
60
61
|
# File 'lib/graphql/query/partial.rb', line 59
def root_type
@root_type
end
|
#schema ⇒ Object
Returns the value of attribute schema.
59
60
61
|
# File 'lib/graphql/query/partial.rb', line 59
def schema
@schema
end
|
Instance Method Details
#analysis_errors=(_ignored) ⇒ Object
118
119
120
|
# File 'lib/graphql/query/partial.rb', line 118
def analysis_errors=(_ignored)
end
|
#current_trace ⇒ Object
78
79
80
|
# File 'lib/graphql/query/partial.rb', line 78
def current_trace
@query.current_trace
end
|
#fragments ⇒ Object
94
95
96
|
# File 'lib/graphql/query/partial.rb', line 94
def fragments
@query.fragments
end
|
#leaf? ⇒ Boolean
51
52
53
|
# File 'lib/graphql/query/partial.rb', line 51
def leaf?
@leaf
end
|
#query? ⇒ Boolean
106
107
108
|
# File 'lib/graphql/query/partial.rb', line 106
def query?
true
end
|
#resolve_type ⇒ Object
86
87
88
|
# File 'lib/graphql/query/partial.rb', line 86
def resolve_type(...)
@query.resolve_type(...)
end
|
#result ⇒ Object
74
75
76
|
# File 'lib/graphql/query/partial.rb', line 74
def result
@result ||= Result.new(query: self, values: result_values)
end
|
#root_value ⇒ Object
55
56
57
|
# File 'lib/graphql/query/partial.rb', line 55
def root_value
object
end
|
#run_partials ⇒ Object
110
111
112
|
# File 'lib/graphql/query/partial.rb', line 110
def run_partials(...)
@query.run_partials(...)
end
|
#selected_operation ⇒ Object
126
127
128
|
# File 'lib/graphql/query/partial.rb', line 126
def selected_operation
Language::Nodes::OperationDefinition.new(selections: ast_nodes.flat_map(&:selections))
end
|
#selected_operation_name ⇒ Object
134
135
136
|
# File 'lib/graphql/query/partial.rb', line 134
def selected_operation_name
@query.selected_operation_name
end
|
#static_errors ⇒ Object
130
131
132
|
# File 'lib/graphql/query/partial.rb', line 130
def static_errors
@query.static_errors
end
|
#subscription? ⇒ Boolean
122
123
124
|
# File 'lib/graphql/query/partial.rb', line 122
def subscription?
@query.subscription?
end
|
#types ⇒ Object
82
83
84
|
# File 'lib/graphql/query/partial.rb', line 82
def types
@query.types
end
|
#valid? ⇒ Boolean
102
103
104
|
# File 'lib/graphql/query/partial.rb', line 102
def valid?
@query.valid?
end
|
#validate ⇒ Object
98
99
100
|
# File 'lib/graphql/query/partial.rb', line 98
def validate
@query.validate
end
|
#variables ⇒ Object
90
91
92
|
# File 'lib/graphql/query/partial.rb', line 90
def variables
@query.variables
end
|