From 9a0a00d84b30060c5ac6ce323883f3d466a2cd39 Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Mon, 2 Dec 2024 10:43:53 -0500 Subject: [PATCH] Use hard-coded calls to eager-loadable dependents instead --- lib/graphql.rb | 7 +++++++ lib/graphql/autoload.rb | 7 +------ spec/graphql/autoload_spec.rb | 6 ++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/graphql.rb b/lib/graphql.rb index 8247956565..23a196edf3 100644 --- a/lib/graphql.rb +++ b/lib/graphql.rb @@ -10,6 +10,13 @@ module GraphQL extend Autoload + # Load all `autoload`-configured classes, and also eager-load dependents who have autoloads of their own. + def self.eager_load! + super + Query.eager_load! + Types.eager_load! + end + class Error < StandardError end diff --git a/lib/graphql/autoload.rb b/lib/graphql/autoload.rb index 85631471c7..506812b2f7 100644 --- a/lib/graphql/autoload.rb +++ b/lib/graphql/autoload.rb @@ -19,12 +19,7 @@ def autoload(const_name, path) def eager_load! @_eager_loading = true if @_eagerloaded_constants - @_eagerloaded_constants.each do |const_name| - loaded_const = const_get(const_name) - if loaded_const.respond_to?(:eager_load!) - loaded_const.eager_load! - end - end + @_eagerloaded_constants.each { |const_name| const_get(const_name) } @_eagerloaded_constants = nil end nil diff --git a/spec/graphql/autoload_spec.rb b/spec/graphql/autoload_spec.rb index 210eaee016..f9313acb0f 100644 --- a/spec/graphql/autoload_spec.rb +++ b/spec/graphql/autoload_spec.rb @@ -13,6 +13,12 @@ module EagerModule autoload(:EagerClass, "fixtures/eager_module/eager_class") autoload(:OtherEagerClass, "fixtures/eager_module/other_eager_class") autoload(:NestedEagerModule, "fixtures/eager_module/nested_eager_module") + + def self.eager_load! + super + + NestedEagerModule.eager_load! + end end describe "#autoload" do