Skip to content

Commit 9f3769c

Browse files
authored
Add indexer_extension_modules to runtime metadata (#1298)
## Why To support ingestion in any data format while keeping format-specific logic in its own gem (`elasticgraph-json_ingestion`, the upcoming `elasticgraph-proto_ingestion`), the indexer needs an extension mechanism analogous to the GraphQL one: schema definition extensions register runtime extensions in the schema artifacts, and the runtime component applies them at boot. This PR adds the runtime metadata storage for that. ## What - Add `indexer_extension_modules` to `RuntimeMetadata::Schema`, mirroring `graphql_extension_modules` - Add a `RuntimeMetadata::IndexerExtension` wrapper (twin of `GraphQLExtension`) - Nothing registers or consumes these yet, and empty lists are pruned from dumped YAML, so no schema artifacts change ## Verification - `script/lint`, `script/type_check` - `script/run_gem_specs elasticgraph-schema_artifacts` (100% coverage) - `script/run_gem_specs elasticgraph-schema_definition` - `bundle exec rake schema_artifacts:check` (no artifact changes) ## Stack Current PR is marked with `->`. - -> [#1298 Add indexer_extension_modules to runtime metadata](#1298) - [#1299 Add register_indexer_extension schema definition API](#1299) - [#1300 Apply indexer extension modules when the Indexer boots](#1300) - [#1301 Extract an ingestion adapter seam inside elasticgraph-indexer](#1301) - [#1302 Move JSON ingestion into elasticgraph-json_ingestion via an indexer extension](#1302)
1 parent 4cdc065 commit 9f3769c

12 files changed

Lines changed: 52 additions & 27 deletions

File tree

elasticgraph-schema_artifacts/lib/elastic_graph/schema_artifacts/runtime_metadata/graphql_extension.rb renamed to elasticgraph-schema_artifacts/lib/elastic_graph/schema_artifacts/runtime_metadata/component_extension.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ module ElasticGraph
1212
module SchemaArtifacts
1313
module RuntimeMetadata
1414
# @private
15-
class GraphQLExtension < ::Data.define(:extension_ref)
15+
class ComponentExtension < ::Data.define(:extension_ref)
1616
def self.loader
1717
@loader ||= ExtensionLoader.new(Module.new)
1818
end
1919

2020
EXTENSION_REF = "extension_ref"
2121

2222
def load_extension
23-
Extension.load_from_hash(extension_ref, via: GraphQLExtension.loader)
23+
Extension.load_from_hash(extension_ref, via: ComponentExtension.loader)
2424
end
2525

2626
def self.from_hash(hash)

elasticgraph-schema_artifacts/lib/elastic_graph/schema_artifacts/runtime_metadata/schema.rb

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

99
require "elastic_graph/constants"
10+
require "elastic_graph/schema_artifacts/runtime_metadata/component_extension"
1011
require "elastic_graph/schema_artifacts/runtime_metadata/enum"
1112
require "elastic_graph/schema_artifacts/runtime_metadata/extension"
1213
require "elastic_graph/schema_artifacts/runtime_metadata/extension_loader"
13-
require "elastic_graph/schema_artifacts/runtime_metadata/graphql_extension"
1414
require "elastic_graph/schema_artifacts/runtime_metadata/graphql_resolver"
1515
require "elastic_graph/schema_artifacts/runtime_metadata/hash_dumper"
1616
require "elastic_graph/schema_artifacts/runtime_metadata/index_definition"
@@ -34,6 +34,7 @@ class Schema < ::Data.define(
3434
:schema_element_names,
3535
:graphql_extension_modules,
3636
:graphql_resolvers_by_name,
37+
:indexer_extension_modules,
3738
:static_script_ids_by_scoped_name
3839
)
3940
# @private
@@ -53,6 +54,8 @@ class Schema < ::Data.define(
5354
# @private
5455
GRAPHQL_RESOLVERS_BY_NAME = "graphql_resolvers_by_name"
5556
# @private
57+
INDEXER_EXTENSION_MODULES = "indexer_extension_modules"
58+
# @private
5659
STATIC_SCRIPT_IDS_BY_NAME = "static_script_ids_by_scoped_name"
5760

5861
# Loads a {RuntimeMetadata::Schema} from the given hash.
@@ -90,13 +93,18 @@ def self.from_hash(hash)
9093

9194
graphql_extension_modules =
9295
hash[GRAPHQL_EXTENSION_MODULES]&.map do |ext_mod_hash|
93-
GraphQLExtension.from_hash(ext_mod_hash)
96+
ComponentExtension.from_hash(ext_mod_hash)
9497
end || []
9598

9699
graphql_resolvers_by_name = hash[GRAPHQL_RESOLVERS_BY_NAME]&.to_h do |name, resolver_hash|
97100
[name.to_sym, GraphQLResolver.from_hash(resolver_hash)]
98101
end || {}
99102

103+
indexer_extension_modules =
104+
hash[INDEXER_EXTENSION_MODULES]&.map do |ext_mod_hash|
105+
ComponentExtension.from_hash(ext_mod_hash)
106+
end || []
107+
100108
static_script_ids_by_scoped_name = hash[STATIC_SCRIPT_IDS_BY_NAME] || {}
101109

102110
new(
@@ -108,6 +116,7 @@ def self.from_hash(hash)
108116
schema_element_names: schema_element_names,
109117
graphql_extension_modules: graphql_extension_modules,
110118
graphql_resolvers_by_name: graphql_resolvers_by_name,
119+
indexer_extension_modules: indexer_extension_modules,
111120
static_script_ids_by_scoped_name: static_script_ids_by_scoped_name
112121
)
113122
end
@@ -123,6 +132,7 @@ def to_dumpable_hash
123132
GRAPHQL_EXTENSION_MODULES => graphql_extension_modules.map(&:to_dumpable_hash),
124133
GRAPHQL_RESOLVERS_BY_NAME => HashDumper.dump_hash(graphql_resolvers_by_name.transform_keys(&:to_s), &:to_dumpable_hash),
125134
INDEX_DEFINITIONS_BY_NAME => HashDumper.dump_hash(index_definitions_by_name, &:to_dumpable_hash),
135+
INDEXER_EXTENSION_MODULES => indexer_extension_modules.map(&:to_dumpable_hash),
126136
OBJECT_TYPES_BY_NAME => HashDumper.dump_hash(object_types_by_name, &:to_dumpable_hash),
127137
SCALAR_TYPES_BY_NAME => HashDumper.dump_hash(scalar_types_by_name, &:to_dumpable_hash),
128138
SCHEMA_ELEMENT_NAMES => schema_element_names.to_dumpable_hash,

elasticgraph-schema_artifacts/sig/elastic_graph/schema_artifacts/runtime_metadata/graphql_extension.rbs renamed to elasticgraph-schema_artifacts/sig/elastic_graph/schema_artifacts/runtime_metadata/component_extension.rbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ElasticGraph
22
module SchemaArtifacts
33
module RuntimeMetadata
4-
class GraphQLExtensionSupertype
4+
class ComponentExtensionSupertype
55
attr_reader extension_ref: ::Hash[::String, ::String]
66

77
def initialize: (
@@ -17,14 +17,14 @@ module ElasticGraph
1717
| (::Hash[::String, ::String]) -> instance
1818
end
1919

20-
class GraphQLExtension < GraphQLExtensionSupertype
20+
class ComponentExtension < ComponentExtensionSupertype
2121
self.@loader: ExtensionLoader?
2222
def self.loader: () -> ExtensionLoader
2323

2424
EXTENSION_REF: "extension_ref"
2525

2626
def load_extension: () -> Extension
27-
def self.from_hash: (::Hash[::String, untyped]) -> GraphQLExtension
27+
def self.from_hash: (::Hash[::String, untyped]) -> ComponentExtension
2828
def to_dumpable_hash: () -> ::Hash[::String, untyped]
2929
end
3030
end

elasticgraph-schema_artifacts/sig/elastic_graph/schema_artifacts/runtime_metadata/schema.rbs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ module ElasticGraph
88
attr_reader enum_types_by_name: ::Hash[::String, Enum::Type]
99
attr_reader index_definitions_by_name: ::Hash[::String, IndexDefinition]
1010
attr_reader schema_element_names: SchemaElementNames
11-
attr_reader graphql_extension_modules: ::Array[GraphQLExtension]
11+
attr_reader graphql_extension_modules: ::Array[ComponentExtension]
1212
attr_reader graphql_resolvers_by_name: ::Hash[::Symbol, GraphQLResolver]
13+
attr_reader indexer_extension_modules: ::Array[ComponentExtension]
1314
attr_reader static_script_ids_by_scoped_name: ::Hash[::String, ::String]
1415

1516
def initialize: (
@@ -19,8 +20,9 @@ module ElasticGraph
1920
enum_types_by_name: ::Hash[::String, Enum::Type],
2021
index_definitions_by_name: ::Hash[::String, IndexDefinition],
2122
schema_element_names: SchemaElementNames,
22-
graphql_extension_modules: ::Array[GraphQLExtension],
23+
graphql_extension_modules: ::Array[ComponentExtension],
2324
graphql_resolvers_by_name: ::Hash[::Symbol, GraphQLResolver],
25+
indexer_extension_modules: ::Array[ComponentExtension],
2426
static_script_ids_by_scoped_name: ::Hash[::String, ::String]) -> void
2527

2628
def with: (
@@ -30,8 +32,9 @@ module ElasticGraph
3032
?enum_types_by_name: ::Hash[::String, Enum::Type],
3133
?index_definitions_by_name: ::Hash[::String, IndexDefinition],
3234
?schema_element_names: SchemaElementNames,
33-
?graphql_extension_modules: ::Array[GraphQLExtension],
35+
?graphql_extension_modules: ::Array[ComponentExtension],
3436
?graphql_resolvers_by_name: ::Hash[::Symbol, GraphQLResolver],
37+
?indexer_extension_modules: ::Array[ComponentExtension],
3538
?static_script_ids_by_scoped_name: ::Hash[::String, ::String]) -> Schema
3639
end
3740

@@ -44,6 +47,7 @@ module ElasticGraph
4447
SCHEMA_ELEMENT_NAMES: "schema_element_names"
4548
GRAPHQL_EXTENSION_MODULES: "graphql_extension_modules"
4649
GRAPHQL_RESOLVERS_BY_NAME: "graphql_resolvers_by_name"
50+
INDEXER_EXTENSION_MODULES: "indexer_extension_modules"
4751
STATIC_SCRIPT_IDS_BY_NAME: "static_script_ids_by_scoped_name"
4852

4953
def self.from_hash: (::Hash[::String, untyped]) -> Schema

elasticgraph-schema_artifacts/spec/support/example_extensions/graphql_extension_modules.rb renamed to elasticgraph-schema_artifacts/spec/support/example_extensions/component_extension_modules.rb

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

99
module ElasticGraph
1010
module SchemaArtifacts
11-
module GraphQLExtensionModule1
11+
module ComponentExtensionModule1
1212
end
1313
end
1414
end

elasticgraph-schema_artifacts/spec/unit/elastic_graph/schema_artifacts/runtime_metadata/graphql_extension_spec.rb renamed to elasticgraph-schema_artifacts/spec/unit/elastic_graph/schema_artifacts/runtime_metadata/component_extension_spec.rb

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

9-
require "elastic_graph/schema_artifacts/runtime_metadata/graphql_extension"
9+
require "elastic_graph/schema_artifacts/runtime_metadata/component_extension"
1010

1111
module ElasticGraph
1212
module SchemaArtifacts
1313
module RuntimeMetadata
14-
RSpec.describe GraphQLExtension do
14+
RSpec.describe ComponentExtension do
1515
it "loads extension lazily" do
16-
graphql_extension = GraphQLExtension.new(
16+
component_extension = ComponentExtension.new(
1717
extension_ref: {
1818
"name" => "ElasticGraph::Extensions::Valid",
1919
"require_path" => "support/example_extensions/valid"
2020
}
2121
)
2222

23-
extension = graphql_extension.load_extension
23+
extension = component_extension.load_extension
2424

2525
expect(extension).to be_a(RuntimeMetadata::Extension)
2626
expect(extension.extension_class).to be_a(::Module).and have_attributes(name: "ElasticGraph::Extensions::Valid")

elasticgraph-schema_artifacts/spec/unit/elastic_graph/schema_artifacts/runtime_metadata/schema_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
require "elastic_graph/schema_artifacts/runtime_metadata/schema"
1616
require "elastic_graph/spec_support/runtime_metadata_support"
1717
require "elastic_graph/spec_support/example_extensions/graphql_resolvers"
18-
require "support/example_extensions/graphql_extension_modules"
18+
require "support/example_extensions/component_extension_modules"
1919
require "support/example_extensions/indexing_preparers"
2020
require "support/example_extensions/scalar_coercion_adapters"
2121
require "yaml"
@@ -158,13 +158,14 @@ module RuntimeMetadata
158158
form: :snake_case,
159159
overrides: {"any_of" => "or"}
160160
),
161-
graphql_extension_modules: [graphql_extension_module1],
161+
graphql_extension_modules: [component_extension_module1],
162162
graphql_resolvers_by_name: {
163163
resolver1: graphql_resolver_with(
164164
needs_lookahead: true,
165165
resolver_ref: graphql_resolver_with_lookahead(limit: 10).to_dumpable_hash
166166
)
167167
},
168+
indexer_extension_modules: [component_extension_module1],
168169
static_script_ids_by_scoped_name: {
169170
"filter/time_of_day" => "time_of_day_4474b200b6a00f385ed49f7c9669cbf3"
170171
}
@@ -302,8 +303,8 @@ module RuntimeMetadata
302303
},
303304
"graphql_extension_modules" => [{
304305
"extension_ref" => {
305-
"name" => "ElasticGraph::SchemaArtifacts::GraphQLExtensionModule1",
306-
"require_path" => "support/example_extensions/graphql_extension_modules"
306+
"name" => "ElasticGraph::SchemaArtifacts::ComponentExtensionModule1",
307+
"require_path" => "support/example_extensions/component_extension_modules"
307308
}
308309
}],
309310
"graphql_resolvers_by_name" => {
@@ -316,6 +317,12 @@ module RuntimeMetadata
316317
}
317318
}
318319
},
320+
"indexer_extension_modules" => [{
321+
"extension_ref" => {
322+
"name" => "ElasticGraph::SchemaArtifacts::ComponentExtensionModule1",
323+
"require_path" => "support/example_extensions/component_extension_modules"
324+
}
325+
}],
319326
"static_script_ids_by_scoped_name" => {
320327
"filter/time_of_day" => "time_of_day_4474b200b6a00f385ed49f7c9669cbf3"
321328
}
@@ -387,6 +394,7 @@ module RuntimeMetadata
387394
schema_element_names: SchemaElementNames.from_hash({"form" => "camelCase"}),
388395
graphql_extension_modules: [],
389396
graphql_resolvers_by_name: {},
397+
indexer_extension_modules: [],
390398
static_script_ids_by_scoped_name: {}
391399
)
392400
end

elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def deleted_type(name)
344344
# end
345345
def register_graphql_extension(extension_module, defined_at:, **config)
346346
extension = SchemaArtifacts::RuntimeMetadata::Extension.new(extension_module, defined_at, config)
347-
@state.graphql_extension_modules << SchemaArtifacts::RuntimeMetadata::GraphQLExtension.new(extension.to_dumpable_hash)
347+
@state.graphql_extension_modules << SchemaArtifacts::RuntimeMetadata::ComponentExtension.new(extension.to_dumpable_hash)
348348
nil
349349
end
350350

elasticgraph-schema_definition/lib/elastic_graph/schema_definition/results.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def build_runtime_metadata
125125
schema_element_names: state.schema_elements,
126126
graphql_extension_modules: state.graphql_extension_modules,
127127
graphql_resolvers_by_name: state.graphql_resolvers_by_name,
128+
indexer_extension_modules: [],
128129
static_script_ids_by_scoped_name: STATIC_SCRIPT_REPO.script_ids_by_scoped_name
129130
).tap { |rm| verify_runtime_metadata(rm) }
130131
end

elasticgraph-schema_definition/sig/elastic_graph/schema_definition/state.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module ElasticGraph
1515
attr_reader paginated_collection_element_types: ::Set[::String]
1616
attr_reader user_defined_fields: ::Set[SchemaElements::Field]
1717
attr_reader reserved_type_names: ::Set[::String]
18-
attr_reader graphql_extension_modules: ::Array[SchemaArtifacts::RuntimeMetadata::GraphQLExtension]
18+
attr_reader graphql_extension_modules: ::Array[SchemaArtifacts::RuntimeMetadata::ComponentExtension]
1919
attr_reader graphql_resolvers_by_name: ::Hash[::Symbol, SchemaArtifacts::RuntimeMetadata::GraphQLResolver]
2020
attr_reader built_in_graphql_resolvers: ::Set[::Symbol]
2121
attr_accessor initially_registered_built_in_types: ::Set[::String]
@@ -48,7 +48,7 @@ module ElasticGraph
4848
paginated_collection_element_types: ::Set[::String],
4949
user_defined_fields: ::Set[SchemaElements::Field],
5050
reserved_type_names: ::Set[::String],
51-
graphql_extension_modules: ::Array[SchemaArtifacts::RuntimeMetadata::GraphQLExtension],
51+
graphql_extension_modules: ::Array[SchemaArtifacts::RuntimeMetadata::ComponentExtension],
5252
graphql_resolvers_by_name: ::Hash[::Symbol, SchemaArtifacts::RuntimeMetadata::GraphQLResolver],
5353
built_in_graphql_resolvers: ::Set[::Symbol],
5454
initially_registered_built_in_types: ::Set[::String],

0 commit comments

Comments
 (0)