Skip to content

Commit

Permalink
Merge pull request #54 from block/myron/use-filter-node-interpreter/s…
Browse files Browse the repository at this point in the history
…tep3

Make `FilterNodeInterpreter` available to `FilterValueSetExtractor`.
  • Loading branch information
myronmarston authored Dec 10, 2024
2 parents cdfe4c8 + 490a575 commit 5b28934
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 17 deletions.
7 changes: 4 additions & 3 deletions elasticgraph-graphql/lib/elastic_graph/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ def datastore_query_builder
@datastore_query_builder ||= begin
require "elastic_graph/graphql/datastore_query"
DatastoreQuery::Builder.with(
filter_interpreter: filter_interpreter,
runtime_metadata: runtime_metadata,
logger: logger,
filter_interpreter:,
filter_node_interpreter:,
runtime_metadata:,
logger:,
default_page_size: @config.default_page_size,
max_page_size: @config.max_page_size
)
Expand Down
16 changes: 11 additions & 5 deletions elasticgraph-graphql/lib/elastic_graph/graphql/datastore_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,23 @@ def source

# Encapsulates dependencies of `Query`, giving us something we can expose off of `application`
# to build queries when desired.
class Builder < Support::MemoizableData.define(:runtime_metadata, :logger, :query_defaults)
def self.with(runtime_metadata:, logger:, **query_defaults)
new(runtime_metadata: runtime_metadata, logger: logger, query_defaults: query_defaults)
class Builder < Support::MemoizableData.define(:runtime_metadata, :logger, :filter_node_interpreter, :query_defaults)
def self.with(runtime_metadata:, logger:, filter_node_interpreter:, **query_defaults)
new(runtime_metadata:, logger:, filter_node_interpreter:, query_defaults:)
end

def routing_picker
@routing_picker ||= RoutingPicker.new(schema_names: runtime_metadata.schema_element_names)
@routing_picker ||= RoutingPicker.new(
filter_node_interpreter: filter_node_interpreter,
schema_names: runtime_metadata.schema_element_names
)
end

def index_expression_builder
@index_expression_builder ||= IndexExpressionBuilder.new(schema_names: runtime_metadata.schema_element_names)
@index_expression_builder ||= IndexExpressionBuilder.new(
filter_node_interpreter: filter_node_interpreter,
schema_names: runtime_metadata.schema_element_names
)
end

def new_query(**options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ class GraphQL
class DatastoreQuery
# Responsible for building a search index expression for a specific query based on the filters.
class IndexExpressionBuilder
def initialize(schema_names:)
@filter_value_set_extractor = Filtering::FilterValueSetExtractor.new(schema_names, Support::TimeSet::ALL, Support::TimeSet::EMPTY) do |operator, filter_value|
def initialize(filter_node_interpreter:, schema_names:)
@filter_value_set_extractor = Filtering::FilterValueSetExtractor.new(
filter_node_interpreter,
schema_names,
Support::TimeSet::ALL,
Support::TimeSet::EMPTY
) do |operator, filter_value|
case operator
when :gt, :gte, :lt, :lte
if date_string?(filter_value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ class GraphQL
class DatastoreQuery
# Responsible for picking routing values for a specific query based on the filters.
class RoutingPicker
def initialize(schema_names:)
def initialize(filter_node_interpreter:, schema_names:)
all_values_set = RoutingValueSet::ALL
empty_set = RoutingValueSet::EMPTY

@filter_value_set_extractor = Filtering::FilterValueSetExtractor.new(schema_names, all_values_set, empty_set) do |operator, filter_value|
@filter_value_set_extractor = Filtering::FilterValueSetExtractor.new(
filter_node_interpreter,
schema_names,
all_values_set,
empty_set
) do |operator, filter_value|
if operator == :equal_to_any_of
# This calls `.compact` to remove `nil` filter_value values
RoutingValueSet.of(filter_value.compact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module Filtering
# Responsible for extracting a set of values from query filters, based on a using a custom
# set type that is able to efficiently model the "all values" case.
class FilterValueSetExtractor
def initialize(schema_names, all_values_set, empty_set, &build_set_for_filter)
def initialize(filter_node_interpreter, schema_names, all_values_set, empty_set, &build_set_for_filter)
@filter_node_interpreter = filter_node_interpreter
@schema_names = schema_names
@all_values_set = all_values_set
@empty_set = empty_set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ def can_match_nil_values_at?(path, filter)

def filter_value_set_extractor
@filter_value_set_extractor ||=
Filtering::FilterValueSetExtractor.new(schema_element_names, IncludesNilSet, ExcludesNilSet) do |operator, filter_value|
Filtering::FilterValueSetExtractor.new(
filter_node_interpreter,
schema_element_names,
IncludesNilSet,
ExcludesNilSet
) do |operator, filter_value|
if operator == :equal_to_any_of && filter_value.include?(nil)
IncludesNilSet
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module ElasticGraph
class GraphQL
class DatastoreQuery
class IndexExpressionBuilder
def initialize: (schema_names: SchemaArtifacts::RuntimeMetadata::SchemaElementNames) -> void
def initialize: (
filter_node_interpreter: Filtering::FilterNodeInterpreter,
schema_names: SchemaArtifacts::RuntimeMetadata::SchemaElementNames,
) -> void

def determine_search_index_expression: (
::Array[::Hash[::String, untyped]],
::Array[DatastoreCore::_IndexDefinition],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module ElasticGraph
class GraphQL
class DatastoreQuery
class RoutingPicker
def initialize: (schema_names: SchemaArtifacts::RuntimeMetadata::SchemaElementNames) -> void
def initialize: (
filter_node_interpreter: Filtering::FilterNodeInterpreter,
schema_names: SchemaArtifacts::RuntimeMetadata::SchemaElementNames
) -> void

def extract_eligible_routing_values: (
::Array[::Hash[::String, untyped]],
::Array[::String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ module ElasticGraph
class FilterValueSetExtractor[S < Support::_NegatableSet[S]]
type setType[out S] = S | singleton(UnboundedSetWithExclusions)

def initialize: (SchemaArtifacts::RuntimeMetadata::SchemaElementNames, setType[S], setType[S]) { (::Symbol, untyped) -> S? } -> void
def initialize: (
FilterNodeInterpreter,
SchemaArtifacts::RuntimeMetadata::SchemaElementNames,
setType[S],
setType[S]
) { (::Symbol, untyped) -> S? } -> void

def extract_filter_value_set: (::Array[::Hash[::String, untyped]], ::Array[::String]) -> S?

private

@filter_node_interpreter: FilterNodeInterpreter
@schema_names: SchemaArtifacts::RuntimeMetadata::SchemaElementNames
@all_values_set: setType[S]
@empty_set: setType[S]
Expand Down

0 comments on commit 5b28934

Please sign in to comment.