-
| I have been reading about visibility in the docs. The  The case I'm interested in is the user’s email address. In our app, a user's email should not be visible to anyone but an admin. But users should be queryable by  I just don't want to enable non-admin queries of all users, that returns the email field for all the users. I was thinking to hide the field's visibility by checking  Probably i'm thinking about this in a non-GraphQL way. Is this a common use case? How do people do this? | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
| Hey, great question. "Visibility" is checked before running any of the query (even before validating the query string), so  If you want to use actual runtime values ( field :email, String, description: "The user's email address. (Hidden for non-admins, unless you're requesting your own email address."
def email 
  if object == context[:current_user] || context[:current_user].admin?
    object.email 
  else 
    nil 
  end 
end I hope that helps ... hopefully one of those options will do the trick! | 
Beta Was this translation helpful? Give feedback.
Hey, great question.
"Visibility" is checked before running any of the query (even before validating the query string), so
objectisn't available. No fields have been executed, no queries have been started, etc -- there's just no runtime data. All we have is the query string and thecontext.If you want to use actual runtime values (
objects that are being used to resolve fields), then you have to use some runtime feature to implement this. "Authorization" might work (although you said it above it won't 😅 !) , but also, you could implement the field to returnnilfor unauthorized users: