Class: GraphQL::Query::Partial
- Inherits:
-
Object
- Object
- GraphQL::Query::Partial
- 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
-
#ast_nodes ⇒ Object
readonly
Returns the value of attribute ast_nodes.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#field_definition ⇒ Object
readonly
Returns the value of attribute field_definition.
-
#multiplex ⇒ Object
Returns the value of attribute multiplex.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#result_values ⇒ Object
Returns the value of attribute result_values.
-
#root_type ⇒ Object
readonly
Returns the value of attribute root_type.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#analysis_errors=(_ignored) ⇒ Object
-
#analyzers ⇒ Object
-
#current_trace ⇒ Object
-
#fragments ⇒ Object
-
#initialize(path: nil, object:, query:, context: nil, fragment_node: nil, type: nil) ⇒ Partial
constructor
A new instance of Partial.
-
#leaf? ⇒ Boolean
-
#resolve_type ⇒ Object
-
#result ⇒ Object
-
#selected_operation ⇒ Object
-
#selected_operation_name ⇒ Object
-
#static_errors ⇒ Object
-
#subscription? ⇒ Boolean
-
#types ⇒ Object
-
#valid? ⇒ Boolean
-
#variables ⇒ Object
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 |
# 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 if fragment_node @ast_nodes = [fragment_node] @root_type = type || raise(ArgumentError, "Pass `type:` when using `node:`") # This is only used when `@leaf` @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 (readonly)
Returns the value of attribute ast_nodes.
54 55 56 |
# File 'lib/graphql/query/partial.rb', line 54 def ast_nodes @ast_nodes end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
54 55 56 |
# File 'lib/graphql/query/partial.rb', line 54 def context @context end |
#field_definition ⇒ Object (readonly)
Returns the value of attribute field_definition.
54 55 56 |
# File 'lib/graphql/query/partial.rb', line 54 def field_definition @field_definition end |
#multiplex ⇒ Object
Returns the value of attribute multiplex.
56 57 58 |
# File 'lib/graphql/query/partial.rb', line 56 def multiplex @multiplex end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
54 55 56 |
# File 'lib/graphql/query/partial.rb', line 54 def object @object end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
54 55 56 |
# File 'lib/graphql/query/partial.rb', line 54 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
54 55 56 |
# File 'lib/graphql/query/partial.rb', line 54 def query @query end |
#result_values ⇒ Object
Returns the value of attribute result_values.
56 57 58 |
# File 'lib/graphql/query/partial.rb', line 56 def result_values @result_values end |
#root_type ⇒ Object (readonly)
Returns the value of attribute root_type.
54 55 56 |
# File 'lib/graphql/query/partial.rb', line 54 def root_type @root_type end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
54 55 56 |
# File 'lib/graphql/query/partial.rb', line 54 def schema @schema end |
Instance Method Details
#analysis_errors=(_ignored) ⇒ Object
101 102 103 |
# File 'lib/graphql/query/partial.rb', line 101 def analysis_errors=(_ignored) # pass end |
#analyzers ⇒ Object
97 98 99 |
# File 'lib/graphql/query/partial.rb', line 97 def analyzers EmptyObjects::EMPTY_ARRAY end |
#current_trace ⇒ Object
73 74 75 |
# File 'lib/graphql/query/partial.rb', line 73 def current_trace @query.current_trace end |
#fragments ⇒ Object
89 90 91 |
# File 'lib/graphql/query/partial.rb', line 89 def fragments @query.fragments end |
#leaf? ⇒ Boolean
50 51 52 |
# File 'lib/graphql/query/partial.rb', line 50 def leaf? @leaf end |
#resolve_type ⇒ Object
81 82 83 |
# File 'lib/graphql/query/partial.rb', line 81 def resolve_type(...) @query.resolve_type(...) end |
#result ⇒ Object
69 70 71 |
# File 'lib/graphql/query/partial.rb', line 69 def result @result ||= Result.new(query: self, values: result_values) end |
#selected_operation ⇒ Object
109 110 111 |
# File 'lib/graphql/query/partial.rb', line 109 def selected_operation ast_nodes.first end |
#selected_operation_name ⇒ Object
117 118 119 |
# File 'lib/graphql/query/partial.rb', line 117 def selected_operation_name @query.selected_operation_name end |
#static_errors ⇒ Object
113 114 115 |
# File 'lib/graphql/query/partial.rb', line 113 def static_errors @query.static_errors end |
#subscription? ⇒ Boolean
105 106 107 |
# File 'lib/graphql/query/partial.rb', line 105 def subscription? @query.subscription? end |
#types ⇒ Object
77 78 79 |
# File 'lib/graphql/query/partial.rb', line 77 def types @query.types end |
#valid? ⇒ Boolean
93 94 95 |
# File 'lib/graphql/query/partial.rb', line 93 def valid? @query.valid? end |
#variables ⇒ Object
85 86 87 |
# File 'lib/graphql/query/partial.rb', line 85 def variables @query.variables end |