Skip to content

Commit

Permalink
Use hard-coded calls to eager-loadable dependents instead
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Dec 2, 2024
1 parent 00e480c commit 9a0a00d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions lib/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 1 addition & 6 deletions lib/graphql/autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/graphql/autoload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a0a00d

Please sign in to comment.