graphiti-api / graphiti

Stylish Graph APIs
https://www.graphiti.dev/
MIT License
958 stars 138 forks source link

howto invoke filter_string_match() function etc. #285

Open openxyz opened 3 years ago

openxyz commented 3 years ago

Graphiti::Adapters::ActiveRecord has some great function such as filter_string_match() etc.
but howto invoke it ?, for example:

filter  :some_field do
  match do | scope ,value |
     filter_string_match(...)  #  can`t work 
    #  my workround  it ugly :  Graphiti::Adapters::ActiveRecord.new self
  end 
end
wadetandy commented 3 years ago

These are by default what gets called under the hood when you have an attribute filtered by the specified operator:

class PostResource < ApplicationResource
  attribute :title, :string, filterable: true
end

# https://myapi.com/v1/posts?filter[title][prefix]=hello

That will call filter_string_prefix when it resolves. These are all available on the resource's adapter though, so if you need to invoke them directly for some reason, you should be able to do it:

filter  :some_field do
  match do | scope ,value |
    self.adapter.filter_string_match(value)
  end 
end