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

Instance Method Details

#abstract?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 47

def abstract?
  true
end

#current_sourcesObject



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_nameObject



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

Returns:

  • (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_indexObject



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_subtypesObject



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_typeObject



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