Introduction
Field-level permissions control who can see or change specific pieces of data in a database. This keeps sensitive information safe.
Field-level permissions control who can see or change specific pieces of data in a database. This keeps sensitive information safe.
type User {
id: ID!
name: String!
email: String! @auth(requires: USER)
salary: Float @auth(requires: ADMIN)
}type User {
id: ID!
name: String!
email: String! @auth(requires: USER)
}type User {
id: ID!
name: String!
salary: Float @auth(requires: ADMIN)
}type Post {
id: ID!
title: String!
content: String! @auth(requires: AUTHOR)
}This query tries to get user details including email and salary. The email is visible to users with USER role, salary only to ADMIN role.
type User {
id: ID!
name: String!
email: String! @auth(requires: USER)
salary: Float @auth(requires: ADMIN)
}
query GetUser {
user(id: "1") {
id
name
email
salary
}
}Field-level permissions help protect sensitive data without hiding the whole record.
Permissions are often based on user roles or ownership.
Always test your permissions to avoid accidental data leaks.
Field-level permissions control access to individual data fields.
They help keep sensitive information safe.
Use directives or rules to set who can see or edit each field.
field-level permissions in GraphQL?@directiveName(arguments) format placed after the field type.@auth(role: "admin") correctly. Options A, B, and D have syntax errors or wrong symbols.type User { id: ID! name: String email: String @auth(role: "admin") }{ user { id name email } }@auth(role: "admin") directive restricts email access to admin role only.type User { id: ID! name: String email: String @auth(role: admin) }email field but only admins to see others' emails. Which field-level permission setup achieves this?@auth(role: "admin") on email field only restricts email only to admins, blocking users from their own email. Make email field public and filter in resolver exposes email publicly, unsafe. Remove email field from schema and add a separate query complicates schema unnecessarily.Pass the test and this pattern moves unknown