Bird
0
0

Why is the context argument preferred over global variables for sharing data like authentication info in GraphQL?

hard📝 Conceptual Q10 of 15
GraphQL - Resolvers
Why is the context argument preferred over global variables for sharing data like authentication info in GraphQL?
ABecause global variables cannot store objects
BBecause context is unique per request, avoiding data leaks between users
CBecause context is defined in the schema
DBecause global variables are faster to access
Step-by-Step Solution
Solution:
  1. Step 1: Understand request isolation in GraphQL

    Each request gets its own context object, so data is isolated per user.
  2. Step 2: Contrast with global variables

    Global variables are shared across requests and users, risking data leaks and concurrency issues.
  3. Final Answer:

    Because context is unique per request, avoiding data leaks between users -> Option B
  4. Quick Check:

    Context isolates data per request [OK]
Quick Trick: Context isolates data per request, unlike globals [OK]
Common Mistakes:
  • Thinking globals are safer
  • Believing context is schema-defined
  • Assuming globals cannot store objects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes