Last active
April 27, 2020 23:48
-
-
Save msroot/b1c6ed4577e449c78dd4d52a10a46962 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'search_object' | |
require 'search_object/plugin/graphql' | |
module Resolvers | |
class BaseSearchResolver | |
include ::SearchObject.module(:graphql) | |
def self.create_connection_for(klass) | |
plural = ActiveSupport::Inflector.pluralize(klass.to_s) | |
edge = Class.new(GraphQL::Types::Relay::BaseEdge) do | |
graphql_name "#{plural}EdgeType" | |
node_type("Types::#{klass}Type".constantize) | |
end | |
connection = Class.new(GraphQL::Types::Relay::BaseConnection) do | |
graphql_name "#{plural}Connection" | |
field :total_count, Integer, null: false | |
def total_count | |
object.nodes.size | |
end | |
edge_type(edge) | |
end | |
type connection, null: false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment