Skip to content

Commit 8dc35fb

Browse files
committed
Make schema definition extension modules fully opt-in in specs
Nothing needs the defaulting anymore. The shared spec helpers no longer apply the JSON ingestion extension to schema definitions; instead, each place that genuinely needs JSON schemas opts in explicitly: - `generate_schema_artifacts` includes the extension only when loading the repository's main test schema (`config/schema.rb`), which uses the JSON ingestion schema definition DSL. - `build_indexer` includes the extension when it generates artifacts itself, since the indexer can only ingest JSON events today. The require is lazy so bundles without `elasticgraph-json_ingestion` can still build an indexer from an externally built `datastore_core:`. - Specs that index documents with inline schemas (and so need JSON schema validation) pass the extension at their build call sites. - Vestigial `t.json_schema` calls in unit specs that never index are removed, along with a `JsonSafeLong` placeholder assertion that duplicated coverage now living in elasticgraph-json_ingestion.
1 parent 5e11583 commit 8dc35fb

19 files changed

Lines changed: 87 additions & 66 deletions

File tree

elasticgraph-datastore_core/spec/integration/elastic_graph/datastore_core/index_definition/rollover_index_template_spec.rb

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

99
require "elastic_graph/constants"
1010
require "elastic_graph/datastore_core/index_definition"
11+
require "elastic_graph/json_ingestion/schema_definition/api_extension"
1112
require "elastic_graph/support/hash_util"
1213
require "stringio"
1314
require_relative "implementation_shared_examples"
@@ -16,6 +17,12 @@ module ElasticGraph
1617
class DatastoreCore
1718
module IndexDefinition
1819
RSpec.describe RolloverIndexTemplate, :uses_datastore, :builds_indexer do
20+
# Documents indexed by these specs are validated against the JSON schemas, so the schemas
21+
# defined in this file all include the JSON ingestion schema definition extension.
22+
def build_datastore_core(**options, &block)
23+
super(schema_definition_extension_modules: [JSONIngestion::SchemaDefinition::APIExtension], **options, &block)
24+
end
25+
1926
# Use different index names than any other tests use, because most tests expect a specific index
2027
# configuration (based on `config/schema.graphql`) and we do not want to mess with it here.
2128
let(:index_prefix) { unique_index_name }

elasticgraph-graphql/spec/acceptance/elasticgraph_graphql_acceptance_support.rb

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

99
require "elastic_graph/graphql/datastore_search_router"
10+
require "elastic_graph/json_ingestion/schema_definition/api_extension"
1011
require "elastic_graph/schema_definition/schema_elements/type_namer"
1112
require "elastic_graph/spec_support/builds_admin"
1213
require "graphql"
@@ -91,6 +92,9 @@ def self.with_both_casing_forms(&block)
9192
schema_element_name_form: :camelCase,
9293
derived_type_name_formats: derived_type_name_formats,
9394
enum_value_overrides_by_type: enum_value_overrides_by_type,
95+
# The camelCase schema definition below is derived from the repository's main test schema,
96+
# which uses the JSON ingestion schema definition DSL, so it requires this extension.
97+
schema_definition_extension_modules: [JSONIngestion::SchemaDefinition::APIExtension],
9498
schema_definition: ->(schema) do
9599
# standard:disable Security/Eval -- it's ok here in a test.
96100
schema.as_active_instance { eval(camel_case_schema_def) }

elasticgraph-graphql/spec/integration/elastic_graph/graphql/datastore_query/misc_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_relative "datastore_query_integration_support"
1010
require "elastic_graph/errors"
1111
require "elastic_graph/graphql/datastore_search_router"
12+
require "elastic_graph/json_ingestion/schema_definition/api_extension"
1213

1314
module ElasticGraph
1415
class GraphQL
@@ -85,7 +86,7 @@ def msearch(body:, **args, &block)
8586

