Module: GraphQL::Execution::Execute::ExecutionFunctions Private
- Included in:
- GraphQL::Execution::Execute
- Defined in:
- lib/graphql/execution/execute.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
- .continue_resolve_field(raw_value, field_ctx) ⇒ Object private
- .lazy_resolve_root_selection(result, query: nil, queries: nil) ⇒ Object private
- .resolve_field(object, field_ctx) ⇒ Object private
- .resolve_root_selection(query) ⇒ Object private
- .resolve_selection(object, current_type, current_ctx, mutation: false) ⇒ Object private
- .resolve_value(value, field_type, field_ctx) ⇒ Object private
Class Method Details
.continue_resolve_field(raw_value, field_ctx) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/graphql/execution/execute.rb', line 133 def continue_resolve_field(raw_value, field_ctx) if field_ctx.parent.invalid_null? return nil end query = field_ctx.query case raw_value when GraphQL::ExecutionError raw_value.ast_node ||= field_ctx.ast_node raw_value.path = field_ctx.path query.context.errors.push(raw_value) when Array list_errors = raw_value.each_with_index.select { |value, _| value.is_a?(GraphQL::ExecutionError) } if list_errors.any? list_errors.each do |error, index| error.ast_node = field_ctx.ast_node error.path = field_ctx.path + [index] query.context.errors.push(error) end end end resolve_value( raw_value, field_ctx.type, field_ctx, ) end |
.lazy_resolve_root_selection(result, query: nil, queries: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 49 50 51 52 53 |
# File 'lib/graphql/execution/execute.rb', line 45 def lazy_resolve_root_selection(result, query: nil, queries: nil) if query.nil? && queries.length == 1 query = queries[0] end GraphQL::Tracing.trace("execute_query_lazy", {queries: queries, query: query}) do GraphQL::Execution::Lazy.resolve(result) end end |
.resolve_field(object, field_ctx) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/graphql/execution/execute.rb', line 99 def resolve_field(object, field_ctx) query = field_ctx.query irep_node = field_ctx.irep_node parent_type = irep_node.owner_type field = field_ctx.field raw_value = begin arguments = query.arguments_for(irep_node, field) field_ctx.schema.middleware.invoke([parent_type, object, field, arguments, field_ctx]) rescue GraphQL::ExecutionError => err err end # If the returned object is lazy (unfinished), # assign the lazy object to `.value=` so we can resolve it later. # When we resolve it later, reassign it to `.value=` so that # the finished value replaces the unfinished one. # # If the returned object is finished, continue to coerce # and resolve child fields if query.schema.lazy?(raw_value) field_ctx.value = field.prepare_lazy(raw_value, arguments, field_ctx).then { |inner_value| field_ctx.value = continue_resolve_field(inner_value, field_ctx) } elsif raw_value.is_a?(GraphQL::Execution::Lazy) # It came from a connection resolve, assume it was already instrumented field_ctx.value = raw_value.then { |inner_value| field_ctx.value = continue_resolve_field(inner_value, field_ctx) } else field_ctx.value = continue_resolve_field(raw_value, field_ctx) end end |
.resolve_root_selection(query) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/graphql/execution/execute.rb', line 31 def resolve_root_selection(query) GraphQL::Tracing.trace("execute_query", query: query) do operation = query.selected_operation op_type = operation.operation_type root_type = query.root_type_for_operation(op_type) resolve_selection( query.root_value, root_type, query.context, mutation: query.mutation? ) end end |
.resolve_selection(object, current_type, current_ctx, mutation: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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 91 92 93 94 95 96 97 |
# File 'lib/graphql/execution/execute.rb', line 55 def resolve_selection(object, current_type, current_ctx, mutation: false ) # Assign this _before_ resolving the children # so that when a child propagates null, the selection result is # ready for it. current_ctx.value = {} selections_on_type = current_ctx.irep_node.typed_children[current_type] selections_on_type.each do |name, child_irep_node| field_ctx = current_ctx.spawn_child( key: name, object: object, irep_node: child_irep_node, ) field_result = GraphQL::Tracing.trace("execute_field", { context: field_ctx }) do resolve_field( object, field_ctx ) end if field_result.is_a?(Skip) next end if mutation GraphQL::Execution::Lazy.resolve(field_ctx) end # If the last subselection caused a null to propagate to _this_ selection, # then we may as well quit executing fields because they # won't be in the response if current_ctx.invalid_null? break else current_ctx.value[name] = field_ctx end end current_ctx.value end |
.resolve_value(value, field_type, field_ctx) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/graphql/execution/execute.rb', line 162 def resolve_value(value, field_type, field_ctx) field_defn = field_ctx.field if value.nil? if field_type.kind.non_null? parent_type = field_ctx.irep_node.owner_type type_error = GraphQL::InvalidNullError.new(parent_type, field_defn, value) field_ctx.schema.type_error(type_error, field_ctx) PROPAGATE_NULL else nil end elsif value.is_a?(GraphQL::ExecutionError) if field_type.kind.non_null? PROPAGATE_NULL else nil end elsif value.is_a?(Skip) field_ctx.value = value else case field_type.kind when GraphQL::TypeKinds::SCALAR, GraphQL::TypeKinds::ENUM field_type.coerce_result(value, field_ctx) when GraphQL::TypeKinds::LIST inner_type = field_type.of_type i = 0 result = [] field_ctx.value = result value.each do |inner_value| inner_ctx = field_ctx.spawn_child( key: i, object: inner_value, irep_node: field_ctx.irep_node, ) inner_result = resolve_value( inner_value, inner_type, inner_ctx, ) inner_ctx.value = inner_result result << inner_ctx i += 1 end result when GraphQL::TypeKinds::NON_NULL inner_type = field_type.of_type resolve_value( value, inner_type, field_ctx, ) when GraphQL::TypeKinds::OBJECT resolve_selection( value, field_type, field_ctx ) when GraphQL::TypeKinds::UNION, GraphQL::TypeKinds::INTERFACE query = field_ctx.query resolved_type = field_type.resolve_type(value, field_ctx) possible_types = query.possible_types(field_type) if !possible_types.include?(resolved_type) parent_type = field_ctx.irep_node.owner_type type_error = GraphQL::UnresolvedTypeError.new(value, field_defn, parent_type, resolved_type, possible_types) field_ctx.schema.type_error(type_error, field_ctx) PROPAGATE_NULL else resolve_value( value, resolved_type, field_ctx, ) end else raise("Unknown type kind: #{field_type.kind}") end end end |