Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the context argument in a resolver function.
GraphQL
const resolver = (parent, args, [1]) => { return [1].userId; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using args or parent instead of context to get user info.
Confusing the order of resolver arguments.
✗ Incorrect
The context argument provides shared data like authentication info to resolvers.
2fill in blank
mediumComplete the code to extract the user role from the context argument.
GraphQL
function checkRole(_, __, [1]) { return [1].user.role; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to get user role from args or parent.
Using the wrong argument position.
✗ Incorrect
The context holds the current user's data, including roles.
3fill in blank
hardFix the error in accessing the context argument in this resolver.
GraphQL
const resolver = (parent, args, info) => { return [1].userId; } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use
context (undefined) or args/parent instead of info.Not passing context properly to resolvers.
✗ Incorrect
Although named info, the third argument holds the context with user data (true info metadata is fourth). Use info here.
4fill in blank
hardFill both blanks to correctly use context and args in a resolver.
GraphQL
const resolver = (parent, [1], [2]) => { return [2].user.id === [1].id; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping args and context positions.
Using info instead of context.
✗ Incorrect
args holds input arguments, context holds user info.
5fill in blank
hardFill all three blanks to destructure context and use args in a resolver.
GraphQL
const resolver = (_, [1], [2]) => { const { user } = [3]; return user.id === [1].id; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using info or parent instead of context.
Mixing up args and context.
✗ Incorrect
We destructure user from context and compare with args.