Class: ElasticGraph::GraphQL::DatastoreQuery::IndexExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/graphql/datastore_query/index_expression_builder.rb

Constant Summary collapse

EMPTY =
new(names_to_include: ::Set.new, names_to_exclude: ::Set.new)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.only(name) ⇒ Object



115
116
117
# File 'lib/elastic_graph/graphql/datastore_query/index_expression_builder.rb', line 115

def self.only(name)
  IndexExpression.new(names_to_include: ::Set.new([name].compact), names_to_exclude: ::Set.new)
end

Instance Method Details

#+(other) ⇒ Object



126
127
128
129
130
131
# File 'lib/elastic_graph/graphql/datastore_query/index_expression_builder.rb', line 126

def +(other)
  with(
    names_to_include: names_to_include.union(other.names_to_include),
    names_to_exclude: names_to_exclude.union(other.names_to_exclude)
  )
end

#to_sObject



119
120
121
122
123
124
# File 'lib/elastic_graph/graphql/datastore_query/index_expression_builder.rb', line 119

def to_s
  # Note: exclusions must come after inclusions. I can't find anything in the Elasticsearch or OpenSearch docs
  # that mention this, but when exclusions come first I found that we got errors.
  parts = names_to_include.sort + names_to_exclude.sort.map { |name| "-#{name}" }
  parts.join(",")
end