Class: ElasticGraph::SchemaArtifacts::RuntimeMetadata::Schema
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaArtifacts::RuntimeMetadata::Schema
- Defined in:
- elasticgraph-schema_artifacts/lib/elastic_graph/schema_artifacts/runtime_metadata/schema.rb
Overview
Entry point for runtime metadata for an entire schema.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Schema
Loads a Schema from the given hash.
Instance Method Summary collapse
-
#to_dumpable_hash ⇒ Hash<String, Hash<String, Object>>
Converts to a hash that is suitable for dumping to disk as YAML.
Class Method Details
.from_hash(hash) ⇒ Schema
Loads a ElasticGraph::SchemaArtifacts::RuntimeMetadata::Schema from the given hash.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'elasticgraph-schema_artifacts/lib/elastic_graph/schema_artifacts/runtime_metadata/schema.rb', line 65 def self.from_hash(hash) elasticgraph_version = hash.fetch(ELASTICGRAPH_VERSION) do raise Errors::SchemaError, "`#{RUNTIME_METADATA_FILE}` is missing `#{ELASTICGRAPH_VERSION}`. To proceed, regenerate the schema artifacts." end if elasticgraph_version != ElasticGraph::VERSION raise Errors::SchemaError, <<~EOS ElasticGraph version mismatch: schema artifacts were dumped by version #{elasticgraph_version}, but current version is #{ElasticGraph::VERSION}. To proceed, regenerate the schema artifacts using ElasticGraph v#{ElasticGraph::VERSION} or boot with these artifacts using ElasticGraph v#{elasticgraph_version}. EOS end object_types_by_name = hash[OBJECT_TYPES_BY_NAME]&.transform_values do |type_hash| ObjectType.from_hash(type_hash) end || {} scalar_types_by_name = hash[SCALAR_TYPES_BY_NAME]&.then do |subhash| ScalarType.load_many(subhash) end || {} enum_types_by_name = hash[ENUM_TYPES_BY_NAME]&.transform_values do |type_hash| Enum::Type.from_hash(type_hash) end || {} index_definitions_by_name = hash[INDEX_DEFINITIONS_BY_NAME]&.transform_values do |index_hash| IndexDefinition.from_hash(index_hash) end || {} schema_element_names = SchemaElementNames.from_hash(hash.fetch(SCHEMA_ELEMENT_NAMES)) graphql_extension_modules = hash[GRAPHQL_EXTENSION_MODULES]&.map do |ext_mod_hash| ComponentExtension.from_hash(ext_mod_hash) end || [] graphql_resolvers_by_name = hash[GRAPHQL_RESOLVERS_BY_NAME]&.to_h do |name, resolver_hash| [name.to_sym, GraphQLResolver.from_hash(resolver_hash)] end || {} indexer_extension_modules = hash[INDEXER_EXTENSION_MODULES]&.map do |ext_mod_hash| ComponentExtension.from_hash(ext_mod_hash) end || [] static_script_ids_by_scoped_name = hash[STATIC_SCRIPT_IDS_BY_NAME] || {} new( elasticgraph_version: elasticgraph_version, object_types_by_name: object_types_by_name, scalar_types_by_name: scalar_types_by_name, enum_types_by_name: enum_types_by_name, index_definitions_by_name: index_definitions_by_name, schema_element_names: schema_element_names, graphql_extension_modules: graphql_extension_modules, graphql_resolvers_by_name: graphql_resolvers_by_name, indexer_extension_modules: indexer_extension_modules, static_script_ids_by_scoped_name: static_script_ids_by_scoped_name ) end |
Instance Method Details
#to_dumpable_hash ⇒ Hash<String, Hash<String, Object>>
Converts to a hash that is suitable for dumping to disk as YAML.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'elasticgraph-schema_artifacts/lib/elastic_graph/schema_artifacts/runtime_metadata/schema.rb', line 127 def to_dumpable_hash Support::HashUtil.recursively_prune_nils_and_empties_from({ # Keys here are ordered alphabetically; please keep them that way. ELASTICGRAPH_VERSION => elasticgraph_version, ENUM_TYPES_BY_NAME => HashDumper.dump_hash(enum_types_by_name, &:to_dumpable_hash), GRAPHQL_EXTENSION_MODULES => graphql_extension_modules.map(&:to_dumpable_hash), GRAPHQL_RESOLVERS_BY_NAME => HashDumper.dump_hash(graphql_resolvers_by_name.transform_keys(&:to_s), &:to_dumpable_hash), INDEX_DEFINITIONS_BY_NAME => HashDumper.dump_hash(index_definitions_by_name, &:to_dumpable_hash), INDEXER_EXTENSION_MODULES => indexer_extension_modules.map(&:to_dumpable_hash), OBJECT_TYPES_BY_NAME => HashDumper.dump_hash(object_types_by_name, &:to_dumpable_hash), SCALAR_TYPES_BY_NAME => HashDumper.dump_hash(scalar_types_by_name, &:to_dumpable_hash), SCHEMA_ELEMENT_NAMES => schema_element_names.to_dumpable_hash, STATIC_SCRIPT_IDS_BY_NAME => static_script_ids_by_scoped_name }) end |