Class: ElasticGraph::SchemaArtifacts::RuntimeMetadata::ObjectType
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaArtifacts::RuntimeMetadata::ObjectType
- Defined in:
- lib/elastic_graph/schema_artifacts/runtime_metadata/object_type.rb
Overview
Provides runtime metadata related to object types.
Constant Summary collapse
- UPDATE_TARGETS =
"update_targets"- INDEX_DEFINITION_NAMES =
"index_definition_names"- GRAPHQL_FIELDS_BY_NAME =
"graphql_fields_by_name"- ELASTICGRAPH_CATEGORY =
"elasticgraph_category"- SOURCE_TYPE =
"source_type"- GRAPHQL_ONLY_RETURN_TYPE =
"graphql_only_return_type"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(update_targets:, index_definition_names:, graphql_fields_by_name:, elasticgraph_category:, source_type:, graphql_only_return_type:) ⇒ ObjectType
constructor
A new instance of ObjectType.
- #to_dumpable_hash ⇒ Object
Constructor Details
#initialize(update_targets:, index_definition_names:, graphql_fields_by_name:, elasticgraph_category:, source_type:, graphql_only_return_type:) ⇒ ObjectType
Returns a new instance of ObjectType.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/object_type.rb', line 37 def initialize(update_targets:, index_definition_names:, graphql_fields_by_name:, elasticgraph_category:, source_type:, graphql_only_return_type:) graphql_fields_by_name = graphql_fields_by_name.select { |name, field| field.needed?(name) } super( update_targets: update_targets, index_definition_names: index_definition_names, graphql_fields_by_name: graphql_fields_by_name, elasticgraph_category: elasticgraph_category, source_type: source_type, graphql_only_return_type: graphql_only_return_type ) end |
Class Method Details
.from_hash(hash) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/object_type.rb', line 50 def self.from_hash(hash) update_targets = hash[UPDATE_TARGETS]&.map do |update_target_hash| UpdateTarget.from_hash(update_target_hash) end || [] graphql_fields_by_name = hash[GRAPHQL_FIELDS_BY_NAME]&.to_h do |name, field_hash| field_hash = field_hash.merge(GraphQLField::NAME_IN_INDEX => name) unless field_hash[GraphQLField::NAME_IN_INDEX] [name, GraphQLField.from_hash(field_hash)] end || {} new( update_targets: update_targets, index_definition_names: hash[INDEX_DEFINITION_NAMES] || [], graphql_fields_by_name: graphql_fields_by_name, elasticgraph_category: hash[ELASTICGRAPH_CATEGORY]&.to_sym || nil, source_type: hash[SOURCE_TYPE] || nil, graphql_only_return_type: !!hash[GRAPHQL_ONLY_RETURN_TYPE] ) end |
Instance Method Details
#to_dumpable_hash ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/object_type.rb', line 70 def to_dumpable_hash dumped_graphql_fields_by_name = HashDumper.dump_hash(graphql_fields_by_name.to_h do |name, field| field = field.with(name_in_index: nil) if field.name_in_index == name [name, field] end, &:to_dumpable_hash) { # Keys here are ordered alphabetically; please keep them that way. ELASTICGRAPH_CATEGORY => elasticgraph_category&.to_s, GRAPHQL_FIELDS_BY_NAME => dumped_graphql_fields_by_name, GRAPHQL_ONLY_RETURN_TYPE => graphql_only_return_type ? true : nil, INDEX_DEFINITION_NAMES => index_definition_names, SOURCE_TYPE => source_type, UPDATE_TARGETS => update_targets.map(&:to_dumpable_hash) } end |