0
0
GraphQLquery~5 mins

Directive-based authorization in GraphQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is directive-based authorization in GraphQL?
It is a way to control access to parts of a GraphQL schema by using special annotations called directives that check user permissions before resolving fields.
Click to reveal answer
beginner
How do you apply a directive for authorization on a GraphQL field?
You add the directive name with any needed arguments directly beside the field in the schema, for example: email: String @auth(role: "ADMIN").
Click to reveal answer
intermediate
What role does the resolver play in directive-based authorization?
The resolver checks the directive's rules during query execution and either allows the data to be returned or denies access if the user lacks permission.
Click to reveal answer
intermediate
Why use directive-based authorization instead of checking permissions inside resolvers?
Directives keep authorization logic separate and reusable, making the schema cleaner and easier to maintain.
Click to reveal answer
beginner
Name a common directive name used for authorization in GraphQL schemas.
A common directive name is @auth, which often takes arguments like user roles or permissions to check.
Click to reveal answer
What does a directive in GraphQL do for authorization?
AFormats the output data
BChecks user permissions before returning data
CDefines the database schema
DCaches query results
Where do you place an authorization directive in a GraphQL schema?
AOn the field or type that needs protection
BOnly in the query operation
CIn the database configuration
DInside the client application code
What happens if a user does not meet the directive's authorization rules?
AThe server crashes
BThe query runs normally
CThe field returns an error or null
DThe data is modified
Which of these is a benefit of using directive-based authorization?
AAutomatically encrypts data
BIncreases query execution time
CRemoves the need for authentication
DCentralizes access control logic
What argument might an @auth directive take?
Arole
Bcolor
Csize
Dformat
Explain how directive-based authorization works in a GraphQL schema.
Think about how special tags in the schema control who can see data.
You got /4 concepts.
    Describe the advantages of using directive-based authorization compared to putting authorization checks inside resolvers.
    Consider how keeping code organized helps when your app grows.
    You got /4 concepts.