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
+ if own_exts
387
+ if ( s_exts = superclass . extensions ) . any?
388
+ own_exts + superclass . extensions
389
+ else
390
+ own_exts
391
+ end
392
+ else
393
+ superclass . extensions
394
+ end
395
+ else
396
+ own_exts || EMPTY_ARRAY
397
+ end
383
398
end
384
399
385
400
private
386
401
402
+ def own_extensions
403
+ @own_extensions
404
+ end
405
+
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