Skip to content

Commit

Permalink
Upgrade GraphQL gem to 2.4.5 and deal with eager loading.
Browse files Browse the repository at this point in the history
GraphQL gem 2.4.5 includes some changes related to code loading:

rmosolgo/graphql-ruby#5178

I've made a few changes to deal with that:

* I've introduced `::GraphQL.eager_load!` where we do eager loading for production.
* I've stopped requiring files nested under `graphql`--instead, we should load `graphql` and rely on the autoloading.
  • Loading branch information
myronmarston committed Dec 2, 2024
1 parent 85f6dc2 commit d7bcb2d
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion elasticgraph-apollo/elasticgraph-apollo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ElasticGraphGemspecHelper.define_elasticgraph_gem(gemspec_file: __FILE__, catego

spec.add_dependency "elasticgraph-graphql", eg_version
spec.add_dependency "elasticgraph-support", eg_version
spec.add_dependency "graphql", "~> 2.4.3"
spec.add_dependency "graphql", "~> 2.4.5"
spec.add_dependency "apollo-federation", "~> 3.8"

# Note: technically, this is not purely a development dependency, but since `eg-schema_def`
Expand Down
2 changes: 1 addition & 1 deletion elasticgraph-graphql/elasticgraph-graphql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ElasticGraphGemspecHelper.define_elasticgraph_gem(gemspec_file: __FILE__, catego

spec.add_dependency "elasticgraph-datastore_core", eg_version
spec.add_dependency "elasticgraph-schema_artifacts", eg_version
spec.add_dependency "graphql", "~> 2.4.3"
spec.add_dependency "graphql", "~> 2.4.5"

spec.add_development_dependency "elasticgraph-admin", eg_version
spec.add_development_dependency "elasticgraph-elasticsearch", eg_version
Expand Down
3 changes: 3 additions & 0 deletions elasticgraph-graphql/lib/elastic_graph/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ def monotonic_clock
# at boot time instead of deferring dependency loading until we handle the first query. In other environments (such as tests),
# it's nice to load dependencies when needed.
def load_dependencies_eagerly
require "graphql"
::GraphQL.eager_load!

# run a simple GraphQL query to force load any dependencies needed to handle GraphQL queries
graphql_query_executor.execute(EAGER_LOAD_QUERY, client: Client::ELASTICGRAPH_INTERNAL)
graphql_http_endpoint # force load this too.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# frozen_string_literal: true

require "graphql/dataloader/source"
require "graphql"

module ElasticGraph
class GraphQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

require "elastic_graph/graphql/query_details_tracker"
require "elastic_graph/graphql/resolvers/query_source"
require "graphql/dataloader"
require "graphql"

module ElasticGraph
class GraphQL
Expand Down
2 changes: 1 addition & 1 deletion elasticgraph-graphql/spec/support/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require "elastic_graph/graphql/query_details_tracker"
require "elastic_graph/graphql/resolvers/query_adapter"
require "elastic_graph/graphql/resolvers/query_source"
require "graphql/dataloader"
require "graphql"

module ResolverHelperMethods
def resolve(type_name, field_name, document = nil, **options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ElasticGraphGemspecHelper.define_elasticgraph_gem(gemspec_file: __FILE__, catego

spec.add_dependency "elasticgraph-graphql", eg_version
spec.add_dependency "elasticgraph-support", eg_version
spec.add_dependency "graphql", "~> 2.4.3"
spec.add_dependency "graphql", "~> 2.4.5"
spec.add_dependency "rake", "~> 13.2"

spec.add_development_dependency "elasticgraph-elasticsearch", eg_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

require "elastic_graph/graphql/query_executor"
require "elastic_graph/query_registry/registry"
require "graphql/query/result"
require "graphql"
require "pathname"

module ElasticGraph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ElasticGraphGemspecHelper.define_elasticgraph_gem(gemspec_file: __FILE__, catego
spec.add_dependency "elasticgraph-json_schema", eg_version
spec.add_dependency "elasticgraph-schema_artifacts", eg_version
spec.add_dependency "elasticgraph-support", eg_version
spec.add_dependency "graphql", "~> 2.4.3"
spec.add_dependency "graphql", "~> 2.4.5"
spec.add_dependency "rake", "~> 13.2"

spec.add_development_dependency "elasticgraph-admin", eg_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
require "elastic_graph/schema_definition/rake_tasks"
require "elastic_graph/schema_definition/schema_elements/type_namer"
require "graphql"
require "graphql/language/block_string"
require "yaml"

module ElasticGraph
Expand Down

0 comments on commit d7bcb2d

Please sign in to comment.