@@ -277,15 +277,6 @@ def extensions(new_extensions = nil)
277
277
# Read the value
278
278
@extensions
279
279
else
280
- if @resolve || @function
281
- raise ArgumentError , <<-MSG
282
- Extensions are not supported with resolve procs or functions,
283
- but #{ owner . name } .#{ name } has: #{ @resolve || @function }
284
- So, it can't have extensions: #{ extensions } .
285
- Use a method or a Schema::Resolver instead.
286
- MSG
287
- end
288
-
289
280
# Normalize to a Hash of {name => options}
290
281
extensions_with_options = if new_extensions . last . is_a? ( Hash )
291
282
new_extensions . pop
@@ -454,12 +445,16 @@ def resolve_field(obj, args, ctx)
454
445
# @see https://github.com/rmosolgo/graphql-ruby/issues/1990 before removing
455
446
inner_obj = after_obj && after_obj . object
456
447
if authorized? ( inner_obj , query_ctx )
448
+ ruby_args = to_ruby_args ( after_obj , args , ctx )
457
449
# Then if it passed, resolve the field
458
450
if @resolve_proc
459
451
# Might be nil, still want to call the func in that case
460
- @resolve_proc . call ( inner_obj , args , ctx )
452
+ with_extensions ( inner_obj , ruby_args , query_ctx ) do |extended_obj , extended_args |
453
+ # Pass the GraphQL args here for compatibility:
454
+ @resolve_proc . call ( extended_obj , args , ctx )
455
+ end
461
456
else
462
- public_send_field ( after_obj , args , ctx )
457
+ public_send_field ( after_obj , ruby_args , ctx )
463
458
end
464
459
else
465
460
err = GraphQL ::UnauthorizedFieldError . new ( object : inner_obj , type : obj . class , context : ctx , field : self )
@@ -568,7 +563,13 @@ def fetch_extra(extra_name, ctx)
568
563
569
564
NO_ARGS = { } . freeze
570
565
571
- def public_send_field ( obj , graphql_args , field_ctx )
566
+ # Convert a GraphQL arguments instance into a Ruby-style hash.
567
+ #
568
+ # @param obj [GraphQL::Schema::Object] The object where this field is being resolved
569
+ # @param graphql_args [GraphQL::Query::Arguments]
570
+ # @param field_ctx [GraphQL::Query::Context::FieldResolutionContext]
571
+ # @return [Hash<Symbol => Any>]
572
+ def to_ruby_args ( obj , graphql_args , field_ctx )
572
573
if graphql_args . any? || @extras . any?
573
574
# Splat the GraphQL::Arguments to Ruby keyword arguments
574
575
ruby_kwargs = graphql_args . to_kwargs
@@ -583,10 +584,14 @@ def public_send_field(obj, graphql_args, field_ctx)
583
584
@extras . each do |extra_arg |
584
585
ruby_kwargs [ extra_arg ] = fetch_extra ( extra_arg , field_ctx )
585
586
end
587
+
588
+ ruby_kwargs
586
589
else
587
- ruby_kwargs = NO_ARGS
590
+ NO_ARGS
588
591
end
592
+ end
589
593
594
+ def public_send_field ( obj , ruby_kwargs , field_ctx )
590
595
query_ctx = field_ctx . query . context
591
596
with_extensions ( obj , ruby_kwargs , query_ctx ) do |extended_obj , extended_args |
592
597
if @resolver_class
0 commit comments