Closed jumichot closed 6 years ago
Hi,
You can use the scope
method from SearchObject
module Resolvers
class SiteSearch < Resolvers::ListBaseResolver
PaginatedSites = type do
#...
end
# you can use `context` and `object` instance variables here
# to find what scope you are needing
scope { Client.first.sites }
end
end
Thank you for your response. I know how to define scope this way but it's not dynamique. Is there a way to set the scope in my root query file where I specify the fields ?
I want to reuse my Resolvers::SiteSearch in different query fields with different scopes.
It's what I'm trying to do here but it's not working :
field :searchSites, Resolvers::SiteSearch::PaginatedSites do
resolve ->(obj, args, ctx) {
Resolvers::SiteSearch.new(scope: Client.first.sites)
}
end
Cheers,
I think, I get it. This is a bit tricky.
You can try something like the following:
module Resolvers
class ListBaseResolver < BaseSearchResolver
# ...
# This would build new search class for that particular scope
def self.with_scope(get_scope)
Class.new(self) do
scope do
# This adds support for dynamic and static scopes
if get_scope.respnd_to? :call
get_scope.call(object, filters, context)
else
get_scope
end
end
end
end
end
end
module Resolvers
class SiteSearch < Resolvers::ListBaseResolver
PaginatedSites = type do
#...
end
end
end
# You can call this dynamically or statically
field :searchSites, Resolvers::SiteSearch::PaginatedSites.with_scope(->(obj, args, ctx) { Client.first.sites })
field :searchSites, Resolvers::SiteSearch::PaginatedSites.with_scope(Client.first.sites)
Hi there,
I'm trying to build a reusable search with pagination. I followed the issue, I have a ListResolver :
An I'm using it in a search resolver :
In my query_type.rb file where I have my queries I tried to pass the scope :
But it's not working, I don't have access to pagination info, only the results key contain what I want.
What is the best way to change a resolver scope ?
If I put this in my query_type.rb file
It's working perfectly but I don't know how to pass a scope dynamically that way
Thanks for your help