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" 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.
Run via Query#run_partials.
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
Parameters.
- #input_values ⇒ Object
- #leaf? ⇒ Boolean
- #query? ⇒ Boolean
- #resolve_type ⇒ Object
- #result ⇒ Object
- #root_value ⇒ Object
- #run_partials ⇒ Object
- #selected_operation ⇒ Object
- #selected_operation_name ⇒ Object
- #static_errors ⇒ Object
- #subscription? ⇒ Boolean
- #types ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
- #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
Parameters
path(Array<String, Integer>) — A path inquery.query_stringto start executing fromobject(Object) — A starting object for executionquery(GraphQL::Query) — A full query instance that this partial is based on. Caches are shared.context(Hash) — Extra context values to merge intoquery.context, if providedfragment_node(GraphQL::Language::Nodes::InlineFragment, GraphQL::Language::Nodes::FragmentDefinition)
:call-seq:
initialize(Array[String | Integer] path:, Object object:, GraphQL::Query query:, Hash context:, GraphQL::Language::Nodes::InlineFragment | GraphQL::Language::Nodes::FragmentDefinition fragment_node:, type:)
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 |
# File 'lib/graphql/query/partial.rb', line 29 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:`") # 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.
66 67 68 |
# File 'lib/graphql/query/partial.rb', line 66 def ast_nodes @ast_nodes end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
66 67 68 |
# File 'lib/graphql/query/partial.rb', line 66 def context @context end |
#field_definition ⇒ Object (readonly)
Returns the value of attribute field_definition.
66 67 68 |
# File 'lib/graphql/query/partial.rb', line 66 def field_definition @field_definition end |
#multiplex ⇒ Object
Returns the value of attribute multiplex.
68 69 70 |
# File 'lib/graphql/query/partial.rb', line 68 def multiplex @multiplex end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
66 67 68 |
# File 'lib/graphql/query/partial.rb', line 66 def object @object end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
66 67 68 |
# File 'lib/graphql/query/partial.rb', line 66 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
66 67 68 |
# File 'lib/graphql/query/partial.rb', line 66 def query @query end |
#result_values ⇒ Object
Returns the value of attribute result_values.
68 69 70 |
# File 'lib/graphql/query/partial.rb', line 68 def result_values @result_values end |
#root_type ⇒ Object (readonly)
Returns the value of attribute root_type.
66 67 68 |
# File 'lib/graphql/query/partial.rb', line 66 def root_type @root_type end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
66 67 68 |
# File 'lib/graphql/query/partial.rb', line 66 def schema @schema end |
Instance Method Details
#analysis_errors=(_ignored) ⇒ Object
134 135 136 |
# File 'lib/graphql/query/partial.rb', line 134 def analysis_errors=(_ignored) # pass end |
#analyzers ⇒ Object
130 131 132 |
# File 'lib/graphql/query/partial.rb', line 130 def analyzers EmptyObjects::EMPTY_ARRAY end |
#current_trace ⇒ Object
90 91 92 |
# File 'lib/graphql/query/partial.rb', line 90 def current_trace @query.current_trace end |
#fragments ⇒ Object
110 111 112 |
# File 'lib/graphql/query/partial.rb', line 110 def fragments @query.fragments end |
#input_values ⇒ Object
106 107 108 |
# File 'lib/graphql/query/partial.rb', line 106 def input_values @query.input_values end |
#leaf? ⇒ Boolean
58 59 60 |
# File 'lib/graphql/query/partial.rb', line 58 def leaf? @leaf end |
#query? ⇒ Boolean
122 123 124 |
# File 'lib/graphql/query/partial.rb', line 122 def query? true end |
#resolve_type ⇒ Object
98 99 100 |
# File 'lib/graphql/query/partial.rb', line 98 def resolve_type(...) @query.resolve_type(...) end |
#result ⇒ Object
86 87 88 |
# File 'lib/graphql/query/partial.rb', line 86 def result @result ||= Result.new(query: self, values: result_values) end |
#root_value ⇒ Object
62 63 64 |
# File 'lib/graphql/query/partial.rb', line 62 def root_value object end |
#run_partials ⇒ Object
126 127 128 |
# File 'lib/graphql/query/partial.rb', line 126 def run_partials(...) @query.run_partials(...) end |
#selected_operation ⇒ Object
142 143 144 |
# File 'lib/graphql/query/partial.rb', line 142 def selected_operation Language::Nodes::OperationDefinition.new(selections: ast_nodes.flat_map(&:selections)) end |
#selected_operation_name ⇒ Object
150 151 152 |
# File 'lib/graphql/query/partial.rb', line 150 def selected_operation_name @query.selected_operation_name end |
#static_errors ⇒ Object
146 147 148 |
# File 'lib/graphql/query/partial.rb', line 146 def static_errors @query.static_errors end |
#subscription? ⇒ Boolean
138 139 140 |
# File 'lib/graphql/query/partial.rb', line 138 def subscription? @query.subscription? end |
#types ⇒ Object
94 95 96 |
# File 'lib/graphql/query/partial.rb', line 94 def types @query.types end |
#valid? ⇒ Boolean
118 119 120 |
# File 'lib/graphql/query/partial.rb', line 118 def valid? @query.valid? end |
#validate ⇒ Object
114 115 116 |
# File 'lib/graphql/query/partial.rb', line 114 def validate @query.validate end |
#variables ⇒ Object
102 103 104 |
# File 'lib/graphql/query/partial.rb', line 102 def variables @query.variables end |