Class: ElasticGraph::GraphQL::Filtering::FilterArgsTranslator
- Inherits:
-
Object
- Object
- ElasticGraph::GraphQL::Filtering::FilterArgsTranslator
- Defined in:
- lib/elastic_graph/graphql/filtering/filter_args_translator.rb
Overview
Responsible for translating a ‘filter` expression from GraphQL field names to the internal `name_in_index` of each field. This is necessary so that when a field is defined with an alternate `name_in_index`, the query against the index uses that name even while the name in the GraphQL schema is different.
In addition, we translate the enum value names to enum value objects, so that any runtime metadata associated with that enum value is available to our ‘FilterInterpreter`.
Instance Method Summary collapse
-
#initialize(schema_element_names:) ⇒ FilterArgsTranslator
constructor
A new instance of FilterArgsTranslator.
-
#translate_filter_args(field:, args:) ⇒ Object
Translates the ‘filter` expression from the given `args` and `field` into their equivalent form using the `name_in_index` for any fields that are named differently in the index vs GraphQL.
Constructor Details
#initialize(schema_element_names:) ⇒ FilterArgsTranslator
Returns a new instance of FilterArgsTranslator.
20 21 22 |
# File 'lib/elastic_graph/graphql/filtering/filter_args_translator.rb', line 20 def initialize(schema_element_names:) super(filter_arg_name: schema_element_names.filter) end |
Instance Method Details
#translate_filter_args(field:, args:) ⇒ Object
Translates the ‘filter` expression from the given `args` and `field` into their equivalent form using the `name_in_index` for any fields that are named differently in the index vs GraphQL.
27 28 29 30 31 |
# File 'lib/elastic_graph/graphql/filtering/filter_args_translator.rb', line 27 def translate_filter_args(field:, args:) return nil unless (filter_hash = args[filter_arg_name]) filter_type = field.schema.type_from(field.graphql_field.arguments[filter_arg_name].type) convert(filter_type, filter_hash) end |