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?
✗ Incorrect
Directives for authorization check if a user has permission to access certain data before the data is returned.
Where do you place an authorization directive in a GraphQL schema?
✗ Incorrect
Authorization directives are placed on schema fields or types to control access at the data level.
What happens if a user does not meet the directive's authorization rules?
✗ Incorrect
If authorization fails, the server usually returns an error or null for that field to prevent unauthorized access.
Which of these is a benefit of using directive-based authorization?
✗ Incorrect
Directive-based authorization centralizes and simplifies access control in the schema.
What argument might an @auth directive take?
✗ Incorrect
The @auth directive often takes a 'role' argument to specify which user roles can access the field.
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.