Module: ElasticGraph::SchemaDefinition::Mixins::SupportsFilteringAndAggregation

Included in:
SchemaElements::InterfaceType, SchemaElements::ObjectType, SchemaElements::UnionType
Defined in:
lib/elastic_graph/schema_definition/mixins/supports_filtering_and_aggregation.rb

Overview

Responsible for building object types for filtering and aggregation, from an existing object type.

This is specifically designed to support SchemaElements::TypeWithSubfields (where we have the fields directly available) and SchemaElements::UnionType (where we will need to compute the list of fields by resolving the subtypes and merging their fields).

Instance Method Summary collapse

Instance Method Details

#derived_graphql_typesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/elastic_graph/schema_definition/mixins/supports_filtering_and_aggregation.rb', line 33

def derived_graphql_types
  return [] if graphql_only?

  indexed_agg_type = to_indexed_aggregation_type
  indexed_aggregation_pagination_types =
    if indexed_agg_type
      schema_def_state.factory.build_relay_pagination_types(indexed_agg_type.name)
    else
      [] # : ::Array[SchemaElements::ObjectType]
    end

  sub_aggregation_types = sub_aggregation_types_for_nested_field_references.flat_map do |type|
    [type] + schema_def_state.factory.build_relay_pagination_types(type.name, support_pagination: false) do |t|
      # Record metadata that is necessary for elasticgraph-graphql to correctly recognize and handle
      # this sub-aggregation correctly.
      t.(elasticgraph_category: :nested_sub_aggregation_connection)
      t.resolve_fields_with :object_without_lookahead
    end
  end

  document_pagination_types =
    if indexed?
      schema_def_state.factory.build_relay_pagination_types(name, include_total_edge_count: true, derived_indexed_types: (_ = self).derived_indexed_types)
    elsif schema_def_state.paginated_collection_element_types.include?(name)
      schema_def_state.factory.build_relay_pagination_types(name, include_total_edge_count: true)
    else
      [] # : ::Array[SchemaElements::ObjectType]
    end

  sort_order_enum_type = schema_def_state.enums_for_indexed_types.sort_order_enum_for(self)
  derived_sort_order_enum_types = [sort_order_enum_type].compact + (sort_order_enum_type&.derived_graphql_types || [])

  to_input_filters +
    document_pagination_types +
    indexed_aggregation_pagination_types +
    sub_aggregation_types +
    derived_sort_order_enum_types +
    build_aggregation_sub_aggregations_types + [
      indexed_agg_type,
      to_grouped_by_type,
      to_aggregated_values_type,
      to_highlights_type
    ].compact
end

#does_not_support?(&feature_predicate) ⇒ Boolean

Inverse of ‘supports?`.

Returns:

  • (Boolean)


29
30
31
# File 'lib/elastic_graph/schema_definition/mixins/supports_filtering_and_aggregation.rb', line 29

def does_not_support?(&feature_predicate)
  !supports?(&feature_predicate)
end

#has_custom_mapping_type?Boolean

Returns:

  • (Boolean)


78
79
80
81
# File 'lib/elastic_graph/schema_definition/mixins/supports_filtering_and_aggregation.rb', line 78

def has_custom_mapping_type?
  mapping_type = mapping_options[:type]
  mapping_type && mapping_type != "object"
end

#supports?(&feature_predicate) ⇒ Boolean

Indicates if this type supports a given feature (e.g. ‘filterable?`).

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/elastic_graph/schema_definition/mixins/supports_filtering_and_aggregation.rb', line 20

def supports?(&feature_predicate)
  # If the type uses a custom mapping type we don't know if it can support a feature, so we assume it can't.
  # TODO: clean this up using an interface instead of checking mapping options.
  return false if has_custom_mapping_type?

  graphql_fields_by_name.values.any?(&feature_predicate)
end