diff --git a/lib/graphql/execution/interpreter/runtime.rb b/lib/graphql/execution/interpreter/runtime.rb index 9689474b9b..2fd5aedc3b 100644 --- a/lib/graphql/execution/interpreter/runtime.rb +++ b/lib/graphql/execution/interpreter/runtime.rb @@ -126,11 +126,17 @@ def evaluate_selections(path, owner_object, owner_type, selections, root_operati kwarg_arguments = arguments(object, field_defn, ast_node) # It might turn out that making arguments for every field is slow. # If we have to cache them, we'll need a more subtle approach here. - if field_defn.extras.include?(:ast_node) - kwarg_arguments[:ast_node] = ast_node - end - if field_defn.extras.include?(:execution_errors) - kwarg_arguments[:execution_errors] = ExecutionErrors.new(context, ast_node, next_path) + field_defn.extras.each do |extra| + case extra + when :ast_node + kwarg_arguments[:ast_node] = ast_node + when :execution_errors + kwarg_arguments[:execution_errors] = ExecutionErrors.new(context, ast_node, next_path) + when :path + kwarg_arguments[:path] = next_path + else + kwarg_arguments[extra] = field_defn.fetch_extra(extra, context) + end end next_selections = fields.inject([]) { |memo, f| memo.concat(f.selections) } @@ -276,9 +282,8 @@ def after_lazy(obj, field:, path:, eager: false) # Wrap the execution of _this_ method with tracing, # but don't wrap the continuation below inner_obj = query.trace("execute_field_lazy", {field: field, path: path}) do - method_name = schema.lazy_method_name(obj) begin - obj.public_send(method_name) + schema.sync_lazy(obj) rescue GraphQL::ExecutionError, GraphQL::UnauthorizedError => err yield(err) end @@ -335,6 +340,8 @@ def arg_to_value(graphql_object, arg_type, ast_value) else return false, nil end + elsif ast_value.is_a?(GraphQL::Language::Nodes::NullValue) + return true, nil elsif arg_type.is_a?(GraphQL::Schema::NonNull) arg_to_value(graphql_object, arg_type.of_type, ast_value) elsif arg_type.is_a?(GraphQL::Schema::List) diff --git a/lib/graphql/schema/field.rb b/lib/graphql/schema/field.rb index 0a57357721..f422469772 100644 --- a/lib/graphql/schema/field.rb +++ b/lib/graphql/schema/field.rb @@ -500,13 +500,9 @@ def resolve_field_method(obj, ruby_kwargs, ctx) end end - private - - CONTEXT_EXTRAS = [:path] - # @param ctx [GraphQL::Query::Context::FieldResolutionContext] def fetch_extra(extra_name, ctx) - if !CONTEXT_EXTRAS.include?(extra_name) && respond_to?(extra_name) + if extra_name != :path && respond_to?(extra_name) self.public_send(extra_name) elsif ctx.respond_to?(extra_name) ctx.public_send(extra_name) @@ -515,6 +511,8 @@ def fetch_extra(extra_name, ctx) end end + private + NO_ARGS = {}.freeze def public_send_field(obj, graphql_args, field_ctx) diff --git a/spec/support/lazy_helpers.rb b/spec/support/lazy_helpers.rb index cf7b44c03f..5be3ad7301 100644 --- a/spec/support/lazy_helpers.rb +++ b/spec/support/lazy_helpers.rb @@ -90,7 +90,7 @@ def int(value:, plus:) end def nested_sum(value:) - SumAll.new(context, value) + SumAll.new(value) end field :nullable_nested_sum, LazySum, null: true do @@ -101,7 +101,7 @@ def nullable_nested_sum(value:) if value == 13 Wrapper.new { raise GraphQL::ExecutionError.new("13 is unlucky") } else - SumAll.new(context, value) + SumAll.new(value) end end