Created
June 5, 2018 06:28
-
-
Save gfx/695914ec209798a11b2b11d2e495196e 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
# frozen_string_literal: true | |
module Types | |
class CountableObject < BaseObject | |
class << self | |
def define_connection(**args, &block) | |
super(**args) do | |
block&.call | |
# this type must be GraphQL::INT_TYPE (not Integer), may be a bug. | |
field :totalCount, GraphQL::INT_TYPE, resolve: ->(object, _args, _ctx) { | |
relation = object.nodes | |
if relation.respond_to?(:total_count) | |
relation.total_count # kaminari-zed relation instance | |
else | |
relation.count | |
end | |
} | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment