Module: ElasticGraph::SchemaDefinition::Mixins::HasSubtypes
- Included in:
- SchemaElements::InterfaceType, SchemaElements::UnionType
- Defined in:
- lib/elastic_graph/schema_definition/mixins/has_subtypes.rb
Overview
Provides common support for abstract GraphQL types that have subtypes (e.g. union and interface types).
Instance Method Summary collapse
- #abstract? ⇒ Boolean
- #current_sources ⇒ Object
- #graphql_fields_by_name ⇒ Object
- #index_field_runtime_metadata_tuples(path_prefix: "", parent_source: SELF_RELATIONSHIP_NAME, list_counts_state: SchemaElements::ListCountsState::INITIAL) ⇒ Object
- #indexed? ⇒ Boolean
- #indexing_fields_by_name_in_index ⇒ Object
- #recursively_resolve_subtypes ⇒ Object
- #to_indexing_field_type ⇒ Object
Instance Method Details
#abstract? ⇒ Boolean
47 48 49 |
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 47 def abstract? true end |
#current_sources ⇒ Object
51 52 53 |
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 51 def current_sources resolve_subtypes.flat_map(&:current_sources) end |
#graphql_fields_by_name ⇒ Object
28 29 30 |
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 28 def graphql_fields_by_name merge_fields_by_name_from_subtypes(&:graphql_fields_by_name) end |
#index_field_runtime_metadata_tuples(path_prefix: "", parent_source: SELF_RELATIONSHIP_NAME, list_counts_state: SchemaElements::ListCountsState::INITIAL) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 55 def ( path_prefix: "", parent_source: SELF_RELATIONSHIP_NAME, list_counts_state: SchemaElements::ListCountsState::INITIAL ) resolve_subtypes.flat_map do |t| t.( path_prefix: path_prefix, parent_source: parent_source, list_counts_state: list_counts_state ) end end |
#indexed? ⇒ Boolean
37 38 39 |
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 37 def indexed? super || subtypes_indexed? end |
#indexing_fields_by_name_in_index ⇒ Object
32 33 34 35 |
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 32 def indexing_fields_by_name_in_index merge_fields_by_name_from_subtypes(&:indexing_fields_by_name_in_index) .merge("__typename" => schema_def_state.factory.new_field(name: "__typename", type: "String", parent_type: _ = self)) end |
#recursively_resolve_subtypes ⇒ Object
41 42 43 44 45 |
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 41 def recursively_resolve_subtypes resolve_subtypes.flat_map do |type| type.is_a?(HasSubtypes) ? (_ = type).recursively_resolve_subtypes : [type] end end |
#to_indexing_field_type ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 20 def to_indexing_field_type subtypes_by_name = recursively_resolve_subtypes.to_h do |type| [type.name, _ = type.to_indexing_field_type] end Indexing::FieldType::Union.new(subtypes_by_name) end |