File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -374,16 +374,36 @@ def arguments_loads_as_type
374374 # @param extension [Class] Extension class
375375 # @param options [Hash] Optional extension options
376376 def extension ( extension , **options )
377- extensions << { extension => options }
377+ @own_extensions ||= [ ]
378+ @own_extensions << { extension => options }
378379 end
379380
380381 # @api private
381382 def extensions
382- @extensions ||= [ ]
383+ own_exts = @own_extensions
384+ # Jump through some hoops to avoid creating arrays when we don't actually need them
385+ if superclass . respond_to? ( :extensions )
386+ s_exts = superclass . extensions
387+ if own_exts
388+ if s_exts . any?
389+ own_exts + s_exts
390+ else
391+ own_exts
392+ end
393+ else
394+ s_exts
395+ end
396+ else
397+ own_exts || EMPTY_ARRAY
398+ end
383399 end
384400
385401 private
386402
403+ def own_extensions
404+ @own_extensions
405+ end
406+
387407 def own_arguments_loads_as_type
388408 @own_arguments_loads_as_type ||= { }
389409 end
Original file line number Diff line number Diff line change @@ -811,6 +811,20 @@ def load_input(input); end
811811 res = exec_query " { resolverWithExtension } "
812812 assert_equal "Hi, Robert!" , res [ "data" ] [ "resolverWithExtension" ]
813813 end
814+
815+ it "inherits extensions" do
816+ r1 = Class . new ( GraphQL ::Schema ::Resolver ) do
817+ extension ( ResolverTest ::GreetingExtension )
818+ end
819+
820+ e2 = Class . new ( GraphQL ::Schema ::FieldExtension )
821+ r2 = Class . new ( r1 ) do
822+ extension ( e2 )
823+ end
824+
825+ assert_equal 1 , r1 . extensions . size
826+ assert_equal 2 , r2 . extensions . size
827+ end
814828 end
815829
816830 describe "max_page_size" do
You can’t perform that action at this time.
0 commit comments