Closed panbanda closed 6 years ago
Yes, you can 😀
Overwrite fetch_results
and plug there. I have done in How to GraphQL tutorial here.
You can create a module for that:
module WithQueryResolver
def fetch_results
# NOTE: Don't run QueryResolver during tests
return super unless context.present?
GraphQL::QueryResolver.run(Link, context, Types::LinkType) do
super
end
end
end
And use it like this:
class SearchResolver
include SearchObject.module(:graphql)
include WithQueryResolver
end
Thats fantastic. Works perfectly thank you.
Just in case this helps anyone, here is the resolver I am using. If there are any tips I welcome them.
require 'search_object/plugin/graphql'
require 'graphql/query_resolver'
module Resolvers
class BaseSearchResolver
include ::SearchObject.module(:graphql)
protected
def self.use_query_resolver obj, obj_type
define_method("resolver_obj") { obj }
define_method("resolver_obj_type") { obj_type }
include ClassMethods
end
module ClassMethods
def fetch_results
# NOTE: Don't run QueryResolver during tests
return super unless context.present?
GraphQL::QueryResolver.run(resolver_obj, context, resolver_obj_type) do
super
end
end
end
end
end
module Resolvers
class CategorySearchResolver < Resolvers::BaseSearchResolver
use_query_resolver ::Category, Types::CategoryType
# ...
end
end
@jylinman Thanks 🙌
Greetings! This is an amazing library thank you.
Is there a way to override the resolver to allow for batching or something like graphql-query-resolver? I don't want to mess up the searchobject resolver and also want to help my database breath a bit too...
Thanks