8687
context "when the indexed type has nested `default_sort_fields`" do
8788
let(:graphql) do
88-
build_graphql(schema_definition: lambda do |schema|
89+
build_graphql(schema_definition_extension_modules: [JSONIngestion::SchemaDefinition::APIExtension], schema_definition: lambda do |schema|
8990
schema.object_type "Money" do |t|
9091
t.field "currency", "String!"
9192
t.field "amount_cents", "Int!"

elasticgraph-graphql/spec/integration/elastic_graph/graphql/resolvers/nested_relationships_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# frozen_string_literal: true
88

99
require "elastic_graph/graphql/resolvers/nested_relationships"
10+
require "elastic_graph/json_ingestion/schema_definition/api_extension"
1011

1112
module ElasticGraph
1213
class GraphQL
@@ -16,7 +17,7 @@ module Resolvers
1617
# is implemented via a filter on `id` (the search routing field)
1718
context "when the field being resolved is a relay connection field", :expect_search_routing do
1819
let(:graphql) do
19-
build_graphql(schema_definition: lambda do |schema|
20+
build_graphql(schema_definition_extension_modules: [JSONIngestion::SchemaDefinition::APIExtension], schema_definition: lambda do |schema|
2021
schema.object_type "Component" do |t|
2122
t.field "id", "ID!"
2223
t.field "name", "String!"
@@ -62,7 +63,7 @@ module Resolvers
6263

6364
describe "a relates_to_many/relates_to_one bidirectional relationship with an array foreign key from the one to the many" do
6465
let(:graphql) do
65-
build_graphql(schema_definition: lambda do |schema|
66+
build_graphql(schema_definition_extension_modules: [JSONIngestion::SchemaDefinition::APIExtension], schema_definition: lambda do |schema|
6667
schema.object_type "Money" do |t|
6768
t.field "currency", "String!"
6869
t.field "amount_cents", "Int"
@@ -241,7 +242,7 @@ module Resolvers
241242

242243
describe "a relates_to_many/relates_to_one bidirectional relationship with a scalar foreign key from the many to the one" do
243244
let(:graphql) do
244-
build_graphql(schema_definition: lambda do |schema|
245+
build_graphql(schema_definition_extension_modules: [JSONIngestion::SchemaDefinition::APIExtension], schema_definition: lambda do |schema|
245246
schema.object_type "ElectricalPart" do |t|
246247
t.field "id", "ID!"
247248
t.field "name", "String!"
@@ -381,7 +382,7 @@ module Resolvers
381382

382383
describe "a relates_to_many/relates_to_many bidirectional relationship with an array foreign key from a many to a many" do
383384
let(:graphql) do
384-
build_graphql(schema_definition: lambda do |schema|
385+
build_graphql(schema_definition_extension_modules: [JSONIngestion::SchemaDefinition::APIExtension], schema_definition: lambda do |schema|
385386
schema.object_type "Component" do |t|
386387
t.field "id", "ID!"
387388
t.field "name", "String!"
@@ -573,7 +574,7 @@ module Resolvers
573574

574575
describe "a relates_to_one/relates_to_one bidirectional relationship with a scalar foreign key from a one to a one" do
575576
let(:graphql) do
576-
build_graphql(schema_definition: lambda do |schema|
577+
build_graphql(schema_definition_extension_modules: [JSONIngestion::SchemaDefinition::APIExtension], schema_definition: lambda do |schema|
577578
schema.object_type "Manufacturer" do |t|
578579
t.field "id", "ID!"
579580
t.field "name", "String"

elasticgraph-graphql/spec/unit/elastic_graph/graphql/query_executor_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ def resolve(field:, object:, args:, context:)
447447

448448
schema.scalar_type "Operands" do |t|
449449
t.mapping type: nil
450-
t.json_schema type: "null"
451450
end
452451

453452
schema.object_type "Widget" do |t|

elasticgraph-graphql/spec/unit/elastic_graph/graphql/resolvers/get_record_field_value_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module Resolvers
1919
self.schema_artifacts = generate_schema_artifacts do |schema|
2020
schema.scalar_type "MyInt" do |t|
2121
t.mapping type: "integer"
22-
t.json_schema type: "integer"
2322
end
2423

2524
schema.object_type "PersonIdentifiers" do |t|

elasticgraph-graphql/spec/unit/elastic_graph/graphql/scalar_coercion_adapters/no_op_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module ScalarCoercionAdapters
1414
RSpec.describe "NoOp" do
1515
include_context("scalar coercion adapter support", "SomeCustomScalar", schema_definition: ->(schema) do
1616
schema.scalar_type "SomeCustomScalar" do |t|
17-
t.json_schema type: "null"
1817
t.mapping type: nil
1918
end
2019

elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema/type_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,6 @@ def search_index_definitions_from(type_name: "TheType")
955955
schema = define_schema do |s|
956956
s.scalar_type "CustomScalar" do |t|
957957
t.mapping type: "keyword"
958-
t.json_schema type: "string"
959958
end
960959
end
961960

@@ -967,7 +966,6 @@ def search_index_definitions_from(type_name: "TheType")
967966
schema = define_schema do |s|
968967
s.scalar_type "CustomScalar" do |t|
969968
t.mapping type: "keyword"
970-
t.json_schema type: "string"
971969
t.grouping_missing_value_placeholder "MISSING"
972970
end
973971
end
@@ -980,7 +978,6 @@ def search_index_definitions_from(type_name: "TheType")
980978
schema = define_schema do |s|
981979
s.scalar_type "CustomScalar" do |t|
982980
t.mapping type: "keyword"
983-
t.json_schema type: "string"
984981
t.grouping_missing_value_placeholder nil
985982
end
986983
end
@@ -1007,7 +1004,6 @@ def search_index_definitions_from(type_name: "TheType")
10071004
t.field "name", "String"
10081005
t.field "count", "Int"
10091006
t.field "price", "Float"
1010-
t.field "big_number", "JsonSafeLong"
10111007
t.index "things"
10121008
end
10131009
end
@@ -1016,7 +1012,6 @@ def search_index_definitions_from(type_name: "TheType")
10161012
expect(schema.type_named("String").grouping_missing_value_placeholder).to eq MISSING_STRING_PLACEHOLDER_VALUE
10171013
expect(schema.type_named("Int").grouping_missing_value_placeholder).to eq MISSING_NUMERIC_PLACEHOLDER
10181014
expect(schema.type_named("Float").grouping_missing_value_placeholder).to eq MISSING_NUMERIC_PLACEHOLDER
1019-
expect(schema.type_named("JsonSafeLong").grouping_missing_value_placeholder).to eq MISSING_NUMERIC_PLACEHOLDER
10201015
end
10211016

10221017
it "returns nil for object types" do

elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class GraphQL
1616
define_schema do |schema|
1717
schema.scalar_type "_FieldSet" do |t|
1818
t.mapping type: "keyword"
19-
t.json_schema type: "string"
2019
end
2120

2221
schema.object_type "Widget" do |t|

elasticgraph-indexer/spec/support/multiple_version_support.rb

Lines changed: 7 additions & 1 deletion
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/spec_support/schema_definition_helpers"
1011

1112
module ElasticGraph
@@ -15,7 +16,12 @@ class Indexer
1516

1617
def build_indexer_with_multiple_schema_versions(schema_versions:)
1718
results_by_version = schema_versions.to_h do |json_schema_version, prior_def|
18-
results = define_schema(schema_element_name_form: :snake_case, json_schema_version: json_schema_version, &prior_def)
19+
results = define_schema(
20+
schema_element_name_form: :snake_case,
21+
json_schema_version: json_schema_version,
22+
extension_modules: [JSONIngestion::SchemaDefinition::APIExtension],
23+
&prior_def
24+
)
1925
[json_schema_version, results]
2026
end
2127

0 commit comments

Comments
 (0)