Bird
0
0

How can you ensure a delete mutation only deletes if the user has admin rights?

hard📝 Application Q9 of 15
GraphQL - Mutations

How can you ensure a delete mutation only deletes if the user has admin rights?

AInclude user role as an argument in the mutation
BAdd an authorization check in the resolver before deletion
CReturn an error if user role is missing in mutation response
DUse a query instead of mutation to delete
Step-by-Step Solution
Solution:
  1. Step 1: Understand authorization in GraphQL

    Authorization is handled in the server resolver logic, not by mutation arguments.
  2. Step 2: Evaluate options

    Passing user role as argument is insecure; queries cannot delete; error return is reactive, not preventive.
  3. Final Answer:

    Add an authorization check in the resolver before deletion -> Option B
  4. Quick Check:

    Authorization logic belongs in resolver code [OK]
Quick Trick: Put authorization checks inside resolver functions [OK]
Common Mistakes:
  • Passing user role as mutation argument
  • Using queries to delete data
  • Relying on error messages instead of checks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes