File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -374,16 +374,36 @@ def arguments_loads_as_type
374
374
# @param extension [Class] Extension class
375
375
# @param options [Hash] Optional extension options
376
376
def extension ( extension , **options )
377
- extensions << { extension => options }
377
+ @own_extensions ||= [ ]
378
+ @own_extensions << { extension => options }
378
379
end
379
380
380
381
# @api private
381
382
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
383
399
end
384
400
385
401
private
386
402
403
+ def own_extensions
404
+ @own_extensions
405
+ end
406
+
387
407
def own_arguments_loads_as_type
388
408
@own_arguments_loads_as_type ||= { }
389
409
end
Original file line number Diff line number Diff line change @@ -811,6 +811,20 @@ def load_input(input); end
811
811
res = exec_query " { resolverWithExtension } "
812
812
assert_equal "Hi, Robert!" , res [ "data" ] [ "resolverWithExtension" ]
813
813
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
814
828
end
815
829
816
830
describe "max_page_size" do
You can’t perform that action at this time.
0 commit comments