0
0
GraphQLquery~20 mins

Field-level permissions in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Field-Level Permissions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What fields are visible to a user with 'read:basic' permission?

Given this GraphQL schema snippet with field-level permissions, which fields will be visible to a user having only the 'read:basic' permission?

type User {
  id: ID!
  name: String! @auth(roles: ["read:basic"])
  email: String! @auth(roles: ["read:private"])
  phone: String @auth(roles: ["read:private"])
}
Aid, name
Bid, email, phone
Cid, name, email
Did, name, email, phone
Attempts:
2 left
💡 Hint

Check which fields require 'read:basic' permission and which require 'read:private'.

🧠 Conceptual
intermediate
1:30remaining
Why use field-level permissions in GraphQL?

What is the main reason to implement field-level permissions in a GraphQL API?

ATo automatically generate documentation for fields
BTo speed up query execution by limiting fields
CTo control which fields a user can see or modify based on their role
DTo enforce database schema constraints
Attempts:
2 left
💡 Hint

Think about security and data privacy.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GraphQL field-level permission directive

Which option contains the correct syntax for applying a field-level permission directive in GraphQL?

type Product {
  id: ID!
  price: Float! @auth(roles: ["admin", "manager"])
}
Aprice: Float! @auth(roles: ["admin", "manager"])
Bprice: Float! @auth(roles = ["admin", "manager"])
Cprice: Float! @auth(roles: "admin", "manager")
Dprice: Float! @auth(roles => ["admin", "manager"])
Attempts:
2 left
💡 Hint

Look carefully at the syntax for directive arguments in GraphQL.

optimization
advanced
2:30remaining
How to optimize field-level permission checks in GraphQL resolvers?

Which approach best optimizes field-level permission checks to avoid redundant authorization logic in GraphQL resolvers?

AAdd permission checks inside every resolver function manually
BImplement a centralized middleware that checks permissions before resolver execution
CSkip permission checks for fields that are rarely queried
DUse client-side validation to enforce permissions
Attempts:
2 left
💡 Hint

Think about avoiding repeated code and improving maintainability.

🔧 Debug
expert
3:00remaining
Why does this GraphQL query return unauthorized error on a permitted field?

Given this schema and query, why does the user get an unauthorized error on the 'email' field even though they have 'read:basic' permission?

type User {
  id: ID!
  name: String! @auth(roles: ["read:basic"])
  email: String! @auth(roles: ["read:private"])
}

Query:
{
  user {
    id
    name
    email
  }
}
AThe 'email' field is misspelled in the query
BThe 'name' field permission overrides 'email' field permission
CThe 'auth' directive is not supported on fields
DThe user lacks the 'read:private' permission required for the 'email' field
Attempts:
2 left
💡 Hint

Check the permissions required for each field carefully.