Class: ElasticGraph::SchemaArtifacts::RuntimeMetadata::ScalarType
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaArtifacts::RuntimeMetadata::ScalarType
- Defined in:
- lib/elastic_graph/schema_artifacts/runtime_metadata/scalar_type.rb
Overview
Provides runtime metadata related to scalar types.
Constant Summary collapse
- DEFAULT_COERCION_ADAPTER_REF =
{ "name" => "ElasticGraph::GraphQL::ScalarCoercionAdapters::NoOp", "require_path" => "elastic_graph/graphql/scalar_coercion_adapters/no_op" }
- DEFAULT_INDEXING_PREPARER_REF =
{ "name" => "ElasticGraph::Indexer::IndexingPreparers::NoOp", "require_path" => "elastic_graph/indexer/indexing_preparers/no_op" }
Class Method Summary collapse
- .coercion_adapter_extension_loader ⇒ Object
- .indexing_preparer_extension_loader ⇒ Object
-
.load_many(scalar_type_hashes_by_name) ⇒ Object
Loads multiple ‘ScalarType`s from a hash mapping a scalar type name to its serialized hash form (matching what `to_dumpable_hash` returns).
Instance Method Summary collapse
-
#load_coercion_adapter ⇒ Object
Loads the coercion adapter.
- #load_indexing_preparer ⇒ Object
- #to_dumpable_hash ⇒ Object
Class Method Details
.coercion_adapter_extension_loader ⇒ Object
18 19 20 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/scalar_type.rb', line 18 def self.coercion_adapter_extension_loader @coercion_adapter_extension_loader ||= ExtensionLoader.new(ScalarCoercionAdapterInterface) end |
.indexing_preparer_extension_loader ⇒ Object
22 23 24 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/scalar_type.rb', line 22 def self.indexing_preparer_extension_loader @indexing_preparer_extension_loader ||= ExtensionLoader.new(ScalarIndexingPreparerInterface) end |
.load_many(scalar_type_hashes_by_name) ⇒ Object
Loads multiple ‘ScalarType`s from a hash mapping a scalar type name to its serialized hash form (matching what `to_dumpable_hash` returns). We expose a method this way because we want to use a single loader for all `ScalarType`s that need to get loaded, as it performs some caching for efficiency.
40 41 42 43 44 45 46 47 48 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/scalar_type.rb', line 40 def self.load_many(scalar_type_hashes_by_name) scalar_type_hashes_by_name.transform_values do |hash| new( coercion_adapter_ref: hash.fetch("coercion_adapter"), indexing_preparer_ref: hash.fetch("indexing_preparer", DEFAULT_INDEXING_PREPARER_REF), grouping_missing_value_placeholder: hash["grouping_missing_value_placeholder"] ) end end |
Instance Method Details
#load_coercion_adapter ⇒ Object
Loads the coercion adapter. This is done lazily on first access (rather than eagerly in ‘load_many`) to allow us to remove a runtime dependency of `elasticgraph-schema_artifacts` on `elasticgraph-graphql`. The built-in coercion adapters are defined in `elasticgraph-graphql`, and we want to be able to load runtime metadata without requiring the `elasticgraph-graphql` gem (and its dependencies) to be available. For example, we use runtime metadata from `elasticgraph-indexer` but do not want `elasticgraph-graphql` to be loaded as part of that.
elasticgraph-graphql provides the one caller that calls this method, ensuring that the adapters are available to be loaded.
59 60 61 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/scalar_type.rb', line 59 def load_coercion_adapter Extension.load_from_hash(coercion_adapter_ref, via: self.class.coercion_adapter_extension_loader) end |
#load_indexing_preparer ⇒ Object
63 64 65 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/scalar_type.rb', line 63 def load_indexing_preparer Extension.load_from_hash(indexing_preparer_ref, via: self.class.indexing_preparer_extension_loader) end |
#to_dumpable_hash ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/scalar_type.rb', line 67 def to_dumpable_hash { # Keys here are ordered alphabetically; please keep them that way. "coercion_adapter" => load_coercion_adapter.to_dumpable_hash, "grouping_missing_value_placeholder" => grouping_missing_value_placeholder, "indexing_preparer" => load_indexing_preparer.to_dumpable_hash } end |