Recall & Review
beginner
What is the context argument in GraphQL?
The context argument is an object passed to every resolver in a GraphQL server. It holds shared data like authentication info, database connections, or user details that resolvers can access.
Click to reveal answer
beginner
Why do we use the context argument instead of passing data directly to resolvers?
Using context avoids repeating the same data in every resolver call. It provides a single place to store shared info, making code cleaner and easier to maintain.
Click to reveal answer
intermediate
How is the context argument typically created in a GraphQL server?
The context is usually created once per request. It can include user authentication info, database clients, or other services needed by resolvers during that request.
Click to reveal answer
beginner
Give an example of data you might store in the context argument.
You might store the current user's ID, their roles or permissions, a database connection object, or a logger instance in the context.
Click to reveal answer
intermediate
Can the context argument change during a single GraphQL request?
No, the context is created once per request and remains the same for all resolvers during that request to ensure consistent data access.
Click to reveal answer
What is the main purpose of the context argument in GraphQL?
✗ Incorrect
The context argument shares common data such as authentication info with all resolvers during a request.
When is the context argument created in a GraphQL server?
✗ Incorrect
The context is created once for each request to provide consistent data to all resolvers handling that request.
Which of the following is NOT typically stored in the context argument?
✗ Incorrect
The GraphQL query string is usually passed separately, not stored in context.
How do resolvers access the context argument?
✗ Incorrect
Resolvers receive (parent, args, context, info) where context is the third argument.
Why is it better to use context instead of global variables for shared data?
✗ Incorrect
Context is created per request, so it keeps data isolated per user and avoids conflicts.
Explain what the context argument is in GraphQL and why it is useful.
Think about how multiple resolvers can access the same info without repeating it.
You got /3 concepts.
Describe how you would use the context argument to handle user authentication in a GraphQL server.
Consider how to get user data from a request and make it available to all resolvers.
You got /4 concepts.