Module: GraphitiGql::FilterExtras

Defined in:
lib/graphiti_gql/graphiti_hax.rb

Instance Method Summary collapse

Instance Method Details

#each_filterObject



213
214
215
216
217
218
219
220
221
# File 'lib/graphiti_gql/graphiti_hax.rb', line 213

def each_filter
  super do |filter, operator, value|
    unless filter.values[0][:allow_nil]
      has_nil = value.nil? || value.is_a?(Array) && value.any?(&:nil?)
      raise Errors::NullFilter.new(filter.keys.first) if has_nil
    end
    yield filter, operator, value
  end
end

#filter_paramObject



207
208
209
210
211
# File 'lib/graphiti_gql/graphiti_hax.rb', line 207

def filter_param
  default_filter = resource.default_filter if resource.respond_to?(:default_filter)
  default_filter ||= {}
  default_filter.merge(super)
end

#filter_via_adapter(filter, operator, value) ⇒ Object

Only for alias, tiny diff



224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/graphiti_gql/graphiti_hax.rb', line 224

def filter_via_adapter(filter, operator, value)
  type_name = ::Graphiti::Types.name_for(filter.values.first[:type])
  method = :"filter_#{type_name}_#{operator}"
  name = filter.keys.first
  name = resource.all_attributes[name][:alias] || name

  if resource.adapter.respond_to?(method)
    resource.adapter.send(method, @scope, name, value)
  else
    raise ::Graphiti::Errors::AdapterNotImplemented.new \
      resource.adapter, name, method
  end
end