Skip to content

Instantly share code, notes, and snippets.

@harigopal
Last active November 6, 2019 19:47
Show Gist options
  • Save harigopal/d498086083b1db7180e407b43dbf7193 to your computer and use it in GitHub Desktop.
Save harigopal/d498086083b1db7180e407b43dbf7193 to your computer and use it in GitHub Desktop.
Conventions for setting up a GraphQL Server on Rails - UsersResolver
# 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