Last active
November 6, 2019 19:47
-
-
Save harigopal/d498086083b1db7180e407b43dbf7193 to your computer and use it in GitHub Desktop.
Conventions for setting up a GraphQL Server on Rails - UsersResolver
This file contains hidden or 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
# app/queries/users_resolver.rb | |
class UsersResolver < ApplicationQuery | |
def users | |
scope = if current_user.admin? | |
User.all | |
else | |
current_user.team.users | |
end | |
# Avoid N+1 when accessing the avatar, with a shortcut for `.includes(avatar_attachment: :blob)`. | |
scope.with_attached_avatar | |
end | |
def authorized? | |
current_user.present? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment