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)


54
55
56
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 54

def abstract?
  true
end

#current_sourcesObject



58
59
60
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 58

def current_sources
  resolve_subtypes.flat_map(&:current_sources)
end

#directly_queryable?Boolean

An abstract type is queryable if all of its subtypes are root document types (via a direct or inherited index) even if those subtypes aren’t themselves directly queryable. This is why this doesn’t delegate to a subtypes_are_directly_queryable helper.

Returns:

  • (Boolean)


44
45
46
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 44

def directly_queryable?
  super || subtypes_are_root_document_types?
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



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 62

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

#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



48
49
50
51
52
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 48

def recursively_resolve_subtypes
  resolve_subtypes.flat_map do |type|
    type.is_a?(HasSubtypes) ? (_ = type).recursively_resolve_subtypes : [type]
  end
end

#root_document_type?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/elastic_graph/schema_definition/mixins/has_subtypes.rb', line 37

def root_document_type?
  super || subtypes_are_root_document_types?
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