Skip to content

Commit 5e11583

Browse files
committed
Thread schema definition extension modules through the spec builders
The lazy default now lives in `CommonSpecHelpers` so that `generate_schema_artifacts` (and `build_datastore_core`, via a new `schema_definition_extension_modules` option) can use it too. The `elasticgraph-health_check` and `elasticgraph-query_interceptor` suites — whose bundles exclude `elasticgraph-json_ingestion` — pass `[]` explicitly. Spec files that reference the extension constant directly now require it themselves rather than relying on the deleted probe's load-time side effect.
1 parent d938ebe commit 5e11583

10 files changed

Lines changed: 22 additions & 13 deletions

File tree

elasticgraph-health_check/spec/unit/elastic_graph/health_check/health_checker_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ def build_health_checker(health_check:, latest: {}, index_definitions: nil, sche
467467
clients_by_name: datastore_clients_by_name,
468468
clock: class_double(::Time, now: now),
469469
schema_definition: schema_definition,
470+
schema_definition_extension_modules: [],
470471
index_definitions: index_definitions,
471472
extension_settings: {"health_check" => health_check_settings}.compact
472473
)

elasticgraph-health_check/spec/unit/envoy_extension_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def process(http_method, url, with_configured_path_segment:, body: nil, cluster_
145145

146146
def build_graphql_for_path(http_path_segment)
147147
config = {http_path_segment: http_path_segment}.compact
148-
schema_artifacts = generate_schema_artifacts do |schema|
148+
schema_artifacts = generate_schema_artifacts(extension_modules: []) do |schema|
149149
schema.register_graphql_extension(EnvoyExtension, defined_at: "elastic_graph/health_check/envoy_extension", **config)
150150
schema.object_type "Widget" do |t|
151151
t.field "id", "ID"

elasticgraph-json_ingestion/spec/unit/elastic_graph/json_ingestion/schema_definition/indexing/json_schema_with_metadata_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# frozen_string_literal: true
88

9+
require "elastic_graph/json_ingestion/schema_definition/api_extension"
910
require "elastic_graph/json_ingestion/schema_definition/indexing/json_schema_with_metadata"
1011
require "elastic_graph/spec_support/schema_definition_helpers"
1112

elasticgraph-json_ingestion/spec/unit/elastic_graph/json_ingestion/schema_definition/json_schema_field_metadata_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# frozen_string_literal: true
88

9+
require "elastic_graph/json_ingestion/schema_definition/api_extension"
910
require "elastic_graph/json_ingestion/schema_definition/indexing/json_schema_field_metadata"
1011
require "elastic_graph/spec_support/schema_definition_helpers"
1112

elasticgraph-json_ingestion/spec/unit/elastic_graph/json_ingestion/schema_definition/schema_elements/scalar_type_extension_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
require "elastic_graph/constants"
1010
require "elastic_graph/errors"
11+
require "elastic_graph/json_ingestion/schema_definition/api_extension"
1112
require "elastic_graph/json_ingestion/schema_definition/schema_elements/scalar_type_extension"
1213
require "elastic_graph/spec_support/schema_definition_helpers"
1314

elasticgraph-query_interceptor/spec/unit/elastic_graph/query_interceptor/graphql_extension_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def expect_configured_interceptors(graphql)
170170
end
171171

172172
def generate_schema_artifacts
173-
super do |schema|
173+
super(extension_modules: []) do |schema|
174174
yield schema
175175

176176
# Ensure there's at least one indexed type defined to avoid GraphQL validation errors.

elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/runtime_metadata/runtime_metadata_support.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#
77
# frozen_string_literal: true
88

9-
require "elastic_graph/json_ingestion/schema_definition/api_extension"
109
require "elastic_graph/spec_support/schema_definition_helpers"
1110
require "elastic_graph/spec_support/runtime_metadata_support"
1211

spec_support/lib/elastic_graph/spec_support/builds_datastore_core.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def build_datastore_core(
2929
clusters: nil,
3030
schema_artifacts_directory: nil,
3131
schema_artifacts: nil,
32+
schema_definition_extension_modules: nil,
3233
datastore_backend: nil,
3334
reload_schema_artifacts: false,
3435
**config_overrides,
@@ -59,6 +60,7 @@ def build_datastore_core(
5960
schema_element_name_overrides: schema_element_name_overrides,
6061
derived_type_name_formats: derived_type_name_formats,
6162
enum_value_overrides_by_type: enum_value_overrides_by_type,
63+
extension_modules: schema_definition_extension_modules || default_schema_definition_extension_modules,
6264
reload_schema_artifacts: reload_schema_artifacts,
6365
&schema_definition
6466
)

spec_support/lib/elastic_graph/spec_support/schema_definition_helpers.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ def define_schema_with_schema_elements(schema_elements, extension_modules: defau
3535
)
3636
end
3737

38-
# The require is performed lazily (only when a spec relies on the default) so that this file can be
39-
# loaded in spec bundles that do not include the optional `elasticgraph-json_ingestion` gem. Suites in
40-
# such bundles must pass `extension_modules:` explicitly; if one relies on the default it will get a
41-
# clear `LoadError` here rather than silently building schema artifacts without JSON schemas.
42-
def default_schema_definition_extension_modules
43-
require "elastic_graph/json_ingestion/schema_definition/api_extension"
44-
[::ElasticGraph::JSONIngestion::SchemaDefinition::APIExtension]
45-
end
38+
# `default_schema_definition_extension_modules` is provided by `CommonSpecHelpers`, which performs
39+
# the `elasticgraph-json_ingestion` require lazily so this file can be loaded in spec bundles that
40+
# do not include that optional gem.
4641
end

spec_support/spec_helper.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,23 @@ def without_vcr
356356
end
357357
# :nocov:
358358

359+
# The require is performed lazily (only when a spec relies on the default) so that this can be used
360+
# from spec bundles that do not include the optional `elasticgraph-json_ingestion` gem. Suites in
361+
# such bundles must pass `extension_modules:` explicitly; if one relies on the default it will get a
362+
# clear `LoadError` here rather than silently building schema artifacts without JSON schemas.
363+
def default_schema_definition_extension_modules
364+
require "elastic_graph/json_ingestion/schema_definition/api_extension"
365+
[::ElasticGraph::JSONIngestion::SchemaDefinition::APIExtension]
366+
end
367+
359368
def generate_schema_artifacts(
360369
schema_element_name_form: :snake_case,
361370
schema_element_name_overrides: {},
362371
derived_type_name_formats: {},
363372
enum_value_overrides_by_type: {},
373+
extension_modules: default_schema_definition_extension_modules,
364374
reload_schema_artifacts: false
365375
)
366-
require "elastic_graph/json_ingestion/schema_definition/api_extension"
367376
require "elastic_graph/schema_definition/test_support"
368377
require "stringio"
369378

@@ -373,7 +382,7 @@ def generate_schema_artifacts(
373382
schema_element_name_overrides: schema_element_name_overrides,
374383
derived_type_name_formats: derived_type_name_formats,
375384
enum_value_overrides_by_type: enum_value_overrides_by_type,
376-
extension_modules: [::ElasticGraph::JSONIngestion::SchemaDefinition::APIExtension],
385+
extension_modules: extension_modules,
377386
reload_schema_artifacts: reload_schema_artifacts,
378387
output: output
379388
) do |schema|

0 commit comments

Comments
 (0)