Skip to content

Commit

Permalink
put users into resolver to have query_type class as clean as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfranzen committed Sep 18, 2020
1 parent 831af15 commit 0d5f374
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
13 changes: 13 additions & 0 deletions app/graphql/resolvers/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Resolvers
# Resolver to return a user
class Users < BaseResolver
type Types::UserType.connection_type, null: true
description 'Returns all user for the current user company'

def resolve(**_args)
::User.accessible_by(current_ability).includes(:company)
end
end
end
9 changes: 1 addition & 8 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ module Types
class QueryType < BaseObject
field :me, resolver: Resolvers::Me

field :users, Types::UserType.connection_type, null: false
def users(**_args)
::User.accessible_by(current_ability).includes(:company)
end
field :users, resolver: Resolvers::Users
field :user, resolver: Resolvers::User

field :company, resolver: Resolvers::Companies::Company

def current_ability
Ability.new(context[:current_user])
end
end
end
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ class Application < Rails::Application
# Skip views, helpers and assets when generating a new resource.

config.time_zone = 'Berlin'

# devise uses this for default from options
config.action_mailer.default_options = { from: ENV['DEVISE_MAILER_FROM'] }
end
end

0 comments on commit 0d5f374

Please sign in to comment.